track sent/received events;

force sent/received ratio tracking;
send mixpanel events when state is changed to online;
This commit is contained in:
Roman Volosovskyi 2018-04-24 11:32:25 +02:00
parent 8cd77653f4
commit e830183011
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
13 changed files with 92 additions and 27 deletions

1
.env
View File

@ -20,3 +20,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1 DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=1 INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=1 GROUP_CHATS_ENABLED=1
FORCE_SENT_RECEIVED_TRACKING=0

View File

@ -19,3 +19,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1 DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=0 INSTABUG_SURVEYS=0
GROUP_CHATS_ENABLED=1 GROUP_CHATS_ENABLED=1
FORCE_SENT_RECEIVED_TRACKING=0

View File

@ -20,3 +20,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1 DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=1 INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=1 GROUP_CHATS_ENABLED=1
FORCE_SENT_RECEIVED_TRACKING=1

View File

@ -20,3 +20,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=0 DEBUG_WEBVIEW=0
INSTABUG_SURVEYS=1 INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=0 GROUP_CHATS_ENABLED=0
FORCE_SENT_RECEIVED_TRACKING=0

View File

@ -95,7 +95,8 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:transport/set-message-envelope-hash :transport/set-message-envelope-hash
[re-frame/trim-v] [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 {:db (assoc-in db [:transport/message-envelopes envelope-hash] {:chat-id chat-id
:message-id message-id})})) :message-id message-id})}))

View File

@ -23,11 +23,15 @@
{::listen-to-network-status [#(re-frame/dispatch [::update-connection-status %]) {::listen-to-network-status [#(re-frame/dispatch [::update-connection-status %])
#(re-frame/dispatch [::update-network-status %])]})) #(re-frame/dispatch [::update-network-status %])]}))
(handlers/register-handler-db (handlers/register-handler-fx
::update-connection-status ::update-connection-status
[re-frame/trim-v] [re-frame/trim-v]
(fn [db [is-connected?]] (fn [{:keys [db]} [is-connected?]]
(assoc db :network-status (if is-connected? :online :offline)))) (cond->
{:db (assoc db :network-status (if is-connected? :online :offline))}
is-connected?
(assoc :drain-mixpanel-events nil))))
(handlers/register-handler-fx (handlers/register-handler-fx
::update-network-status ::update-network-status

View File

@ -30,7 +30,7 @@
{:shh/add-new-sym-key {:web3 (:web3 db) {:shh/add-new-sym-key {:web3 (:web3 db)
:sym-key sym-key :sym-key sym-key
:on-success (fn [sym-key sym-key-id] :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 :signature signature
:sym-key sym-key :sym-key sym-key
:sym-key-id sym-key-id :sym-key-id sym-key-id
@ -45,7 +45,7 @@
(when (user-is-group-admin? chat-id cofx) (when (user-is-group-admin? chat-id cofx)
{:shh/get-new-sym-key {:web3 (get-in cofx [:db :web3]) {:shh/get-new-sym-key {:web3 (get-in cofx [:db :web3])
:on-success (fn [sym-key sym-key-id] :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 sym-key
:sym-key-id sym-key-id :sym-key-id sym-key-id
:message message}]))}})) :message message}]))}}))

View File

