From bb7d31a35759851085e8a668a139d046c3b483fd Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 16 Jul 2018 08:34:11 +0300 Subject: [PATCH] [#5169] Remove Mixpanel --- .env | 3 +- .env.e2e | 3 +- .env.jenkins | 3 +- .env.nightly | 3 +- .env.prod | 1 - .../data_store/realm/schemas/base/core.cljs | 8 +- .../realm/schemas/base/v7/account.cljs | 30 +++ .../realm/schemas/base/v7/core.cljs | 12 + src/status_im/network/events.cljs | 11 +- src/status_im/translations/en.cljs | 10 - src/status_im/ui/screens/accounts/events.cljs | 2 +- .../ui/screens/accounts/recover/events.cljs | 2 +- src/status_im/ui/screens/add_new/views.cljs | 6 +- src/status_im/ui/screens/desktop/views.cljs | 2 - src/status_im/ui/screens/events.cljs | 2 - .../ui/screens/profile/user/views.cljs | 6 - .../ui/screens/usage_data/events.cljs | 9 - .../ui/screens/usage_data/styles.cljs | 72 ------ .../ui/screens/usage_data/views.cljs | 43 ---- src/status_im/ui/screens/views.cljs | 2 - src/status_im/utils/config.cljs | 1 - src/status_im/utils/handlers.cljs | 29 +-- src/status_im/utils/instabug.cljs | 10 - src/status_im/utils/mixpanel.cljs | 137 ------------ src/status_im/utils/mixpanel_events.cljs | 205 ------------------ test/cljs/status_im/test/runner.cljs | 4 +- test/cljs/status_im/test/utils/mixpanel.cljs | 43 ---- 27 files changed, 63 insertions(+), 596 deletions(-) create mode 100644 src/status_im/data_store/realm/schemas/base/v7/account.cljs create mode 100644 src/status_im/data_store/realm/schemas/base/v7/core.cljs delete mode 100644 src/status_im/ui/screens/usage_data/events.cljs delete mode 100644 src/status_im/ui/screens/usage_data/styles.cljs delete mode 100644 src/status_im/ui/screens/usage_data/views.cljs delete mode 100644 src/status_im/utils/mixpanel.cljs delete mode 100644 src/status_im/utils/mixpanel_events.cljs delete mode 100644 test/cljs/status_im/test/utils/mixpanel.cljs diff --git a/.env b/.env index 3ed6d3c318..aba9905c14 100644 --- a/.env +++ b/.env @@ -9,7 +9,6 @@ QUEUE_MESSAGE_ENABLED=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 POW_TARGET=0.002 POW_TIME=1 -MIXPANEL_TOKEN=e1c71ae86923310ffb75de525d54cabf DEFAULT_NETWORK=mainnet_rpc TESTFAIRY_TOKEN=969f6c921cb435cea1d41d1ea3f5b247d6026d55 INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c @@ -17,4 +16,4 @@ DEBUG_WEBVIEW=1 INSTABUG_SURVEYS=1 GROUP_CHATS_ENABLED=0 USE_SYM_KEY=0 -SPAM_BUTTON_DETECTION_ENABLED=1 \ No newline at end of file +SPAM_BUTTON_DETECTION_ENABLED=1 diff --git a/.env.e2e b/.env.e2e index b0a4481eac..bca9553617 100644 --- a/.env.e2e +++ b/.env.e2e @@ -8,7 +8,6 @@ JSC_ENABLED=1 QUEUE_MESSAGE_ENABLED=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 COMPILE_VIEWS_ENABLED=0 -MIXPANEL_TOKEN=e1c71ae86923310ffb75de525d54cabf POW_TARGET=0.002 POW_TIME=1 DEFAULT_NETWORK=testnet_rpc @@ -16,4 +15,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c DEBUG_WEBVIEW=1 INSTABUG_SURVEYS=0 GROUP_CHATS_ENABLED=1 -USE_SYM_KEY=0 \ No newline at end of file +USE_SYM_KEY=0 diff --git a/.env.jenkins b/.env.jenkins index 95c63759a9..cca2b08bbc 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -7,7 +7,6 @@ LOG_LEVEL_STATUS_GO=info JSC_ENABLED=1 QUEUE_MESSAGE_ENABLED=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 -MIXPANEL_TOKEN=e1c71ae86923310ffb75de525d54cabf TESTFAIRY_TOKEN=969f6c921cb435cea1d41d1ea3f5b247d6026d55 POW_TARGET=0.002 POW_TIME=1 @@ -18,4 +17,4 @@ INSTABUG_SURVEYS=1 GROUP_CHATS_ENABLED=0 USE_SYM_KEY=0 SPAM_BUTTON_DETECTION_ENABLED=1 -MAINNET_WARNING_ENABLED=1 \ No newline at end of file +MAINNET_WARNING_ENABLED=1 diff --git a/.env.nightly b/.env.nightly index c9be838cf8..cc0aaee454 100644 --- a/.env.nightly +++ b/.env.nightly @@ -7,7 +7,6 @@ LOG_LEVEL_STATUS_GO=info JSC_ENABLED=1 QUEUE_MESSAGE_ENABLED=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 -MIXPANEL_TOKEN=3f2e1a8970f159aa2a3d5dc5d65eab38 TESTFAIRY_TOKEN=969f6c921cb435cea1d41d1ea3f5b247d6026d55 POW_TARGET=0.002 POW_TIME=1 @@ -17,4 +16,4 @@ DEBUG_WEBVIEW=1 INSTABUG_SURVEYS=1 GROUP_CHATS_ENABLED=0 SPAM_BUTTON_DETECTION_ENABLED=1 -MAINNET_WARNING_ENABLED=1 \ No newline at end of file +MAINNET_WARNING_ENABLED=1 diff --git a/.env.prod b/.env.prod index d0204dd8ae..e58a56b1fe 100644 --- a/.env.prod +++ b/.env.prod @@ -10,7 +10,6 @@ QUEUE_MESSAGE_ENABLED=0 RN_BRIDGE_THRESHOLD_WARNINGS=0 POW_TARGET=0.002 POW_TIME=1 -MIXPANEL_TOKEN=2584e00100d319d12e538cc4d0fa9fc1 DEFAULT_NETWORK=mainnet_rpc TESTFAIRY_TOKEN=969f6c921cb435cea1d41d1ea3f5b247d6026d55 INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c diff --git a/src/status_im/data_store/realm/schemas/base/core.cljs b/src/status_im/data_store/realm/schemas/base/core.cljs index 3070c9550b..f140d9021a 100644 --- a/src/status_im/data_store/realm/schemas/base/core.cljs +++ b/src/status_im/data_store/realm/schemas/base/core.cljs @@ -4,7 +4,8 @@ [status-im.data-store.realm.schemas.base.v3.core :as v3] [status-im.data-store.realm.schemas.base.v4.core :as v4] [status-im.data-store.realm.schemas.base.v5.core :as v5] - [status-im.data-store.realm.schemas.base.v6.core :as v6])) + [status-im.data-store.realm.schemas.base.v6.core :as v6] + [status-im.data-store.realm.schemas.base.v7.core :as v7])) ;; put schemas ordered by version (def schemas [{:schema v1/schema @@ -24,4 +25,7 @@ :migration v5/migration} {:schema v6/schema :schemaVersion 6 - :migration v6/migration}]) + :migration v6/migration} + {:schema v7/schema + :schemaVersion 7 + :migration v7/migration}]) diff --git a/src/status_im/data_store/realm/schemas/base/v7/account.cljs b/src/status_im/data_store/realm/schemas/base/v7/account.cljs new file mode 100644 index 0000000000..fdcbaede47 --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v7/account.cljs @@ -0,0 +1,30 @@ +(ns status-im.data-store.realm.schemas.base.v7.account) + +(def schema {:name :account + :primaryKey :address + :properties {:address :string + :public-key :string + :name {:type :string :optional true} + :email {:type :string :optional true} + :status {:type :string :optional true} + :debug? {:type :bool :default false} + :photo-path :string + :signing-phrase {:type :string} + :mnemonic {:type :string :optional true} + :last-updated {:type :int :default 0} + :last-sign-in {:type :int :default 0} + :signed-up? {:type :bool + :default false} + :network :string + :networks {:type :list + :objectType :network} + :bootnodes {:type :list + :objectType :bootnode} + :last-request {:type :int :optional true} + :settings {:type :string} + :dev-mode? {:type :bool :default false} + :seed-backed-up? {:type :bool :default false} + :wallet-set-up-passed? {:type :bool + :default false} + :mainnet-warning-shown? {:type :bool + :default false}}}) diff --git a/src/status_im/data_store/realm/schemas/base/v7/core.cljs b/src/status_im/data_store/realm/schemas/base/v7/core.cljs new file mode 100644 index 0000000000..f7b7a23a6b --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v7/core.cljs @@ -0,0 +1,12 @@ +(ns status-im.data-store.realm.schemas.base.v7.core + (:require [status-im.data-store.realm.schemas.base.v1.network :as network] + [status-im.data-store.realm.schemas.base.v4.bootnode :as bootnode] + [status-im.data-store.realm.schemas.base.v7.account :as account] + [taoensso.timbre :as log])) + +(def schema [network/schema + bootnode/schema + account/schema]) + +(defn migration [old-realm new-realm] + (log/debug "migrating base database v7: " old-realm new-realm)) diff --git a/src/status_im/network/events.cljs b/src/status_im/network/events.cljs index f6afd8eada..db18b3aba3 100644 --- a/src/status_im/network/events.cljs +++ b/src/status_im/network/events.cljs @@ -28,12 +28,11 @@ (handlers/register-handler-fx ::update-connection-status [re-frame/trim-v] - (fn [{{:keys [network-status mailserver-status] :as db} :db :as cofx} [is-connected?]] - (cond-> (handlers-macro/merge-fx cofx - {:db (assoc db :network-status (if is-connected? :online :offline))} - (inbox/request-messages)) - is-connected? - (assoc :drain-mixpanel-events nil)))) + (fn [{db :db :as cofx} [is-connected?]] + (handlers-macro/merge-fx + cofx + {:db (assoc db :network-status (if is-connected? :online :offline))} + (inbox/request-messages)))) (handlers/register-handler-fx ::update-network-status diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 4071875e39..45f28d8401 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -51,16 +51,6 @@ :other-accounts "Other accounts" :sign-you-in "Signing you in…" - :help-improve "Help improve Status\nby sharing usage patterns" - :help-improve? "Help improve Status?" - :help-improve-description "We collect anonymous data to understand how Status is used and inform future development. Whilst we appreciate your help to make Status better, this is an optional choice and can be changed at any time." - :learn-what-we-collect-link "Learn more about what we collect" - :share-usage-data "Share data" - :dont-want-to-share "Do not share" - :confirmation-title "Share data with Status?" - :confirmation-text "Are you sure you want to share anonymous data with Status?" - :confirmation-action "Share" - ;;drawer :switch-users "Switch users" :logout-title "Log out?" diff --git a/src/status_im/ui/screens/accounts/events.cljs b/src/status_im/ui/screens/accounts/events.cljs index c48bdf522e..f8c09671ca 100644 --- a/src/status_im/ui/screens/accounts/events.cljs +++ b/src/status_im/ui/screens/accounts/events.cljs @@ -119,7 +119,7 @@ (fn [{{:accounts/keys [create] :as db} :db :as cofx} _] (handlers-macro/merge-fx cofx {:db db - :dispatch [:navigate-to-clean :usage-data [:account-finalized true]]} + :dispatch [:navigate-to-clean :home]} (accounts.utils/account-update {:name (:name create)})))) (handlers/register-handler-fx diff --git a/src/status_im/ui/screens/accounts/recover/events.cljs b/src/status_im/ui/screens/accounts/recover/events.cljs index 79ee18fba9..c7b445c749 100644 --- a/src/status_im/ui/screens/accounts/recover/events.cljs +++ b/src/status_im/ui/screens/accounts/recover/events.cljs @@ -60,7 +60,7 @@ :account-recovered-navigate (fn [{:keys [db]}] {:db (assoc-in db [:accounts/recover :processing] false) - :dispatch [:navigate-to :usage-data [:account-finalized false]]})) + :dispatch [:navigate-to-clean :home]})) (handlers/register-handler-fx :recover-account diff --git a/src/status_im/ui/screens/add_new/views.cljs b/src/status_im/ui/screens/add_new/views.cljs index 2307f36abf..db803576e7 100644 --- a/src/status_im/ui/screens/add_new/views.cljs +++ b/src/status_im/ui/screens/add_new/views.cljs @@ -11,8 +11,7 @@ [status-im.ui.components.styles :as styles] [status-im.ui.components.status-bar.view :as status-bar] [status-im.ui.components.toolbar.view :as toolbar] - [status-im.utils.config :as config] - [status-im.utils.mixpanel :as mixpanel])) + [status-im.utils.config :as config])) (defn- options-list [{:keys [anon-id]}] [react/view action-button.styles/actions-list @@ -51,8 +50,7 @@ :accessibility-label :invite-friends-button :icon :icons/share :icon-opts {:color colors/blue} - :on-press #(do (mixpanel/track anon-id "Tap" {:target :invite-friends} false) - (list-selection/open-share {:message (i18n/label :t/get-status-at)}))}]]) + :on-press #(list-selection/open-share {:message (i18n/label :t/get-status-at)})}]]) (views/defview add-new [] (views/letsubs [account [:get-current-account] diff --git a/src/status_im/ui/screens/desktop/views.cljs b/src/status_im/ui/screens/desktop/views.cljs index e2fc25054a..301ba6e09d 100644 --- a/src/status_im/ui/screens/desktop/views.cljs +++ b/src/status_im/ui/screens/desktop/views.cljs @@ -4,7 +4,6 @@ [status-im.ui.components.react :as react] [status-im.ui.screens.intro.views :as intro.views] [status-im.ui.screens.accounts.create.views :as create.views] - [status-im.ui.screens.usage-data.views :as usage-data.views] [status-im.ui.screens.accounts.login.views :as login.views] [status-im.ui.screens.accounts.recover.views :as recover.views] [status-im.ui.screens.accounts.views :as accounts.views])) @@ -13,7 +12,6 @@ (views/letsubs [view-id [:get :view-id]] (let [component (case view-id :intro intro.views/intro - :usage-data usage-data.views/usage-data :accounts accounts.views/accounts :recover recover.views/recover :create-account create.views/create-account diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index b45922416f..62777bf628 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -34,7 +34,6 @@ status-im.ui.screens.offline-messaging-settings.events status-im.ui.screens.bootnodes-settings.events status-im.ui.screens.currency-settings.events - status-im.ui.screens.usage-data.events status-im.utils.keychain.events [re-frame.core :as re-frame] [status-im.native-module.core :as status] @@ -58,7 +57,6 @@ [status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.http :as http] [status-im.utils.instabug :as instabug] - [status-im.utils.mixpanel :as mixpanel] [status-im.utils.platform :as platform] [status-im.utils.types :as types] [status-im.utils.utils :as utils] diff --git a/src/status_im/ui/screens/profile/user/views.cljs b/src/status_im/ui/screens/profile/user/views.cljs index 115327fd17..c6549e891c 100644 --- a/src/status_im/ui/screens/profile/user/views.cljs +++ b/src/status_im/ui/screens/profile/user/views.cljs @@ -157,12 +157,6 @@ :action-fn #(re-frame/dispatch [:navigate-to :bootnodes-settings]) :accessibility-label :bootnodes-settings-button}]) [profile.components/settings-item-separator] - [profile.components/settings-item - {:label-kw :t/help-improve? - :value (i18n/label (if sharing-usage-data? :on :off)) - :action-fn #(re-frame/dispatch [:navigate-to :usage-data [:navigate-back]]) - :accessibility-label :help-improve}] - [profile.components/settings-item-separator] [profile.components/settings-switch-item {:label-kw :t/dev-mode :value dev-mode? diff --git a/src/status_im/ui/screens/usage_data/events.cljs b/src/status_im/ui/screens/usage_data/events.cljs deleted file mode 100644 index 28d638964f..0000000000 --- a/src/status_im/ui/screens/usage_data/events.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns status-im.ui.screens.usage-data.events - (:require [status-im.utils.handlers :as handlers] - [status-im.ui.screens.accounts.utils :as accounts.utils])) - -(handlers/register-handler-fx - :help-improve-handler - (fn [{db :db} [_ yes? next]] - (merge (accounts.utils/account-update {:sharing-usage-data? yes?} {:db db}) - {:dispatch (or next [:navigate-to-clean :home])}))) diff --git a/src/status_im/ui/screens/usage_data/styles.cljs b/src/status_im/ui/screens/usage_data/styles.cljs deleted file mode 100644 index 1b2c00e440..0000000000 --- a/src/status_im/ui/screens/usage_data/styles.cljs +++ /dev/null @@ -1,72 +0,0 @@ -(ns status-im.ui.screens.usage-data.styles - (:require-macros [status-im.utils.styles :refer [defnstyle defstyle]]) - (:require [status-im.ui.components.colors :as colors] - [status-im.utils.platform :as platform])) - -(defn scaled-x [window-width n] (* (/ window-width 375) n)) -(defn scaled-y [window-height n] (* (/ window-height 667) n)) - -(def usage-data-view - {:flex 1 - :background-color colors/white - :align-items :center - :justify-content :center}) - -(defn image-container [window-height] - {;; on screens less tall than iPhone 5, let's not show the image at all - :display (if (>= window-height 568) "flex" "none") - :align-items :center - :justify-content :center - :margin-bottom (scaled-y window-height 30)}) - -(defn usage-data-image [window-height] - {:width (* (/ 390 432) (scaled-y window-height 138)) - :height (scaled-y window-height 138)}) - -(defnstyle help-improve-text [window-height] - {:text-align :center - :color colors/black - :margin-bottom (scaled-y window-height 8) - :margin-left 46 - :margin-right 46 - :ios {:line-height 28 - :font-size 22 - :font-weight :bold - :letter-spacing -0.3} - :android {:font-size 24 - :line-height 30}}) - -(defn help-improve-text-description [window-height] - {:line-height 21 - :margin-bottom (scaled-y window-height 26) - :margin-left 34 - :margin-right 34 - :text-align :center - :color colors/gray}) - -(def learn-what-we-collect-link - {:text-align :center - :color colors/blue - :margin-left 61 - :margin-right 63}) - -(defn bottom-button-container [window-height] - {:flex-direction :row - ;; we need to make a margin smaller on iPhone 5(s) - :margin-top (scaled-y window-height - (if (and platform/ios? - (> window-height 568)) - 96 48)) - :margin-left 41 - :margin-right 42}) - -(defn share-button [window-width] - {:padding-horizontal 18 - :width (scaled-x window-width 138) - :margin-right 16}) - -(defn dont-share-button [window-width] - {:padding-horizontal 18 - ;; don't do text wrap on super small devices - :min-width 130 - :width (scaled-x window-width 138)}) diff --git a/src/status_im/ui/screens/usage_data/views.cljs b/src/status_im/ui/screens/usage_data/views.cljs deleted file mode 100644 index 07c7cc3675..0000000000 --- a/src/status_im/ui/screens/usage_data/views.cljs +++ /dev/null @@ -1,43 +0,0 @@ -(ns status-im.ui.screens.usage-data.views - (:require-macros [status-im.utils.views :as views]) - (:require [re-frame.core :as re-frame] - [status-im.i18n :as i18n] - [status-im.react-native.resources :as resources] - [status-im.ui.components.common.common :as components.common] - [status-im.ui.components.react :as react] - [status-im.ui.components.status-bar.view :as status-bar] - [status-im.ui.screens.usage-data.styles :as styles] - [status-im.utils.utils :as utils])) - -(views/defview usage-data [] - (views/letsubs [next [:get-screen-params] - {:keys [width height]} [:dimensions/window]] - [react/view {:style styles/usage-data-view} - [status-bar/status-bar {:flat? true}] - [react/view - [react/view {:style (styles/image-container height)} - [react/image {:source (:analytics-image resources/ui) - :style (styles/usage-data-image height)}]] - [react/i18n-text {:style (styles/help-improve-text height) - :key :help-improve}] - [react/view - [react/i18n-text {:style (styles/help-improve-text-description height) - :key :help-improve-description}]] - [react/text {:style styles/learn-what-we-collect-link - :on-press #(.openURL react/linking "https://wiki.status.im/Help_Improve_Status#Help_Improve_Status")} - (i18n/label :t/learn-what-we-collect-link)]] - [react/view (styles/bottom-button-container height) - [components.common/button {:button-style (styles/share-button width) - :uppercase? false - :on-press #(utils/show-confirmation {:ios-confirm-style "default"} - (i18n/label :t/confirmation-title) - (i18n/label :t/confirmation-text) - (i18n/label :t/confirmation-action) - (fn [] (re-frame/dispatch [:help-improve-handler true next])) - nil) - :label (i18n/label :t/share-usage-data)}] - [components.common/button {:button-style (styles/dont-share-button width) - :uppercase? false - :on-press #(re-frame/dispatch [:help-improve-handler false next]) - :label (i18n/label :t/dont-want-to-share)}]]])) - diff --git a/src/status_im/ui/screens/views.cljs b/src/status_im/ui/screens/views.cljs index 5e293d9b09..386de2e0bf 100644 --- a/src/status_im/ui/screens/views.cljs +++ b/src/status_im/ui/screens/views.cljs @@ -49,7 +49,6 @@ [status-im.ui.screens.add-new.open-dapp.views :refer [open-dapp dapp-description]] [status-im.ui.screens.intro.views :refer [intro]] [status-im.ui.screens.accounts.create.views :refer [create-account]] - [status-im.ui.screens.usage-data.views :refer [usage-data]] [status-im.ui.screens.profile.seed.views :refer [backup-seed]])) (defn get-main-component [view-id] @@ -57,7 +56,6 @@ :collectibles-list collectibles-list :intro intro :create-account create-account - :usage-data usage-data (:home :wallet :my-profile) main-tabs :browser browser :open-dapp open-dapp diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index 4dd65a60df..dae2043835 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -30,7 +30,6 @@ (def add-custom-mailservers-enabled? (enabled? (get-config :ADD_CUSTOM_MAILSERVERS_ENABLED "1"))) (def rn-bridge-threshold-warnings-enabled? (enabled? (get-config :RN_BRIDGE_THRESHOLD_WARNINGS 0))) -(def mixpanel-token (get-config :MIXPANEL_TOKEN)) (def default-network (get-config :DEFAULT_NETWORK)) ;; the default value should be a string for `enabled?` to work correctly. (def rpc-networks-only? (enabled? (get-config :RPC_NETWORKS_ONLY "1"))) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index b360576e2d..27d910f2a8 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -4,7 +4,6 @@ [re-frame.core :refer [reg-event-db reg-event-fx] :as re-frame] [re-frame.interceptor :refer [->interceptor get-coeffect get-effect]] [status-im.utils.instabug :as instabug] - [status-im.utils.mixpanel :as mixpanel] [status-im.models.account :as models.account] [cljs.core.async :as async] [taoensso.timbre :as log])) @@ -93,26 +92,6 @@ (throw (ex-info (check-spec-msg event-id new-db) {}))) context)))) -(def track-mixpanel - "send an event to mixpanel for tracking" - (->interceptor - :id track-mixpanel - :after - (fn track-handler - [context] - (let [new-db (get-coeffect context :db) - [event-name] (get-coeffect context :event)] - (when (get-in new-db [:account/account :sharing-usage-data?]) - (let [event (get-coeffect context :event) - offline? (or (= :offline (:network-status new-db)) - (= :offline (:sync-state new-db))) - anon-id (:device-UUID new-db)] - (doseq [{:keys [label properties]} - (mixpanel/matching-events new-db event mixpanel/event-by-trigger)] - (mixpanel/track anon-id label properties offline?) - (instabug/track label properties))))) - context))) - (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] @@ -121,8 +100,7 @@ (def default-interceptors [debug-handlers-names (when js/goog.DEBUG check-spec) - (re-frame/inject-cofx :now) - track-mixpanel]) + (re-frame/inject-cofx :now)]) (defn register-handler-db ([name handler] (register-handler-db name nil handler)) @@ -146,8 +124,3 @@ (remove (fn [{:keys [dapp? pending?]}] (or pending? dapp?))) (map :whisper-identity))) - -(re-frame.core/reg-fx - :drain-mixpanel-events - (fn [] - (async/go (async/json m))) - -(defn- make-event [id label props] - {:event label - :properties (merge - {:token config/mixpanel-token - :distinct_id id - :os platform/os - :os-version platform/version - :app-version build/version - :time (datetime/timestamp)} - props)}) - -;; holds events that are accumulated while offline. will start throwing away old -;; events if we accumulate more than 2000 -(def ^:private pending-events-queue (async/chan (async/sliding-buffer 2000))) - -(defn- submit-batch - "Submit a batch of events to mixpanel via POST" - [events] - (let [done-chan (async/chan)] - (log/debug "submitting" (count events) "events") - (http/post base-track-url - (str "data=" (encode (into [] events))) - (fn [_] - (log/debug "successfully submitted events") - (async/go (async/close! done-chan))) - (fn [error] - (log/error "error while submitting events" error) - (async/go (async/close! done-chan)))) - done-chan)) - -;; maximum number of events that should be submitted to mixpanel's batch -;; endpoint at once (see https://mixpanel.com/help/reference/http) -(def max-batch-size 50) - -(defn drain-events-queue! - "Drains accumulated events and submits them in batches of " - ([] - (drain-events-queue! pending-events-queue submit-batch)) - ([queue callback] - (let [events (loop [accumulator []] - (if-let [event (async/poll! queue)] - (recur (conj accumulator event)) - accumulator))] - (async/go - (doseq [batch (partition-all max-batch-size events)] - (async/! pending-events-queue event)) - ;; drain queue if we are online - (when-not offline? - (async/go (async/triggers - "Transform definitions vector into map which will be used for matching later - - [{:trigger [:en1]} - {:trigger [:en1 :p1]} - {:trigger [:en2 :p1]} - {:trigger [:en3 :p1 :p2 :p3]}] - - will be transformed into - - {:en1 {events ({:trigger [:en1]}) - :p1 {events ({:trigger [:en1 :p1]})}} - :en2 {:p1 {events ({:trigger [:en2 :p1]})}} - :en3 {:p1 {:p2 {:p3 {events ({:trigger [:en3 :p1 :p2 :p3]})}}}}}" - [events] - (reduce (fn [m {:keys [trigger] :as event}] - (update-in m (conj trigger event-tag) conj event)) - {} - events)) - -(def event-by-trigger - (event->triggers mixpanel-events/events)) - -(defn matching-events [db [event-name first-arg :as event] triggers] - (let [cnt (count event) - triggers (cond-> - ;; first we get all events which are triggered by event name - ;; (the case when :trigger contains only one element) - ;; {:trigger [:only-event-name-here]} - (get-in triggers [event-name event-tag]) - - ;; when event contains two or more elements we are trying - ;; to match by first two elements of :trigger - ;; {:trigger [:event-name :one-parameter]} - (>= cnt 2) - (concat (get-in triggers [event-name first-arg event-tag])) - - ;; also if event contains more than one parameter (more than - ;; two elements) we are trying to match it with equal :trigger - ;; {:trigger [:e-name :p1 :p2 :p3]} - ;; will match only with [:e-name :p1 :p2 :p3] event - (> cnt 2) - (concat (get-in triggers (conj event event-tag))))] - (->> triggers - - (filter (fn [{:keys [filter-fn]}] - (or (not filter-fn) (filter-fn db event)))) - - (mapcat (fn [{:keys [data-fn] :as trigger}] - (if data-fn - (let [data (data-fn db event)] - (if (map? data) - [(update trigger :properties merge data)] - (map (partial update trigger :properties merge) data))) - [trigger])))))) diff --git a/src/status_im/utils/mixpanel_events.cljs b/src/status_im/utils/mixpanel_events.cljs deleted file mode 100644 index 74073e9bd9..0000000000 --- a/src/status_im/utils/mixpanel_events.cljs +++ /dev/null @@ -1,205 +0,0 @@ -(ns status-im.utils.mixpanel-events) -;; This file is supposed to be edited by Chad. -;; Chad loves mixpanel. When Chad was a child he dreamed of being a mixpanel tamer. - -;; To add a new event definition, add a new map to this vector -;; :label is a free string that is displayed in mixpanel -;; :trigger is the re-frame style event that when matched will generate the emission of a mixpanel event -;; :properties is a map of key / value pair that will be added to the mixpanel event to provide more context -(def events - [;; Account creation - - {:label "Account created" - :trigger [:account-finalized]} - {:label "Account restored" - :trigger [:account-recovered]} - - ;; Account lifecycle - - {:label "Login" - :trigger [:initialize-account]} - - {:label "Logout" - :trigger [:navigate-to :accounts]} - - ; Push notification settings - - {:label "Tap" - :trigger [:request-notifications-granted] - :properties {:target :granted-push-notifications}} - - {:label "Tap" - :trigger [:request-notifications-denied] - :properties {:target :denied-push-notifications}} - - ;; Tab navigation - - {:label "Tap" - :trigger [:navigate-to-clean :home] - :properties {:target :home}} - {:label "Tap" - :trigger [:navigate-to-tab :home] - :properties {:target :home}} - {:label "Tap" - :trigger [:navigate-to-tab :my-profile] - :properties {:target :my-profile}} - {:label "Tap" - :trigger [:navigate-to-clean :wallet] - :properties {:target :wallet}} - {:label "Tap" - :trigger [:navigate-to-tab :wallet] - :properties {:target :wallet}} - - ;; New - {:label "Tap" - :trigger [:navigate-to :new] - :properties {:target :new}} - {:label "Tap" - :trigger [:navigate-to :new-chat] - :properties {:target :new-chat}} - {:label "Tap" - :trigger [:scan-qr-code] - :properties {:target :new-chat-qr-code}} - {:label "Tap" - :trigger [:show-profile] - :properties {:target :show-profile}} - {:label "Tap" - :trigger [:open-contact-toggle-list] - :properties {:target :new-group-chat}} - {:label "Tap" - :trigger [:navigate-to :new-public-chat] - :properties {:target :new-public-chat}} - {:label "Tap" - :trigger [:navigate-to :open-dapp] - :properties {:target :open-dapp}} - {:label "Tap" - :trigger [:navigate-to :dapp-description] - :properties {:target :open-dapp-description}} - {:label "Tap" - :trigger [:open-dapp-in-browser] - :properties {:target :open-selected-dapp}} - {:label "Tap" - :trigger [:navigate-to :new-group] - :properties {:target :start-group-chat-next}} - {:label "Tap" - :trigger [:create-new-public-chat] - :properties {:target :create-public-chat}} - {:label "Tap" - :trigger [:navigate-to :new-public-chat] - :properties {:target :join-public-chat}} - - ;; Chat - - {:label "Tap" - :trigger [:navigate-to-chat] - :properties {:target :open-existing-chat}} - {:label "Tap" - :trigger [:navigate-to :browser] - :properties {:target :open-existing-dapp}} - {:label "Tap" - :trigger [:start-chat] - :properties {:target :start-chat}} - {:label "Tap" - :trigger [:send-current-message] - :properties {:target :send-current-message}} - - ;; Wallet - {:label "Tap" - :trigger [:navigate-to :wallet-send-transaction] - :properties {:target :wallet-send-transaction}} - {:label "Tap" - :trigger [:navigate-to :wallet-request-transaction] - :properties {:target :wallet-request-transaction}} - {:label "Tap" - :trigger [:navigate-to :transactions-history] - :properties {:target :transactions-history}} - {:label "Tap" - :trigger [:navigate-to :recent-recipients] - :properties {:target :select-recipient - :type :recent-recipients}} - {:label "Tap" - :trigger [:navigate-to :recipient-qr-code] - :properties {:target :select-recipient - :type :recipient-qr-code}} - {:label "Tap" - :trigger [:navigate-to :contact-code] - :properties {:target :select-recipient - :type :contact-code}} - {:label "Tap" - :trigger [:navigate-to :wallet-send-assets] - :properties {:target :wallet-send-assets}} - {:label "Tap" - :trigger [:wallet.send/toggle-advanced] - :properties {:target :wallet-advanced}} - {:label "Tap" - :trigger [:wallet.send/set-signing?] - :properties {:target :wallet-open-sign-transaction}} - {:label "Tap" - :trigger [:wallet/sign-transaction] - :properties {:target :wallet-sign-transaction}} - {:label "Tap" - :trigger [:wallet/sign-transaction-modal] - :properties {:target :dapp-sign-transaction}} - {:label "Tap" - :trigger [:navigate-to-clean :wallet] - :properties {:target :wallet-got-it}} - {:label "Tap" - :trigger [:send-transaction-message] - :properties {:target :wallet-transaction-sent}} - {:label "Tap" - :trigger [:navigate-to :collectibles-list] - :properties {:target :collectibles-list}} - {:label "Tap" - :trigger [:open-collectible-in-browser] - :properties {:target :open-collectible-in-browser}} - - ;;Profile - {:label "Tap" - :trigger [:my-profile/start-editing-profile] - :properties {:target :edit-profile}} - {:label "Tap" - :trigger [:my-profile/update-picture] - :properties {:target :edit-image - :type :gallery}} - {:label "Tap" - :trigger [:navigate-to :profile-photo-capture] - :properties {:target :edit-image - :type :capture}} - {:label "Tap" - :trigger [:navigate-to :profile-qr-viewer] - :properties {:target :share-contact-code}} - {:label "Tap" - :trigger [:set :my-profile/advanced? true] - :properties {:target :profile-advanced - :type :open}} - {:label "Tap" - :trigger [:set :my-profile/advanced? false] - :properties {:target :profile-advanced - :type :closed}} - {:label "Tap" - :trigger [:switch-dev-mode true] - :properties {:target :profile-dev-mode - :type :on}} - {:label "Tap" - :trigger [:switch-dev-mode false] - :properties {:target :profile-dev-mode - :type :off}} - {:label "Tap" - :trigger [:navigate-to :backup-seed] - :properties {:target :backup-your-seed-phrase}} - {:label "Tap" - :trigger [:set-in [:my-profile/seed :step] :12-words] - :properties {:target :seed-phrase - :type :welcome-ok}} - {:label "Tap" - :trigger [:my-profile/enter-two-random-words] - :properties {:target :seed-phrase - :type :step1-next}} - {:label "Tap" - :trigger [:my-profile/set-step :second-word] - :properties {:target :seed-phrase - :type :step2-next}} - {:label "Tap" - :trigger [:my-profile/finish] - :properties {:target :seed-phrase - :type :step3-done}}]) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index d42f41bf1c..7ed578925a 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -42,7 +42,6 @@ [status-im.test.utils.transducers] [status-im.test.utils.async] [status-im.test.utils.datetime] - [status-im.test.utils.mixpanel] [status-im.test.utils.prices] [status-im.test.utils.keychain.core] [status-im.test.utils.universal-links.core] @@ -100,11 +99,10 @@ 'status-im.test.utils.signing-phrase.core 'status-im.test.utils.transducers 'status-im.test.utils.datetime - 'status-im.test.utils.mixpanel 'status-im.test.utils.prices 'status-im.test.utils.keychain.core 'status-im.test.utils.universal-links.core 'status-im.test.utils.http 'status-im.test.ui.screens.events 'status-im.test.ui.screens.accounts.login.events - 'status-im.test.browser.events) \ No newline at end of file + 'status-im.test.browser.events) diff --git a/test/cljs/status_im/test/utils/mixpanel.cljs b/test/cljs/status_im/test/utils/mixpanel.cljs deleted file mode 100644 index 9886dadad7..0000000000 --- a/test/cljs/status_im/test/utils/mixpanel.cljs +++ /dev/null @@ -1,43 +0,0 @@ -(ns status-im.test.utils.mixpanel - (:require [cljs.test :refer [async deftest is]] - [status-im.utils.mixpanel :as mixpanel] - [cljs.core.async :as async])) - -(def definitions - (mixpanel/event->triggers - [{:trigger [:key]} - {:trigger [:key :subkey]} - {:trigger [:key2] - :filter-fn (fn [_ [_ first-parameter]] - (true? first-parameter))} - {:trigger [:key3 :p1 :p2 :p3]}])) - -(deftest matching-event - (is (empty? (mixpanel/matching-events {} [:non-existing] definitions))) - (is (= 1 (count (mixpanel/matching-events {} [:key] definitions)))) - (is (= 2 (count (mixpanel/matching-events {} [:key :subkey] definitions)))) - (is (= 1 (count (mixpanel/matching-events {} [:key2 true] definitions)))) - (is (= 1 (count (mixpanel/matching-events {} [:key3 :p1 :p2 :p3] definitions)))) - (is (empty? (mixpanel/matching-events {} [:key3 :p1 :p2 :p4] definitions))) - (is (empty? (mixpanel/matching-events {} [:key2 false] definitions))) - (is (empty? (mixpanel/matching-events {} [:key1 :another-subkey] definitions)))) - -(deftest drain-events-queue!-test - (async - done - (let [queue (async/chan (async/sliding-buffer 2000)) - results (atom [])] - (async/go - (async/