Skip to content

Commit

Permalink
[#4006] anonymous uuid for mixpanel
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed May 4, 2018
1 parent 5d5444e commit 00b8ae3
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -728,4 +730,23 @@ public void appStateChange(final String type) {
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);
}
}
9 changes: 9 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ + (BOOL)JSCEnabled
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){
Expand Down
3 changes: 3 additions & 0 deletions src/status_im/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
14 changes: 12 additions & 2 deletions src/status_im/native_module/impl/module.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
3 changes: 2 additions & 1 deletion src/status_im/native_module/module.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

7 changes: 6 additions & 1 deletion src/status_im/ui/screens/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -235,4 +239,5 @@
:wallet/wallet-selected-asset
:prices/prices
:prices/prices-loading?
:notifications/notifications]))
:notifications/notifications
::device-UUID]))
22 changes: 14 additions & 8 deletions src/status_im/ui/screens/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [_]
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/status_im/utils/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -92,15 +91,14 @@
(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)
(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)]
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?))
Expand Down

0 comments on commit 00b8ae3

Please sign in to comment.