From bd22fc65dd57c39eaa30f252663eac942b946340 Mon Sep 17 00:00:00 2001 From: Zihe Jia Date: Tue, 11 Oct 2022 16:43:28 -0700 Subject: [PATCH] remove Mixpanel DevX internal tracking --- .../android/mpmetrics/MixpanelAPI.java | 77 ------------- .../android/mpmetrics/PersistentIdentity.java | 106 ------------------ 2 files changed, 183 deletions(-) diff --git a/src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java b/src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java index 3c66982d..40b7772d 100644 --- a/src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java +++ b/src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java @@ -192,59 +192,11 @@ public class MixpanelAPI { } catch (JSONException e) {} } - if (isDebuggingMode()) { - try { - if (mToken.length() == 32) { // Only track DevX when the token is valid - trackMixpanelDevX(); - } - } catch (JSONException e) {} - } - if (!mConfig.getDisableExceptionHandler()) { ExceptionHandler.init(); } } - private boolean isDebuggingMode() { - return (getContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; - } - - private void trackMixpanelDevX() throws JSONException { - trackDebugLaunch(); - trackMixpanelImplemented(); - } - - private void trackDebugLaunch() throws JSONException { - int debugInitCount = mPersistentIdentity.debugInitCount(mToken); - debugInitCount += 1; - mPersistentIdentity.setDebugInitCount(mToken, debugInitCount); - final JSONObject debugProps = new JSONObject(); - debugProps.put("Debug Launch Count", debugInitCount); - sendHttpEvent("SDK Debug Launch", "metrics-1", mToken, debugProps, true); - } - - private void trackMixpanelImplemented() throws JSONException { - if (mPersistentIdentity.hasImplemented(mToken)) { - return; - } - int implementationScore = 0; - implementationScore += mPersistentIdentity.hasMPDebugTracked(mToken) ? 1 : 0; - implementationScore += mPersistentIdentity.hasMPDebugIdentified(mToken) ? 1 : 0; - implementationScore += mPersistentIdentity.hasMPDebugAliased(mToken) ? 1 : 0; - implementationScore += mPersistentIdentity.hasMPDebugUsedPeople(mToken) ? 1 : 0; - - final JSONObject implementedProps = new JSONObject(); - implementedProps.put("Tracked", mPersistentIdentity.hasMPDebugTracked(mToken)); - implementedProps.put("Identified", mPersistentIdentity.hasMPDebugIdentified(mToken)); - implementedProps.put("Aliased", mPersistentIdentity.hasMPDebugAliased(mToken)); - implementedProps.put("Used People", mPersistentIdentity.hasMPDebugUsedPeople(mToken)); - - if (implementationScore >= 3) { - sendHttpEvent("SDK Implemented", "metrics-1", mToken, implementedProps, true); - mPersistentIdentity.setHasImplemented(mToken); - } - } - private void sendHttpEvent(String eventName, String token, String distinctId, JSONObject properties, boolean updatePeople) throws JSONException { final JSONObject superProperties = getSuperProperties(); String lib = null; @@ -261,7 +213,6 @@ private void sendHttpEvent(String eventName, String token, String distinctId, JS messageProps.put("mp_lib", null != lib ? lib : "Android"); messageProps.put("distinct_id", distinctId); messageProps.put("$lib_version", null != libVersion ? libVersion : MPConfig.VERSION); - messageProps.put("DevX", true); messageProps.put("Project Token", distinctId); if (null != properties) { final Iterator propIter = properties.keys(); @@ -575,15 +526,6 @@ public void setUseIpAddressForGeolocation(boolean useIpAddressForGeolocation) { */ public void setEnableLogging(boolean enableLogging) { mConfig.setEnableLogging(enableLogging); - final JSONObject debugProps = new JSONObject(); - if (isDebuggingMode()) { - try { - debugProps.put("Logging Enabled", enableLogging); - sendHttpEvent("Toggle SDK Logging", "metrics-1", mToken, debugProps, true); - } catch (JSONException e) { - e.printStackTrace(); - } - } } /** @@ -659,9 +601,6 @@ public void alias(String alias, String original) { j.put("alias", alias); j.put("original", original); track("$create_alias", j); - if (isDebuggingMode()) { - mPersistentIdentity.setHasMPDebugAliased(mToken); - } } catch (final JSONException e) { MPLog.e(LOGTAG, "Failed to alias", e); } @@ -731,9 +670,6 @@ private void identify(String distinctId, boolean markAsUserId, boolean usePeople JSONObject identifyPayload = new JSONObject(); identifyPayload.put("$anon_distinct_id", currentEventsDistinctId); track("$identify", identifyPayload); - if (isDebuggingMode()) { - mPersistentIdentity.setHasMPDebugIdentified(mToken); - } } catch (JSONException e) { MPLog.e(LOGTAG, "Could not track $identify event"); } @@ -2099,14 +2035,6 @@ private JSONObject stdPeopleMessage(String actionType, Object properties) dataObj.put("$user_id", distinctId); } dataObj.put("$mp_metadata", mSessionMetadata.getMetadataForPeople()); - - if (((getContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0)) { - if (properties instanceof JSONObject && ((JSONObject) properties).keys().hasNext() - && !((JSONObject) properties).keys().next().startsWith("$ae_")) { - mPersistentIdentity.setHasMPDebugUsedPeople(mToken); - } - } - return dataObj; } @@ -2322,11 +2250,6 @@ protected void track(String eventName, JSONObject properties, boolean isAutomati new AnalyticsMessages.EventDescription(eventName, messageProps, mToken, isAutomaticEvent, mSessionMetadata.getMetadataForEvent()); mMessages.eventsMessage(eventDescription); - if (isDebuggingMode()) { - if (!eventName.startsWith("$")) { - mPersistentIdentity.setHasMPDebugTracked(mToken); - } - } } catch (final JSONException e) { MPLog.e(LOGTAG, "Exception tracking event " + eventName, e); } diff --git a/src/main/java/com/mixpanel/android/mpmetrics/PersistentIdentity.java b/src/main/java/com/mixpanel/android/mpmetrics/PersistentIdentity.java index a9b3dd99..3e538f7d 100644 --- a/src/main/java/com/mixpanel/android/mpmetrics/PersistentIdentity.java +++ b/src/main/java/com/mixpanel/android/mpmetrics/PersistentIdentity.java @@ -332,105 +332,6 @@ public void addTimeEvent(String timeEventName, Long timeEventTimestamp) { } } - private synchronized int getIntFlagValue(String token, String flagName) { - int intFlagValue = 0; - try { - SharedPreferences prefs = mMixpanelPreferences.get(); - intFlagValue = prefs.getInt(token + flagName, 0); - } catch (final ExecutionException e) { - MPLog.e(LOGTAG, "Couldn't read internal Mixpanel shared preferences.", e.getCause()); - } catch (final InterruptedException e) { - MPLog.e(LOGTAG, "Couldn't read internal Mixpanel from shared preferences.", e); - } - return intFlagValue; - } - - private synchronized void setIntFlagValue(String token, String flagName, int flagValue) { - try { - SharedPreferences.Editor mixpanelPreferencesEditor = mMixpanelPreferences.get().edit(); - mixpanelPreferencesEditor.putInt(token + flagName, flagValue); - writeEdits(mixpanelPreferencesEditor); - } catch (ExecutionException e) { - MPLog.e(LOGTAG, "Couldn't write internal Mixpanel shared preferences.", e.getCause()); - } catch (InterruptedException e) { - MPLog.e(LOGTAG, "Couldn't write internal Mixpanel from shared preferences.", e); - } - } - - private synchronized boolean getBoolFlagValue(String token, String flagName) { - boolean boolFlagValue = false; - try { - SharedPreferences prefs = mMixpanelPreferences.get(); - boolFlagValue = prefs.getBoolean(token + flagName, false); - } catch (final ExecutionException e) { - MPLog.e(LOGTAG, "Couldn't read internal Mixpanel shared preferences.", e.getCause()); - } catch (final InterruptedException e) { - MPLog.e(LOGTAG, "Couldn't read internal Mixpanel from shared preferences.", e); - } - return boolFlagValue; - - } - - private synchronized void setBooleanFlagValue(String token, String flagName, boolean flagValue) { - try { - SharedPreferences.Editor mixpanelPreferencesEditor = mMixpanelPreferences.get().edit(); - mixpanelPreferencesEditor.putBoolean(token + flagName, flagValue); - writeEdits(mixpanelPreferencesEditor); - } catch (ExecutionException e) { - MPLog.e(LOGTAG, "Couldn't write internal Mixpanel shared preferences.", e.getCause()); - } catch (InterruptedException e) { - MPLog.e(LOGTAG, "Couldn't write internal Mixpanel from shared preferences.", e); - } - } - - public synchronized int debugInitCount(String token) { - return getIntFlagValue(token, MP_DEBUG_INIT_COUNT_KEY); - } - - public synchronized void setDebugInitCount(String token, int debugInitCount) { - setIntFlagValue(token, MP_DEBUG_INIT_COUNT_KEY, debugInitCount); - } - - public synchronized boolean hasImplemented(String token) { - return getBoolFlagValue(token, MP_HAS_IMPLEMENTED_KEY); - } - - public synchronized void setHasImplemented(String token) { - setBooleanFlagValue(token, MP_HAS_IMPLEMENTED_KEY, true); - } - - public synchronized boolean hasMPDebugTracked(String token) { - return getBoolFlagValue(token, MP_HAS_DEBUG_TRACKED_KEY); - } - - public synchronized void setHasMPDebugTracked(String token) { - setBooleanFlagValue(token, MP_HAS_DEBUG_TRACKED_KEY, true); - } - - public synchronized boolean hasMPDebugIdentified(String token) { - return getBoolFlagValue(token, MP_HAS_DEBUG_IDENTIFIED_KEY); - } - - public synchronized void setHasMPDebugIdentified(String token) { - setBooleanFlagValue(token, MP_HAS_DEBUG_IDENTIFIED_KEY, true); - } - - public synchronized boolean hasMPDebugAliased(String token) { - return getBoolFlagValue(token, MP_HAS_DEBUG_ALIASED_KEY); - } - - public synchronized void setHasMPDebugAliased(String token) { - setBooleanFlagValue(token, MP_HAS_DEBUG_ALIASED_KEY, true); - } - - public synchronized boolean hasMPDebugUsedPeople(String token) { - return getBoolFlagValue(token, MP_HAS_DEBUG_USED_PEOPLE_KEY); - } - - public synchronized void setHasMPDebugUsedPeople(String token) { - setBooleanFlagValue(token, MP_HAS_DEBUG_USED_PEOPLE_KEY, true); - } - public synchronized boolean isFirstIntegration(String token) { boolean firstLaunch = false; try { @@ -741,11 +642,4 @@ private static void writeEdits(final SharedPreferences.Editor editor) { private static final String DELIMITER = ","; private static final String LOGTAG = "MixpanelAPI.PIdentity"; - private static final String MP_DEBUG_INIT_COUNT_KEY = "mpDebugInitCount"; - private static final String MP_HAS_IMPLEMENTED_KEY = "mpHasImplemented"; - private static final String MP_HAS_DEBUG_TRACKED_KEY = "mpHasDebugTracked"; - private static final String MP_HAS_DEBUG_IDENTIFIED_KEY = "mpHasDebugIdentified"; - private static final String MP_HAS_DEBUG_ALIASED_KEY = "mpHasDebugAliased"; - private static final String MP_HAS_DEBUG_USED_PEOPLE_KEY = "mpHasDebugUsedPeople"; - }