@ -95,7 +95,8 @@
:payload this :payload this
:success-event [:transport/set-message-envelope-hash :success-event [:transport/set-message-envelope-hash
chat-id chat-id
(transport.utils/message-id this)]} (transport.utils/message-id this)
message-type]}
cofx)) cofx))
(receive [this chat-id signature cofx] (receive [this chat-id signature cofx]
{:dispatch [:chat-received-message/add (assoc (into {} this) {:dispatch [:chat-received-message/add (assoc (into {} this)

View File

@ -38,6 +38,7 @@
(def testfairy-token (get-config :TESTFAIRY_TOKEN)) (def testfairy-token (get-config :TESTFAIRY_TOKEN))
(def instabug-token (get-config :INSTABUG_TOKEN)) (def instabug-token (get-config :INSTABUG_TOKEN))
(def instabug-surveys-enabled? (get-config :INSTABUG_SURVEYS)) (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-target (js/parseFloat (get-config :POW_TARGET "0.002")))
(def pow-time (js/parseInt (get-config :POW_TIME "1"))) (def pow-time (js/parseInt (get-config :POW_TIME "1")))

View File

@ -6,6 +6,7 @@
[status-im.utils.ethereum.core :as ethereum] [status-im.utils.ethereum.core :as ethereum]
[status-im.utils.instabug :as instabug] [status-im.utils.instabug :as instabug]
[status-im.utils.mixpanel :as mixpanel] [status-im.utils.mixpanel :as mixpanel]
[cljs.core.async :as async]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(def pre-event-callback (atom nil)) (def pre-event-callback (atom nil))
@ -91,14 +92,17 @@
(fn track-handler (fn track-handler
[context] [context]
(let [new-db (get-coeffect context :db) (let [new-db (get-coeffect context :db)
current-account-id (get-in new-db [:account/account :address])] current-account-id (get-in new-db [:account/account :address])
(when (get-in new-db [:account/account :sharing-usage-data?]) [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) (let [event (get-coeffect context :event)
offline? (or (= :offline (:network-status new-db)) offline? (or (= :offline (:network-status new-db))
(= :offline (:sync-state new-db))) (= :offline (:sync-state new-db)))
anon-id (ethereum/sha3 current-account-id)] anon-id (ethereum/sha3 current-account-id)]
(doseq [{:keys [label properties]} (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?)) (mixpanel/track anon-id label properties offline?))
(when (= :send-current-message (first event)) (when (= :send-current-message (first event))
(instabug/maybe-show-survey new-db))))) (instabug/maybe-show-survey new-db)))))
@ -137,3 +141,8 @@
(remove (fn [{:keys [dapp? pending?]}] (remove (fn [{:keys [dapp? pending?]}]
(or pending? dapp?))) (or pending? dapp?)))
(map :whisper-identity))) (map :whisper-identity)))
(re-frame.core/reg-fx
:drain-mixpanel-events
(fn []
(async/go (async/<! (mixpanel/drain-events-queue!)))))

View File

@ -10,7 +10,8 @@
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[taoensso.timbre :as log] [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-url "http://api.mixpanel.com/")
(def base-track-url (str base-url "track/")) (def base-track-url (str base-url "track/"))
@ -102,7 +103,7 @@
(def event-by-trigger (def event-by-trigger
(event->triggers mixpanel-events/events)) (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) (let [cnt (count event)
triggers (cond-> triggers (cond->
;; first we get all events which are triggered by event name ;; 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 ;; will match only with [:e-name :p1 :p2 :p3] event
(> cnt 2) (> cnt 2)
(concat (get-in triggers (conj event event-tag))))] (concat (get-in triggers (conj event event-tag))))]
(filter (fn [{:keys [filter-fn]}] (->> triggers
(or (not filter-fn) (filter-fn {:event event})))
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)))

View File

@ -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. ;; This file is supposed to be edited by Chad.
;; Chad loves mixpanel. When Chad was a child he dreamed of being a mixpanel tamer. ;; Chad loves mixpanel. When Chad was a child he dreamed of being a mixpanel tamer.
@ -192,4 +193,36 @@
{:label "Tap" {:label "Tap"
:trigger [:my-profile/finish] :trigger [:my-profile/finish]
:properties {:target :seed-phrase :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})}])

View File

@ -7,21 +7,21 @@
(mixpanel/event->triggers (mixpanel/event->triggers
[{:trigger [:key]} [{:trigger [:key]}
{:trigger [:key :subkey]} {:trigger [:key :subkey]}
{:trigger [:key2] {:trigger [:key2]
:filter-fn (fn [{[_ first-parameter] :event}] :filter-fn (fn [_ [_ first-parameter]]
(true? first-parameter))} (true? first-parameter))}
{:trigger [:key3 :p1 :p2 :p3]}])) {:trigger [:key3 :p1 :p2 :p3]}]))
(deftest matching-event (deftest matching-event
(is (empty? (mixpanel/matching-events [:non-existing] definitions))) (is (empty? (mixpanel/matching-events {} [:non-existing] definitions)))
(is (= 1 (count (mixpanel/matching-events [:key] definitions)))) (is (= 1 (count (mixpanel/matching-events {} [:key] definitions))))
(is (= 2 (count (mixpanel/matching-events [:key :subkey] 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 {} [:key2 true] definitions))))
(is (= 1 (count (mixpanel/matching-events [:key3 :p1 :p2 :p3] 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 {} [:key3 :p1 :p2 :p4] definitions)))
(is (empty? (mixpanel/matching-events [:key2 false] definitions))) (is (empty? (mixpanel/matching-events {} [:key2 false] definitions)))
(is (empty? (mixpanel/matching-events [:key1 :another-subkey] definitions)))) (is (empty? (mixpanel/matching-events {} [:key1 :another-subkey] definitions))))
(deftest drain-events-queue!-test (deftest drain-events-queue!-test
(async (async