collectible metrics (#21280)

This commit is contained in:
Volodymyr Kozieiev 2024-10-22 16:10:14 +01:00 committed by Icaro Motta
parent fa42a1b977
commit 2d71a15de7
9 changed files with 61 additions and 25 deletions

View File

@ -14,7 +14,7 @@
(defn centralized-metrics-interceptor
[context]
(when-let [event (tracking/tracked-event (interceptor/get-coeffect context :event))]
(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)))

View File

@ -15,7 +15,7 @@
(deftest centralized-metrics-interceptor-test
(testing "processes context correctly"
(with-redefs [tracking/tracked-event (fn [_] {:metric "mocked-event"})
(with-redefs [tracking/metrics-event (fn [_] {:metric "mocked-event"})
events/push-event? (fn [_] true)]
(let [context {:coeffects {:event [:some-event]
:db {:centralized-metrics/enabled? true}}}]

View File

@ -43,23 +43,38 @@
:screen/onboarding.syncing-progress
:screen/onboarding.syncing-progress-intro
:screen/onboarding.syncing-results
:screen/onboarding.welcome})
:screen/onboarding.welcome
;; Collectibles
:screen/wallet.collectible})
(defn track-view-id-event
[view-id]
(when (contains? view-ids-to-track view-id)
(navigation-event (name view-id))))
(defn tracked-event
[[event-name second-parameter]]
(case event-name
(defn navigated-to-collectibles-tab-event
[location]
(key-value-event "navigated-to-collectibles-tab" {:location location}))
(defn metrics-event
[[rf-event-name rf-event-parameter]]
(case rf-event-name
:profile/get-profiles-overview-success
(user-journey-event app-started-event)
:centralized-metrics/toggle-centralized-metrics
(key-value-event "events.metrics-enabled" {:enabled second-parameter})
(key-value-event "events.metrics-enabled" {:enabled rf-event-parameter})
:set-view-id
(track-view-id-event second-parameter)
(track-view-id-event rf-event-parameter)
:wallet/select-account-tab
(when (= rf-event-parameter :collectibles)
(navigated-to-collectibles-tab-event :account))
:wallet/select-home-tab
(when (= rf-event-parameter :collectibles)
(navigated-to-collectibles-tab-event :home))
nil))

View File

@ -63,17 +63,17 @@
:platform platform-os
:appVersion app-version
:eventValue {:action tracking/app-started-event}}}
(tracking/tracked-event [:profile/get-profiles-overview-success])))
(tracking/metrics-event [:profile/get-profiles-overview-success])))
(is (= {:metric
{:eventName "events.metrics-enabled"
:platform platform-os
:appVersion app-version
:eventValue {:enabled true}}}
(tracking/tracked-event [:centralized-metrics/toggle-centralized-metrics true])))
(tracking/metrics-event [:centralized-metrics/toggle-centralized-metrics true])))
(is (= {:metric
{:eventName "navigation"
:platform platform-os
:appVersion app-version
:eventValue {:viewId "wallet-stack"}}}
(tracking/tracked-event [:set-view-id :wallet-stack])))
(is (nil? (tracking/tracked-event [:unknown-event])))))
(tracking/metrics-event [:set-view-id :wallet-stack])))
(is (nil? (tracking/metrics-event [:unknown-event])))))

View File

@ -43,10 +43,18 @@
(defn flush-collectibles
[{:keys [db]}]
(let [collectibles-per-account (get-in db [:wallet :ui :collectibles :fetched])]
(let [collectibles-per-account (get-in db [:wallet :ui :collectibles :fetched])
updated-accounts (move-collectibles-to-accounts (get-in db [:wallet :accounts])
collectibles-per-account)
has-collectibles? (some (fn [account]
(pos? (count (:collectibles account))))
(vals updated-accounts))]
{:db (-> db
(update-in [:wallet :ui :collectibles] dissoc :pending-requests :fetched)
(update-in [:wallet :accounts] move-collectibles-to-accounts collectibles-per-account))}))
(assoc-in [:wallet :accounts] updated-accounts))
:fx [[:dispatch
[:centralized-metrics/track :metric/wallet-collectibles-fetched
{:has-collectibles? has-collectibles?}]]]}))
(rf/reg-event-fx :wallet/flush-collectibles-fetched flush-collectibles)

View File

@ -10,4 +10,5 @@
;; Note: we set it to nil by default to differentiate when the user logs
;; in and the device is offline, versus re-fetching when offline and
;; tokens already exist in the app-db.
:tokens-loading nil}})
:tokens-loading nil
:active-tab :assets}})

View File

@ -59,6 +59,10 @@
(fn [{:keys [db]} [tab]]
{:db (assoc-in db [:wallet :ui :account-page :active-tab] tab)}))
(rf/reg-event-fx :wallet/select-home-tab
(fn [{:keys [db]} [tab]]
{:db (assoc-in db [:wallet :ui :active-tab] tab)}))
(rf/reg-event-fx :wallet/clear-account-tab
(fn [{:keys [db]}]
{:db (assoc-in db [:wallet :ui :account-page :active-tab] nil)}))

View File

@ -41,6 +41,8 @@
(when (ff/enabled? ::ff/wallet.home-activity)
{:id :activity :label (i18n/label :t/activity) :accessibility-label :activity-tab})])
(defn- change-tab [id] (rf/dispatch [:wallet/select-home-tab id]))
(defn- render-cards
[cards ref]
[rn/flat-list
@ -64,7 +66,7 @@
(defn view
[]
(let [[selected-tab set-selected-tab] (rn/use-state (:id (first tabs-data)))
(let [selected-tab (rf/sub [:wallet/home-tab])
account-list-ref (rn/use-ref-atom nil)
tokens-loading? (rf/sub [:wallet/home-tokens-loading?])
networks (rf/sub [:wallet/selected-network-details])
@ -104,7 +106,7 @@
(when (ff/enabled? ::ff/wallet.graph)
[quo/wallet-graph {:time-frame :empty}])
[render-cards cards account-list-ref]
[render-tabs tabs-data set-selected-tab selected-tab]]
[render-tabs tabs-data change-tab selected-tab]]
:content-container-style style/list-container
:sticky-header-indices [0]
:data []

View File

@ -591,6 +591,12 @@
(fn [ui]
(get-in ui [:account-page :active-tab])))
(rf/reg-sub
:wallet/home-tab
:<- [:wallet/ui]
(fn [ui]
(:active-tab ui)))
(rf/reg-sub
:wallet/aggregated-tokens
:<- [:wallet/accounts-without-watched-accounts]