Skip to content

Commit

Permalink
Keep building/moving stuff in a common base class that will be used b…
Browse files Browse the repository at this point in the history
…oth in Tracks and Mixpanel Tracker.
  • Loading branch information
daniloercoli committed Aug 6, 2015
1 parent c37552f commit 6516e06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class AnalyticsTrackerNosara extends Tracker {

private static final String EVENTS_PREFIX = "wpandroid_";

private String mWpcomUserName = null;
private TracksClient mNosaraClient;

public AnalyticsTrackerNosara(Context context) {
Expand Down Expand Up @@ -347,8 +346,8 @@ public void track(AnalyticsTracker.Stat stat, Map<String, ?> properties) {

final String user;
final TracksClient.NosaraUserType userType;
if (mWpcomUserName != null) {
user = mWpcomUserName;
if (getWordPressComUserName() != null) {
user = getWordPressComUserName();
userType = TracksClient.NosaraUserType.WPCOM;
} else {
// This is just a security checks since the anonID is already available here.
Expand Down Expand Up @@ -402,6 +401,7 @@ public void endSession() {
mNosaraClient.flush();
}


@Override
public void refreshMetadata(boolean isUserConnected, boolean isWordPressComUser, boolean isJetpackUser,
int sessionCount, int numBlogs, int versionCode, String username, String email) {
Expand All @@ -410,15 +410,15 @@ public void refreshMetadata(boolean isUserConnected, boolean isWordPressComUser,
}

if (isUserConnected && isWordPressComUser) {
mWpcomUserName = username;
setWordPressComUserName(username);
// Re-unify the user
if (getAnonID() != null) {
mNosaraClient.trackAliasUser(mWpcomUserName, getAnonID());
mNosaraClient.trackAliasUser(getWordPressComUserName(), getAnonID());
clearAnonID();
}
} else {
// Not wpcom connected. Check if anonID is already present
mWpcomUserName = null;
setWordPressComUserName(null);
if (getAnonID() == null) {
generateNewAnonID();
}
Expand All @@ -443,7 +443,7 @@ public void clearAllData() {
mNosaraClient.clearUserProperties();
// Reset the anon ID here
clearAnonID();
mWpcomUserName = null;
setWordPressComUserName(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ abstract void refreshMetadata(boolean isUserConnected,boolean isWordPressComUser
abstract String getAnonIdPrefKey();

private String mAnonID = null; // do not access this variable directly. Use methods.
private String mWpcomUserName = null;
Context mContext;

public Tracker(Context context) {
Expand Down Expand Up @@ -66,4 +67,12 @@ String generateNewAnonID() {
mAnonID = uuid;
return uuid;
}

String getWordPressComUserName() {
return mWpcomUserName;
}

void setWordPressComUserName(String userName) {
mWpcomUserName = userName;
}
}

0 comments on commit 6516e06

Please sign in to comment.