chore: refactor screens definitions and add more navigation events for screens (#21328)

This change refactors the navigation-screens namespace to organise each screen definition into a group based on the app features. It also adds some metrics tracking to all the of the screens defined in the navigation-screens namespace. 

Additionally, in this change we've introduced a new build configuration for shadow-cljs which allows us to conditionally include code for certain shadow-cljs builds. In this case, we've decided to only exclude the metrics re-frame interceptor from being required when running the component-tests build. This is due to a complication with the metrics interceptor depending on the navigation-screens namespace, which would eventually require many other third-party dependencies that do not have mocks defined for the component tests. To avoid defining more mocks, we've avoided requiring the metrics interceptor for now.
This commit is contained in:
Sean Hagstrom 2024-10-23 08:28:41 -07:00 committed by GitHub
parent ea18966f33
commit 65cdb0dfe7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 855 additions and 569 deletions

View File

@ -95,7 +95,8 @@
;; otherwise sometimes you'll get weird errors when
;; instrumenting functions.
:static-fns false
:infer-externs true}
:infer-externs true
:reader-features #{:mobile}}
;; if you want to use a real device, set your local ip
;; in the SHADOW_HOST env variable to make sure that
;; it will use the right interface
@ -129,7 +130,8 @@
:static-fns true
:fn-invoke-direct true
:optimizations :advanced
:js-options {:js-provider :closure}}}}
:js-options {:js-provider :closure}
:reader-features #{:mobile}}}}
;; the tests are ran with node, react-native dependencies are mocked
;; by using node --require override.js, which uses the node-library
;; produced by the target :mocks below and redefines node require
@ -174,7 +176,8 @@
:static-fns false
:optimizations :simple
:warnings {:fn-deprecated false}
:infer-externs true}}
:infer-externs true
:reader-features #{:mobile}}}
;; mock.js-dependencies is mocking the react-native libraries
;; we build it as a node library so that it can be required by

View File

@ -14,10 +14,13 @@
(defn centralized-metrics-interceptor
[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)
(when (push-event? (interceptor/get-coeffect context :db))
(native-module/add-centralized-metric event)))
(if (or (seq? event) (vector? event))
(doseq [e event]
(native-module/add-centralized-metric e))
(native-module/add-centralized-metric event))))
context)
(def interceptor

View File

@ -1,7 +1,9 @@
(ns status-im.contexts.centralized-metrics.tracking
(:require
[clojure.string]
[legacy.status-im.utils.build :as build]
[react-native.platform :as platform]))
[react-native.platform :as platform]
[status-im.navigation.screens :as screens]))
(defn key-value-event
[event-name event-value]
@ -19,39 +21,31 @@
[view-id]
(key-value-event "navigation" {:viewId view-id}))
(defn screen-event
[screen event-data]
(let [screen-id (:name screen)
view-id (get-in screen [:metrics :alias-id] screen-id)]
{:metric
{:eventName "navigation"
:platform platform/os
:appVersion build/app-short-version
:eventValue (assoc event-data :viewId (name view-id))}}))
(def ^:const app-started-event "app-started")
(def ^:const view-ids-to-track
#{;; Tabs
:communities-stack
:chats-stack
:wallet-stack
;; Onboarding
:screen/onboarding.intro
:screen/onboarding.new-to-status
:screen/onboarding.sync-or-recover-profile
:screen/onboarding.enter-seed-phrase
:screen/onboarding.create-profile
:screen/onboarding.create-profile-password
:screen/onboarding.enable-biometrics
:screen/onboarding.generating-keys
:screen/onboarding.enable-notifications
:screen/onboarding.preparing-status
:screen/onboarding.sign-in-intro
:screen/onboarding.sign-in
:screen/onboarding.syncing-progress
:screen/onboarding.syncing-progress-intro
:screen/onboarding.syncing-results
:screen/onboarding.welcome
;; Collectibles
:screen/wallet.collectible})
:wallet-stack})
(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))))
(navigation-event (name view-id)))))
(defn navigated-to-collectibles-tab-event
[location]

View File

@ -52,7 +52,7 @@
{:eventName "navigation"
:platform platform-os
:appVersion app-version
:eventValue {:viewId "onboarding.create-profile"}}}
:eventValue {:viewId "onboarding.create-profile-info"}}}
(tracking/track-view-id-event :screen/onboarding.create-profile)))
(is (nil? (tracking/track-view-id-event :unknown-stack)))))
@ -76,4 +76,10 @@
:appVersion app-version
:eventValue {:viewId "wallet-stack"}}}
(tracking/metrics-event [:set-view-id :wallet-stack])))
(is (nil? (tracking/metrics-event [:unknown-event])))))
(is (nil? (tracking/metrics-event [:unknown-event])))
(is (= {:metric
{:eventName "navigation"
:platform platform-os
:appVersion app-version
:eventValue {:viewId "onboarding.intro"}}}
(tracking/metrics-event [:set-view-id :screen/onboarding.intro])))))

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
(ns status-im.setup.interceptor-metrics
(:require
#?@(:mobile
[[re-frame.core :as re-frame]
[status-im.contexts.centralized-metrics.events :as centralized-metrics]])))
(defn setup-centralized-metrics-interceptor
[]
#?(:mobile
(re-frame/reg-global-interceptor centralized-metrics/interceptor)))

View File

@ -2,13 +2,13 @@
(:require
[re-frame.core :as re-frame]
[re-frame.std-interceptors :as std-interceptors]
[status-im.contexts.centralized-metrics.events :as centralized-metrics]
[status-im.setup.interceptor-metrics :as interceptor-metrics]
[utils.re-frame :as rf]))
(defn register-global-interceptors
[]
(re-frame/reg-global-interceptor rf/debug-handlers-names)
(re-frame/reg-global-interceptor centralized-metrics/interceptor)
(interceptor-metrics/setup-centralized-metrics-interceptor)
(re-frame/reg-global-interceptor (re-frame/inject-cofx :now))
;; Interceptor `trim-v` removes the first element of the event vector.