diff --git a/src/status_im/contexts/centralized_metrics/events.cljs b/src/status_im/contexts/centralized_metrics/events.cljs index 545711162e..f758922a0d 100644 --- a/src/status_im/contexts/centralized_metrics/events.cljs +++ b/src/status_im/contexts/centralized_metrics/events.cljs @@ -4,7 +4,6 @@ [re-frame.interceptor :as interceptor] status-im.contexts.centralized-metrics.effects [status-im.contexts.centralized-metrics.tracking :as tracking] - [taoensso.timbre :as log] [utils.re-frame :as rf])) (defn push-event? @@ -16,7 +15,6 @@ [context] (when (push-event? (interceptor/get-coeffect context :db)) (when-let [event (tracking/metrics-event (interceptor/get-coeffect context :event))] - (log/debug "tracking event" event) (if (or (seq? event) (vector? event)) (doseq [e event] (native-module/add-centralized-metric e)) diff --git a/src/status_im/contexts/centralized_metrics/tracking.cljs b/src/status_im/contexts/centralized_metrics/tracking.cljs index 491fc5a7cc..c1d00bcd54 100644 --- a/src/status_im/contexts/centralized_metrics/tracking.cljs +++ b/src/status_im/contexts/centralized_metrics/tracking.cljs @@ -6,12 +6,15 @@ [status-im.navigation.screens :as screens])) (defn key-value-event - [event-name event-value] - {:metric - {:eventName event-name - :platform platform/os - :appVersion build/app-short-version - :eventValue event-value}}) + ([event-name] + (key-value-event event-name nil)) + ([event-name event-value] + (cond-> {:metric + {:eventName event-name + :platform platform/os + :appVersion build/app-short-version}} + event-value + (assoc-in [:metric :eventValue] event-value)))) (defn user-journey-event [action] @@ -41,11 +44,16 @@ (defn track-view-id-event [view-id] - (if-let [screen (get screens/screens-by-name view-id)] - (when (get-in screen [:metrics :track?]) - (screen-event screen {})) - (when (contains? view-ids-to-track view-id) - (navigation-event (name view-id))))) + (let [screen (get screens/screens-by-name view-id)] + (cond-> [] + (get-in screen [:metrics :track?]) + (conj (screen-event screen {})) + + (contains? view-ids-to-track view-id) + (conj (navigation-event (name view-id))) + + (= :screen/onboarding.syncing-results view-id) + (conj (key-value-event "onboarding-completed"))))) (defn navigated-to-collectibles-tab-event [location] @@ -60,6 +68,13 @@ :centralized-metrics/toggle-centralized-metrics (key-value-event "events.metrics-enabled" {:enabled rf-event-parameter}) + :profile.login/non-critical-initialization + (key-value-event "user-logged-in") + + (:profile.create/create-and-login + :profile.recover/recover-and-login) + (key-value-event "onboarding-completed") + :set-view-id (track-view-id-event rf-event-parameter) diff --git a/src/status_im/contexts/centralized_metrics/tracking_test.cljs b/src/status_im/contexts/centralized_metrics/tracking_test.cljs index 5df08670f1..bb52fe4b69 100644 --- a/src/status_im/contexts/centralized_metrics/tracking_test.cljs +++ b/src/status_im/contexts/centralized_metrics/tracking_test.cljs @@ -42,19 +42,19 @@ (deftest track-view-id-event-test (testing "returns correct navigation event for view-id" - (is (= {:metric - {:eventName "navigation" - :platform platform-os - :appVersion app-version - :eventValue {:viewId "communities-stack"}}} + (is (= [{:metric + {:eventName "navigation" + :platform platform-os + :appVersion app-version + :eventValue {:viewId "communities-stack"}}}] (tracking/track-view-id-event :communities-stack))) - (is (= {:metric - {:eventName "navigation" - :platform platform-os - :appVersion app-version - :eventValue {:viewId "onboarding.create-profile-info"}}} + (is (= [{:metric + {:eventName "navigation" + :platform platform-os + :appVersion app-version + :eventValue {:viewId "onboarding.create-profile-info"}}}] (tracking/track-view-id-event :screen/onboarding.create-profile))) - (is (nil? (tracking/track-view-id-event :unknown-stack))))) + (is (= [] (tracking/track-view-id-event :unknown-stack))))) (deftest tracked-event-test (testing "returns correct event for given inputs" @@ -70,16 +70,16 @@ :appVersion app-version :eventValue {:enabled true}}} (tracking/metrics-event [:centralized-metrics/toggle-centralized-metrics true]))) - (is (= {:metric - {:eventName "navigation" - :platform platform-os - :appVersion app-version - :eventValue {:viewId "wallet-stack"}}} + (is (= [{:metric + {:eventName "navigation" + :platform platform-os + :appVersion app-version + :eventValue {:viewId "wallet-stack"}}}] (tracking/metrics-event [:set-view-id :wallet-stack]))) (is (nil? (tracking/metrics-event [:unknown-event]))) - (is (= {:metric - {:eventName "navigation" - :platform platform-os - :appVersion app-version - :eventValue {:viewId "onboarding.intro"}}} + (is (= [{:metric + {:eventName "navigation" + :platform platform-os + :appVersion app-version + :eventValue {:viewId "onboarding.intro"}}}] (tracking/metrics-event [:set-view-id :screen/onboarding.intro]))))) diff --git a/src/status_im/contexts/onboarding/events.cljs b/src/status_im/contexts/onboarding/events.cljs index 834a84ffe6..f7f7f25467 100644 --- a/src/status_im/contexts/onboarding/events.cljs +++ b/src/status_im/contexts/onboarding/events.cljs @@ -3,8 +3,6 @@ [re-frame.core :as re-frame] status-im.common.biometric.events [status-im.constants :as constants] - [status-im.contexts.profile.create.events :as profile.create] - [status-im.contexts.profile.recover.events :as profile.recover] [status-im.contexts.shell.constants :as shell.constants] [taoensso.timbre :as log] [utils.i18n :as i18n] @@ -78,30 +76,28 @@ (fn [_ [error]] {:dispatch [:biometric/show-message (ex-cause error)]})) -(rf/defn create-account-and-login - {:events [:onboarding/create-account-and-login]} - [{:keys [db] :as cofx}] - (let [{:keys [seed-phrase] - :as profile} (:onboarding/profile db) - syncing-account-recovered? (and (seq (:syncing/key-uid db)) - (= (:syncing/key-uid db) - (get-in db [:onboarding/profile :key-uid])))] - (rf/merge cofx - {:fx [[:dispatch - [:navigate-to-within-stack - [:screen/onboarding.preparing-status - (get db - :onboarding/navigated-to-enter-seed-phrase-from-screen - :screen/onboarding.new-to-status)]]] - (when-not syncing-account-recovered? - [:dispatch [:syncing/clear-syncing-installation-id]])] - :db (-> db - (dissoc :profile/login) - (dissoc :auth-method) - (assoc :onboarding/new-account? true))} - (if seed-phrase - (profile.recover/recover-profile-and-login profile) - (profile.create/create-profile-and-login profile))))) +(rf/reg-event-fx :onboarding/create-account-and-login + (fn [{:keys [db]}] + (let [{:keys [seed-phrase] + :as profile} (:onboarding/profile db) + syncing-account-recovered? (and (seq (:syncing/key-uid db)) + (= (:syncing/key-uid db) + (get-in db [:onboarding/profile :key-uid])))] + {:db (-> db + (dissoc :profile/login) + (dissoc :auth-method) + (assoc :onboarding/new-account? true)) + :fx [[:dispatch + [:navigate-to-within-stack + [:screen/onboarding.preparing-status + (get db + :onboarding/navigated-to-enter-seed-phrase-from-screen + :screen/onboarding.new-to-status)]]] + (when-not syncing-account-recovered? + [:dispatch [:syncing/clear-syncing-installation-id]]) + (if seed-phrase + [:dispatch [:profile.recover/recover-and-login profile]] + [:dispatch [:profile.create/create-and-login profile]])]}))) (rf/defn on-delete-profile-success {:events [:onboarding/on-delete-profile-success]} @@ -207,4 +203,3 @@ :on-error #(log/error "failed to save biometrics" {:key-uid key-uid :error %})})))) - diff --git a/src/status_im/contexts/profile/create/events.cljs b/src/status_im/contexts/profile/create/events.cljs index f3b4062e59..1d46a26689 100644 --- a/src/status_im/contexts/profile/create/events.cljs +++ b/src/status_im/contexts/profile/create/events.cljs @@ -6,14 +6,13 @@ [utils.re-frame :as rf] [utils.security.core :as security])) -(rf/defn create-profile-and-login - {:events [:profile.create/create-and-login]} - [{:keys [db]} {:keys [display-name password image-path color]}] - (let [login-sha3-password (native-module/sha3 (security/safe-unmask-data password))] - {:db (assoc-in db [:syncing :login-sha3-password] login-sha3-password) - :effects.profile/create-and-login - (assoc (profile.config/create) - :displayName display-name - :password login-sha3-password - :imagePath (profile.config/strip-file-prefix image-path) - :customizationColor color)})) +(rf/reg-event-fx :profile.create/create-and-login + (fn [{:keys [db]} [{:keys [display-name password image-path color]}]] + (let [login-sha3-password (native-module/sha3 (security/safe-unmask-data password))] + {:db (assoc-in db [:syncing :login-sha3-password] login-sha3-password) + :fx [[:effects.profile/create-and-login + (assoc (profile.config/create) + :displayName display-name + :password login-sha3-password + :imagePath (profile.config/strip-file-prefix image-path) + :customizationColor color)]]}))) diff --git a/src/status_im/contexts/profile/recover/events.cljs b/src/status_im/contexts/profile/recover/events.cljs index 5f3f50c198..a514816bd0 100644 --- a/src/status_im/contexts/profile/recover/events.cljs +++ b/src/status_im/contexts/profile/recover/events.cljs @@ -7,23 +7,22 @@ [utils.re-frame :as rf] [utils.security.core :as security])) -(rf/defn recover-profile-and-login - {:events [:profile.recover/recover-and-login]} - [{:keys [db]} {:keys [display-name password image-path color seed-phrase]}] - (let [login-sha3-password (native-module/sha3 (security/safe-unmask-data password))] - {:db - (-> db - (assoc :onboarding/recovered-account? true) - (assoc-in [:syncing :login-sha3-password] login-sha3-password)) - - :effects.profile/restore-and-login - (assoc (profile.config/create) - :displayName display-name - :mnemonic (security/safe-unmask-data seed-phrase) - :password login-sha3-password - :imagePath (profile.config/strip-file-prefix image-path) - :customizationColor (or color constants/profile-default-color) - :fetchBackup true)})) +(rf/reg-event-fx :profile.recover/recover-and-login + (fn [{:keys [db]} [{:keys [display-name password image-path color seed-phrase]}]] + (let [login-sha3-password (native-module/sha3 (security/safe-unmask-data password))] + {:db + (-> db + (assoc :onboarding/recovered-account? true) + (assoc-in [:syncing :login-sha3-password] login-sha3-password)) + :fx + [[:effects.profile/restore-and-login + (assoc (profile.config/create) + :displayName display-name + :mnemonic (security/safe-unmask-data seed-phrase) + :password login-sha3-password + :imagePath (profile.config/strip-file-prefix image-path) + :customizationColor (or color constants/profile-default-color) + :fetchBackup true)]]}))) (rf/reg-event-fx :profile.recover/validate-recovery-phrase (fn [_ [phrase {:keys [on-success on-error]}]] diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 0689ca75c7..8665edf21d 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -31,7 +31,9 @@ status-im.contexts.network.events status-im.contexts.onboarding.common.overlay.events status-im.contexts.onboarding.events + status-im.contexts.profile.create.events status-im.contexts.profile.events + status-im.contexts.profile.recover.events status-im.contexts.profile.settings.events status-im.contexts.settings.language-and-currency.events status-im.contexts.settings.wallet.saved-addresses.events