Skip to content
Permalink
Browse files

Show user survey when N amount of messages sent

It's a temporary solution until Instabug fix User Events API

(cherry picked from commit 05c478bac6f338ba8577278c80608d0b3f6a8ddb)
  • Loading branch information...
dmitryn authored and janherich committed Apr 27, 2018
1 parent 1278dc8 commit 3d146e578c15508f4fd4b4bb8e8dacc7885cd459
1 .env
@@ -18,3 +18,4 @@ DEFAULT_NETWORK=mainnet_rpc
TESTFAIRY_TOKEN=969f6c921cb435cea1d41d1ea3f5b247d6026d55
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=1
@@ -17,3 +17,4 @@ POW_TIME=1
DEFAULT_NETWORK=testnet_rpc
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=0
@@ -18,3 +18,4 @@ POW_TIME=1
DEFAULT_NETWORK=mainnet_rpc
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=1
@@ -18,3 +18,4 @@ POW_TIME=1
DEFAULT_NETWORK=testnet_rpc
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=0
INSTABUG_SURVEYS=1
@@ -41,7 +41,7 @@
[status-im.utils.notifications :as notifications]
[status-im.utils.handlers :as handlers]
[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]
@@ -346,7 +346,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]
@@ -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")))
@@ -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])
(:require-macros status-im.utils.handlers))
@@ -101,7 +102,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
@@ -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)

0 comments on commit 3d146e5

Please sign in to comment.
You can’t perform that action at this time.