Skip to content

Commit

Permalink
Merge branch 'release/2.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBenny committed Aug 16, 2021
2 parents 46ff630 + 94870c2 commit 0bb6ddf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

Version 2.2.1 (2021-08-16)
--------------------------
Fix Session UserID not consistent among tracker instances (#466)

Version 2.2.0 (2021-07-16)
--------------------------
Set amended v_tracker indicating wrapper tracker version (#465)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
2.2.1
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

subprojects {
group = 'com.snowplowanalytics'
version = '2.2.0'
version = '2.2.1'
repositories {
google()
maven {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ systemProp.org.gradle.internal.http.socketTimeout=120000
SONATYPE_STAGING_PROFILE=comsnowplowanalytics
GROUP=com.snowplowanalytics
POM_ARTIFACT_ID=snowplow-android-tracker
VERSION_NAME=2.2.0
VERSION_NAME=2.2.1

POM_NAME=snowplow-android-tracker
POM_PACKAGING=aar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected void setUp() throws Exception {
super.setUp();
Context context = getContext();
cleanSharedPreferences(context, TrackerConstants.SNOWPLOW_SESSION_VARS);
cleanSharedPreferences(context, TrackerConstants.SNOWPLOW_GENERAL_VARS);
}

public void testSessionInit() {
Expand All @@ -66,6 +67,7 @@ public void testFirstSession() {
Session session = getSession(3, 3);

Map<String, Object> sessionContext = getSessionContext(session,"event_1");
assertNotNull(sessionContext.get(Parameters.SESSION_USER_ID));
String sessionId = (String)sessionContext.get(Parameters.SESSION_ID);
assertEquals(1, session.getSessionIndex());
assertNotNull(sessionContext.get(Parameters.SESSION_INDEX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class TrackerConstants {
public static final String EVENT_ECOMM_ITEM = "ti";

public static final String SNOWPLOW_SESSION_VARS = "snowplow_session_vars";
public static final String SNOWPLOW_GENERAL_VARS = "snowplow_general_vars";
public static final String INSTALLATION_USER_ID = "SPInstallationUserId";

public static final String INSTALLED_BEFORE = "installed_before";
public static final String INSTALL_TIMESTAMP = "install_timestamp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package com.snowplowanalytics.snowplow.internal.session;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.StrictMode;
Expand Down Expand Up @@ -134,6 +135,7 @@ public Session(long foregroundTimeout, long backgroundTimeout, @NonNull TimeUnit
this(foregroundTimeout, backgroundTimeout, timeUnit, null, context);
}

@SuppressLint("ApplySharedPref")
@Deprecated
public Session(long foregroundTimeout, long backgroundTimeout, @NonNull TimeUnit timeUnit, @Nullable String namespace, @NonNull Context context) {
this.foregroundTimeout = timeUnit.toMillis(foregroundTimeout);
Expand Down Expand Up @@ -175,6 +177,18 @@ public Session(long foregroundTimeout, long backgroundTimeout, @NonNull TimeUnit
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}

// Get or Set the Session UserID
SharedPreferences generalPref = context.getSharedPreferences(TrackerConstants.SNOWPLOW_GENERAL_VARS, Context.MODE_PRIVATE);
String storedUserId = generalPref.getString(TrackerConstants.INSTALLATION_USER_ID, null);
if (storedUserId != null) {
userId = storedUserId;
} else if (userId != null) {
generalPref.edit()
.putString(TrackerConstants.INSTALLATION_USER_ID, userId)
.commit();
}

Logger.v(TAG, "Tracker Session Object created.");
}

Expand Down Expand Up @@ -237,7 +251,6 @@ private synchronized void updateSession(String eventId) {
}

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(Parameters.SESSION_USER_ID, userId);
editor.putString(Parameters.SESSION_ID, currentSessionId);
editor.putString(Parameters.SESSION_PREVIOUS_ID, previousSessionId);
editor.putInt(Parameters.SESSION_INDEX, sessionIndex);
Expand Down Expand Up @@ -352,11 +365,11 @@ private SharedPreferences getSessionFromSharedPreferences(@NonNull Context conte
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
SharedPreferences sharedPreferences = context.getSharedPreferences(sessionVarsName, Context.MODE_PRIVATE);
if (sharedPreferences.contains(Parameters.SESSION_USER_ID)) {
if (sharedPreferences.contains(Parameters.SESSION_ID)) {
return sharedPreferences;
} else {
sharedPreferences = context.getSharedPreferences(TrackerConstants.SNOWPLOW_SESSION_VARS, Context.MODE_PRIVATE);
if (sharedPreferences.contains(Parameters.SESSION_USER_ID)) {
if (sharedPreferences.contains(Parameters.SESSION_ID)) {
return sharedPreferences;
}
}
Expand Down

0 comments on commit 0bb6ddf

Please sign in to comment.