track sent/received events;
force sent/received ratio tracking; send mixpanel events when state is changed to online;
This commit is contained in:
parent
8cd77653f4
commit
e830183011
1
.env
1
.env
|
@ -20,3 +20,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
|
|||
DEBUG_WEBVIEW=1
|
||||
INSTABUG_SURVEYS=1
|
||||
GROUP_CHATS_ENABLED=1
|
||||
FORCE_SENT_RECEIVED_TRACKING=0
|
||||
|
|
1
.env.e2e
1
.env.e2e
|
@ -19,3 +19,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
|
|||
DEBUG_WEBVIEW=1
|
||||
INSTABUG_SURVEYS=0
|
||||
GROUP_CHATS_ENABLED=1
|
||||
FORCE_SENT_RECEIVED_TRACKING=0
|
||||
|
|
|
@ -20,3 +20,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
|
|||
DEBUG_WEBVIEW=1
|
||||
INSTABUG_SURVEYS=1
|
||||
GROUP_CHATS_ENABLED=1
|
||||
FORCE_SENT_RECEIVED_TRACKING=1
|
||||
|
|
|
@ -20,3 +20,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
|
|||
DEBUG_WEBVIEW=0
|
||||
INSTABUG_SURVEYS=1
|
||||
GROUP_CHATS_ENABLED=0
|
||||
FORCE_SENT_RECEIVED_TRACKING=0
|
||||
|
|
|
@ -95,7 +95,8 @@
|
|||
(handlers/register-handler-fx
|
||||
:transport/set-message-envelope-hash
|
||||
[re-frame/trim-v]
|
||||
(fn [{:keys [db]} [chat-id message-id envelope-hash]]
|
||||
;; message-type is used for tracking
|
||||
(fn [{:keys [db]} [chat-id message-id message-type envelope-hash]]
|
||||
{:db (assoc-in db [:transport/message-envelopes envelope-hash] {:chat-id chat-id
|
||||
:message-id message-id})}))
|
||||
|
||||
|
|
|
@ -23,11 +23,15 @@
|
|||
{::listen-to-network-status [#(re-frame/dispatch [::update-connection-status %])
|
||||
#(re-frame/dispatch [::update-network-status %])]}))
|
||||
|
||||
(handlers/register-handler-db
|
||||
(handlers/register-handler-fx
|
||||
::update-connection-status
|
||||
[re-frame/trim-v]
|
||||
(fn [db [is-connected?]]
|
||||
(assoc db :network-status (if is-connected? :online :offline))))
|
||||
(fn [{:keys [db]} [is-connected?]]
|
||||
(cond->
|
||||
{:db (assoc db :network-status (if is-connected? :online :offline))}
|
||||
|
||||
is-connected?
|
||||
(assoc :drain-mixpanel-events nil))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
::update-network-status
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
{:shh/add-new-sym-key {:web3 (:web3 db)
|
||||
:sym-key sym-key
|
||||
:on-success (fn [sym-key sym-key-id]
|
||||
(re-frame/dispatch [::add-new-sym-key {:chat-id chat-id
|
||||
(re-frame/dispatch [:group/add-new-sym-key {:chat-id chat-id
|
||||
:signature signature
|
||||
:sym-key sym-key
|
||||
:sym-key-id sym-key-id
|
||||
|
@ -45,7 +45,7 @@
|
|||
(when (user-is-group-admin? chat-id cofx)
|
||||
{:shh/get-new-sym-key {:web3 (get-in cofx [:db :web3])
|
||||
:on-success (fn [sym-key sym-key-id]
|
||||
(re-frame/dispatch [::send-new-sym-key {:chat-id chat-id
|
||||
(re-frame/dispatch [:group/send-new-sym-key {:chat-id chat-id
|
||||
:sym-key sym-key
|
||||
:sym-key-id sym-key-id
|
||||
:message message}]))}}))
|
||||
|
|
|
@ -95,7 +95,8 @@
|
|||
:payload this
|
||||
:success-event [:transport/set-message-envelope-hash
|
||||
chat-id
|
||||
(transport.utils/message-id this)]}
|
||||
(transport.utils/message-id this)
|
||||
message-type]}
|
||||
cofx))
|
||||
(receive [this chat-id signature cofx]
|
||||
{:dispatch [:chat-received-message/add (assoc (into {} this)
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
(def testfairy-token (get-config :TESTFAIRY_TOKEN))
|
||||
(def instabug-token (get-config :INSTABUG_TOKEN))
|
||||
(def instabug-surveys-enabled? (get-config :INSTABUG_SURVEYS))
|
||||
(def force-sr-ratio-tracking (get-config :FORCE_SENT_RECEIVED_TRACKING))
|
||||
|
||||
(def pow-target (js/parseFloat (get-config :POW_TARGET "0.002")))
|
||||
(def pow-time (js/parseInt (get-config :POW_TIME "1")))
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.instabug :as instabug]
|
||||
[status-im.utils.mixpanel :as mixpanel]
|
||||
[cljs.core.async :as async]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(def pre-event-callback (atom nil))
|
||||
|
@ -91,14 +92,17 @@
|
|||
(fn track-handler
|
||||
[context]
|
||||
(let [new-db (get-coeffect context :db)
|
||||
current-account-id (get-in new-db [:account/account :address])]
|
||||
(when (get-in new-db [:account/account :sharing-usage-data?])
|
||||
current-account-id (get-in new-db [:account/account :address])
|
||||
[event-name] (get-coeffect context :event)]
|
||||
(when (or
|
||||
(mixpanel/force-tracking? event-name)
|
||||
(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 (ethereum/sha3 current-account-id)]
|
||||
(doseq [{:keys [label properties]}
|
||||
(mixpanel/matching-events event mixpanel/event-by-trigger)]
|
||||
(mixpanel/matching-events new-db event mixpanel/event-by-trigger)]
|
||||
(mixpanel/track anon-id label properties offline?))
|
||||
(when (= :send-current-message (first event))
|
||||
(instabug/maybe-show-survey new-db)))))
|
||||
|
@ -137,3 +141,8 @@
|
|||
(remove (fn [{:keys [dapp? pending?]}]
|
||||
(or pending? dapp?)))
|
||||
(map :whisper-identity)))
|
||||
|
||||
(re-frame.core/reg-fx
|
||||
:drain-mixpanel-events
|
||||
(fn []
|
||||
(async/go (async/<! (mixpanel/drain-events-queue!)))))
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
[status-im.utils.platform :as platform]
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.mixpanel-events :as mixpanel-events]))
|
||||
[status-im.utils.mixpanel-events :as mixpanel-events]
|
||||
[status-im.utils.config :as config]))
|
||||
|
||||
(def base-url "http://api.mixpanel.com/")
|
||||
(def base-track-url (str base-url "track/"))
|
||||
|
@ -102,7 +103,7 @@
|
|||
(def event-by-trigger
|
||||
(event->triggers mixpanel-events/events))
|
||||
|
||||
(defn matching-events [[event-name first-arg :as event] triggers]
|
||||
(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
|
||||
|
@ -122,6 +123,17 @@
|
|||
;; will match only with [:e-name :p1 :p2 :p3] event
|
||||
(> cnt 2)
|
||||
(concat (get-in triggers (conj event event-tag))))]
|
||||
(filter (fn [{:keys [filter-fn]}]
|
||||
(or (not filter-fn) (filter-fn {:event event})))
|
||||
triggers)))
|
||||
(->> triggers
|
||||
|
||||
(filter (fn [{:keys [filter-fn]}]
|
||||
(or (not filter-fn) (filter-fn db event))))
|
||||
|
||||
(map (fn [{:keys [data-fn] :as trigger}]
|
||||
(if data-fn
|
||||
(update trigger :properties merge (data-fn db event))
|
||||
trigger))))))
|
||||
|
||||
(defn force-tracking? [event-name]
|
||||
(and config/force-sr-ratio-tracking
|
||||
(contains? #{:signals/envelope-status :chat-received-message/add}
|
||||
event-name)))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
(ns status-im.utils.mixpanel-events)
|
||||
(ns status-im.utils.mixpanel-events
|
||||
(:require [status-im.chat.models.message :as message-model]))
|
||||
;; This file is supposed to be edited by Chad.
|
||||
;; Chad loves mixpanel. When Chad was a child he dreamed of being a mixpanel tamer.
|
||||
|
||||
|
@ -192,4 +193,36 @@
|
|||
{:label "Tap"
|
||||
:trigger [:my-profile/finish]
|
||||
:properties {:target :seed-phrase
|
||||
:type :step3-done}}])
|
||||
:type :step3-done}}
|
||||
|
||||
;; sent/receive ratio
|
||||
{:label "SRratio"
|
||||
:trigger [:signals/envelope-status]
|
||||
:properties {:target :user-message-sent}
|
||||
:filter-fn (fn [db [_ envelope-hash status]]
|
||||
(when (= :sent status)
|
||||
(let [{:keys [chat-id message-id]}
|
||||
(get-in db [:transport/message-envelopes envelope-hash])
|
||||
|
||||
{:keys [message-type]}
|
||||
(get-in db [:chats chat-id :messages message-id])]
|
||||
(= :user-message message-type))))
|
||||
:data-fn (fn [db [_ envelope-hash status]]
|
||||
(when (= :sent status)
|
||||
(let [{:keys [chat-id message-id]}
|
||||
(get-in db [:transport/message-envelopes envelope-hash])
|
||||
|
||||
{:keys [message-type]}
|
||||
(get-in db [:chats chat-id :messages message-id])]
|
||||
{:message-id message-id
|
||||
:message-type message-type})))}
|
||||
|
||||
{:label "SRratio"
|
||||
:trigger [:chat-received-message/add]
|
||||
:properties {:target :user-message-received}
|
||||
:filter-fn (fn [db [_ {:keys [message-type] :as message}]]
|
||||
(and (= :user-message message-type)
|
||||
(message-model/add-to-chat? {:db db} message)))
|
||||
:data-fn (fn [db [_ {:keys [message-id message-type]}]]
|
||||
{:message-type message-type
|
||||
:message-id message-id})}])
|
||||
|
|
|
@ -7,21 +7,21 @@
|
|||
(mixpanel/event->triggers
|
||||
[{:trigger [:key]}
|
||||
{:trigger [:key :subkey]}
|
||||
{:trigger [:key2]
|
||||
:filter-fn (fn [{[_ first-parameter] :event}]
|
||||
{: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))))
|
||||
(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
|
||||
|
|
Loading…
Reference in New Issue