From 62af757fa14263b28a91eb9164ea9a95493341bc Mon Sep 17 00:00:00 2001 From: Dmitry Novotochinov Date: Fri, 27 Apr 2018 16:47:13 +0300 Subject: [PATCH] Show user survey when N amount of messages sent It's a temporary solution until Instabug fix User Events API --- .env | 1 + .env.e2e | 1 + .env.jenkins | 1 + .env.prod | 1 + src/status_im/ui/screens/events.cljs | 4 +-- src/status_im/utils/config.cljs | 1 + src/status_im/utils/handlers.cljs | 5 +++- src/status_im/utils/instabug.cljs | 37 ++++++++++++++++++++++++++++ 8 files changed, 48 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 2cecb7f3f0..65ac66f3ce 100644 --- a/.env +++ b/.env @@ -18,3 +18,4 @@ DEFAULT_NETWORK=mainnet_rpc TESTFAIRY_TOKEN=969f6c921cb435cea1d41d1ea3f5b247d6026d55 INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c DEBUG_WEBVIEW=1 +INSTABUG_SURVEYS=1 diff --git a/.env.e2e b/.env.e2e index 47820bbe50..7e6693cc83 100644 --- a/.env.e2e +++ b/.env.e2e @@ -17,3 +17,4 @@ POW_TIME=1 DEFAULT_NETWORK=testnet_rpc INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c DEBUG_WEBVIEW=1 +INSTABUG_SURVEYS=0 diff --git a/.env.jenkins b/.env.jenkins index eca125e2f3..2ff9f86949 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -18,3 +18,4 @@ POW_TIME=1 DEFAULT_NETWORK=mainnet_rpc INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c DEBUG_WEBVIEW=1 +INSTABUG_SURVEYS=1 diff --git a/.env.prod b/.env.prod index 18c33a60bc..46cef62ad6 100644 --- a/.env.prod +++ b/.env.prod @@ -18,3 +18,4 @@ POW_TIME=1 DEFAULT_NETWORK=testnet_rpc INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c DEBUG_WEBVIEW=0 +INSTABUG_SURVEYS=1 diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index 73165c450b..d774d8d546 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -42,7 +42,7 @@ [status-im.utils.handlers :as handlers] [status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.http :as http] - [status-im.utils.instabug :as inst] + [status-im.utils.instabug :as instabug] [status-im.utils.mixpanel :as mixpanel] [status-im.utils.platform :as platform] [status-im.utils.types :as types] @@ -348,7 +348,7 @@ :signal-event (fn [_ [_ event-str]] (log/debug :event-str event-str) - (inst/log (str "Signal event: " event-str)) + (instabug/log (str "Signal event: " event-str)) (let [{:keys [type event]} (types/json->clj event-str) to-dispatch (case type "sign-request.queued" [:sign-request-queued event] diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index be7c5a708a..54c32b1604 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -37,6 +37,7 @@ (def default-network (get-config :DEFAULT_NETWORK)) (def testfairy-token (get-config :TESTFAIRY_TOKEN)) (def instabug-token (get-config :INSTABUG_TOKEN)) +(def instabug-surveys-enabled? (get-config :INSTABUG_SURVEYS)) (def pow-target (js/parseFloat (get-config :POW_TARGET "0.002"))) (def pow-time (js/parseInt (get-config :POW_TIME "1"))) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 3062e34612..4853f69c94 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -4,6 +4,7 @@ [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.ethereum.core :as ethereum] + [status-im.utils.instabug :as instabug] [status-im.utils.mixpanel :as mixpanel] [taoensso.timbre :as log])) @@ -100,7 +101,9 @@ anon-id (ethereum/sha3 current-account-id)] (doseq [{:keys [label properties]} (mixpanel/matching-events 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)) + (instabug/maybe-show-survey new-db))))) context))) (defn register-handler diff --git a/src/status_im/utils/instabug.cljs b/src/status_im/utils/instabug.cljs index 5583b92b04..ccde4acb4a 100644 --- a/src/status_im/utils/instabug.cljs +++ b/src/status_im/utils/instabug.cljs @@ -3,6 +3,43 @@ [status-im.utils.config :as config] [status-im.react-native.js-dependencies :as rn-dependencies])) +(def instabug rn-dependencies/instabug) + +;; `event` is an event name, e.g. "Tap" +;; `properties` is a map of event details or nil, e.g. {:target :send-current-message} +;; (see mixpanel_events.edn for list of trackable events) + +(def survey-triggers + [{:event :send-current-message :count 4 :token "UqtvIKgVDUTo4l_sDS-fwA"} + {:event :send-current-message :count 29 :token "Hr9Dk3krPK7PPxuDbHAmXg"}]) + +;; 2018-05-07 12:00:00 +(def survey-enabled-timestamp 1525694400000) + +(defn maybe-show-survey [db] + (when config/instabug-surveys-enabled? + (let [sent-messages (->> db + :chats + (filter (fn [[chat-name _]] (not= "console" chat-name))) + (map second) + (mapcat (comp vals :messages)) + (filter :outgoing)) + sent-messages-count (count sent-messages) + sent-messages-after-ts-count (->> sent-messages + (filter #(> (:ts %) survey-enabled-timestamp)) + count) + {:keys [token]} (first (filter (fn [{:keys [count]}] + (or + (= count sent-messages-count) + (= count sent-messages-after-ts-count))) + survey-triggers))] + (when token + (.showSurveyWithToken instabug token))))) + +(defn track [event properties] + ;; NOTE(dmitryn) disabled until Instabug fix User Events + #_(.logUserEventWithNameAndParams instabug event properties)) + (defn log [str] (if js/goog.DEBUG (log/debug str)