Skip to content

Commit

Permalink
Merge pull request #802 from mixpanel/remove-devX-tracking
Browse files Browse the repository at this point in the history
Remove Mixpanel DevX internal tracking
  • Loading branch information
zihejia authored Oct 20, 2022
2 parents f258727 + bd22fc6 commit 6fef1b9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 183 deletions.
77 changes: 0 additions & 77 deletions src/main/java/com/mixpanel/android/mpmetrics/MixpanelAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ 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();
}
Expand All @@ -211,46 +203,6 @@ public class MixpanelAPI {
}
}

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;
Expand All @@ -267,7 +219,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();
Expand Down Expand Up @@ -581,15 +532,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();
}
}
}

/**
Expand Down Expand Up @@ -665,9 +607,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);
}
Expand Down Expand Up @@ -737,9 +676,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");
}
Expand Down Expand Up @@ -2105,14 +2041,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;
}

Expand Down Expand Up @@ -2328,11 +2256,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);
}
Expand Down
106 changes: 0 additions & 106 deletions src/main/java/com/mixpanel/android/mpmetrics/PersistentIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";

}

0 comments on commit 6fef1b9

Please sign in to comment.