[#4006] anonymous uuid for mixpanel

This commit is contained in:
Roman Volosovskyi 2018-05-01 12:27:04 +02:00
parent 5d5444e3de
commit 00b8ae311d
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
8 changed files with 68 additions and 15 deletions

View File

@ -1,6 +1,8 @@
package im.status.ethereum.module;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.*;
import android.view.WindowManager;
@ -728,4 +730,23 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
Log.d(TAG, "AppStateChange: " + type);
Statusgo.AppStateChange(type);
}
private static String uniqueID = null;
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
@ReactMethod
public void getDeviceUUID(final Callback callback) {
if (uniqueID == null) {
SharedPreferences sharedPrefs = this.getReactApplicationContext().getSharedPreferences(
PREF_UNIQUE_ID, Context.MODE_PRIVATE);
uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
if (uniqueID == null) {
uniqueID = UUID.randomUUID().toString();
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString(PREF_UNIQUE_ID, uniqueID);
editor.commit();
}
}
callback.invoke(uniqueID);
}
}

View File

@ -426,6 +426,15 @@ RCT_EXPORT_METHOD(appStateChange:(NSString *)type) {
AppStateChange((char *) [type UTF8String]);
}
RCT_EXPORT_METHOD(getDeviceUUID:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"getDeviceUUID() method called");
#endif
NSString* Identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
callback(@[Identifier]);
}
+ (void)signalEvent:(const char *) signal
{
if(!signal){

View File

@ -100,3 +100,6 @@
(defn app-state-change [state]
(module-interface/-app-state-change rns-module state))
(defn get-device-UUID [callback]
(module-interface/-get-device-UUID rns-module callback))

View File

@ -12,7 +12,8 @@
[status-im.utils.async :as async-util :refer [timeout]]
[status-im.react-native.js-dependencies :as rn-dependencies]
[status-im.native-module.module :as module]
[status-im.utils.config :as config]))
[status-im.utils.config :as config]
[clojure.string :as string]))
;; if StatusModule is not initialized better to store
;; calls and make them only when StatusModule is ready
@ -243,6 +244,13 @@
(defn app-state-change [state]
(.appStateChange status state))
(defn get-device-UUID [callback]
(call-module
#(.getDeviceUUID
status
(fn [UUID]
(callback (string/upper-case UUID))))))
(defrecord ReactNativeStatus []
module/IReactNativeStatus
;; status-go calls
@ -293,4 +301,6 @@
(-connection-change [this data]
(connection-change data))
(-app-state-change [this state]
(app-state-change state)))
(app-state-change state))
(-get-device-UUID [this callback]
(get-device-UUID callback)))

View File

@ -23,5 +23,6 @@
(-add-peer [this enode callback])
(-close-application [this])
(-connection-change [this data])
(-app-state-change [this state]))
(-app-state-change [this state])
(-get-device-UUID [this callback]))

View File

@ -132,6 +132,10 @@
(spec/def ::message-envelopes (spec/nilable map?))
;;;;UUID
(spec/def ::device-UUID (spec/nilable string?))
(spec/def ::db (allowed-keys
:opt
[:contacts/contacts
@ -235,4 +239,5 @@
:wallet/wallet-selected-asset
:prices/prices
:prices/prices-loading?
:notifications/notifications]))
:notifications/notifications
::device-UUID]))

View File

@ -180,6 +180,11 @@
(i18n/label :testfairy-title)
(i18n/label :testfairy-message)))))
(re-frame/reg-fx
::init-device-UUID
(fn []
(status/get-device-UUID #(re-frame/dispatch [:set :device-UUID %]))))
(re-frame/reg-fx
::get-fcm-token-fx
(fn [_]
@ -224,14 +229,15 @@
{::got-encryption-key-fx opts}))
(handlers/register-handler-fx
:initialize-app
(fn [_ [_ encryption-key]]
{::testfairy-alert nil
:dispatch-n [[:initialize-db encryption-key]
[:load-accounts]
[:initialize-views]
[:listen-to-network-status]
[:initialize-geth]]}))
:initialize-app
(fn [_ [_ encryption-key]]
{::init-device-UUID nil
::testfairy-alert nil
:dispatch-n [[:initialize-db encryption-key]
[:load-accounts]
[:initialize-views]
[:listen-to-network-status]
[:initialize-geth]]}))
(handlers/register-handler-fx
:logout

View File

@ -3,7 +3,6 @@
[clojure.string :as string]
[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]
[cljs.core.async :as async]
@ -92,7 +91,6 @@
(fn track-handler
[context]
(let [new-db (get-coeffect context :db)
current-account-id (get-in new-db [:account/account :address])
[event-name] (get-coeffect context :event)]
(when (or
(mixpanel/force-tracking? event-name)
@ -100,7 +98,7 @@
(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)]
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?))