Skip to content

Commit

Permalink
Merge branch 'main' into fix-release-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu-xiaowei authored Mar 6, 2024
2 parents f17a819 + caf6969 commit 5ee509e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 50 deletions.
1 change: 0 additions & 1 deletion .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
cache: gradle
- name: Build SDK release aar file
run: |
echo ${{ github.event.pull_request.title }}
chmod +x gradlew
./gradlew assembleRelease
- name: Set up JDK 17
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Add the following dependency to your `app` module's `build.gradle` file.

```groovy
dependencies {
implementation 'software.aws.solution:clickstream:0.11.0'
implementation 'software.aws.solution:clickstream:0.11.1'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Life
} else if (event == Lifecycle.Event.ON_START) {
LOG.debug("Application entered the foreground.");
isFromForeground = true;
boolean isNewSession = sessionClient.initialSession();
autoRecordEventClient.handleAppStart();
autoRecordEventClient.updateStartEngageTimestamp();
boolean isNewSession = sessionClient.initialSession();
if (isNewSession) {
autoRecordEventClient.handleSessionStart();
autoRecordEventClient.setIsEntrances();
recordScreenViewAfterSessionStart();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ public void handleAppStart() {
isFirstTime = false;
}

/**
* handle session start events.
*/
public void handleSessionStart() {
final AnalyticsEvent event =
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SESSION_START);
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
}

/**
* handle the app end event.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public SessionClient(@NonNull final ClickstreamContext clickstreamContext) {
public synchronized boolean initialSession() {
session = Session.getInstance(clickstreamContext, session);
this.clickstreamContext.getAnalyticsClient().setSession(session);
if (session.isNewSession()) {
final AnalyticsEvent event =
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SESSION_START);
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
}
return session.isNewSession();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,15 @@ public void testSessionTimeoutAfterReopenTheApp() throws Exception {
JSONObject jsonObject2 = new JSONObject(eventString2);
String eventName2 = jsonObject2.getString("event_type");
assertEquals(Event.PresetEvent.SESSION_START, eventName2);

// assert that the second app start event will have the same session id
cursor.moveToPrevious();
String eventString3 = cursor.getString(2);
JSONObject jsonObject3 = new JSONObject(eventString3);
String eventName3 = jsonObject3.getString("event_type");
assertEquals(Event.PresetEvent.APP_START, eventName3);
assertEquals(jsonObject3.getJSONObject("attributes").getString("_session_id"),
jsonObject2.getJSONObject("attributes").getString("_session_id"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
package software.aws.solution.clickstream;

import android.content.Context;
import android.database.Cursor;
import androidx.test.core.app.ApplicationProvider;

import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -31,7 +28,6 @@
import software.aws.solution.clickstream.client.ClickstreamManager;
import software.aws.solution.clickstream.client.Session;
import software.aws.solution.clickstream.client.SessionClient;
import software.aws.solution.clickstream.client.db.ClickstreamDBUtil;
import software.aws.solution.clickstream.util.ReflectUtil;

import static org.mockito.Mockito.mock;
Expand All @@ -43,7 +39,6 @@
public class SessionClientTest {
private SessionClient client;
private AnalyticsClient analyticsClient;
private ClickstreamDBUtil dbUtil;
private ClickstreamContext clickstreamContext;

/**
Expand All @@ -53,7 +48,6 @@ public class SessionClientTest {
public void setup() {
Context context = ApplicationProvider.getApplicationContext();

dbUtil = new ClickstreamDBUtil(context);
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
configurationBuilder.withAppId("demo-app")
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
Expand All @@ -74,22 +68,12 @@ public void setup() {
*/
@Test
public void testExecuteStart() throws Exception {
client.initialSession();
boolean isNewSession = client.initialSession();
Session session = (Session) ReflectUtil.getFiled(client, "session");
Assert.assertNotNull(session);
Session clientSession = (Session) ReflectUtil.getFiled(analyticsClient, "session");
Assert.assertNotNull(clientSession);
Assert.assertEquals(1, dbUtil.getTotalNumber());
Cursor cursor = dbUtil.queryAllEvents();
cursor.moveToFirst();
String eventString = cursor.getString(2);
JSONObject jsonObject = new JSONObject(eventString);
Assert.assertEquals("_session_start", jsonObject.getString("event_type"));
JSONObject attributes = jsonObject.getJSONObject("attributes");
Assert.assertNotNull(attributes.getString("_session_id"));
Assert.assertNotNull(attributes.getString("_session_start_timestamp"));
Assert.assertNotNull(attributes.getString("_session_duration"));
cursor.close();
Assert.assertTrue(isNewSession);
}

/**
Expand All @@ -106,17 +90,6 @@ public void testExecuteStartAndStore() throws Exception {
client.storeSession();
Session storedSession = (Session) ReflectUtil.getFiled(client, "session");
Assert.assertFalse(storedSession.isNewSession());

Assert.assertEquals(1, dbUtil.getTotalNumber());
Cursor cursor = dbUtil.queryAllEvents();
cursor.moveToFirst();
String eventString = cursor.getString(2);
JSONObject jsonObject = new JSONObject(eventString);
JSONObject attributes = jsonObject.getJSONObject("attributes");
Assert.assertNotNull(attributes.getString("_session_id"));
Assert.assertNotNull(attributes.getString("_session_start_timestamp"));
Assert.assertNotNull(attributes.getString("_session_duration"));
cursor.close();
}


Expand All @@ -143,8 +116,6 @@ public void testExecuteStartTwiceWithoutSessionTimeout() throws Exception {
Assert.assertEquals(session.getSessionID(), newSession.getSessionID());
Assert.assertEquals(session.getStartTime(), newSession.getStartTime());
Assert.assertEquals(1, newSession.getSessionIndex());

Assert.assertEquals(1, dbUtil.getTotalNumber());
}


Expand Down Expand Up @@ -172,8 +143,6 @@ public void testExecuteStartTwiceWithSessionTimeout() throws Exception {
Assert.assertNotEquals(session.getSessionID(), newSession.getSessionID());
Assert.assertNotEquals(session.getStartTime(), newSession.getStartTime());
Assert.assertEquals(2, newSession.getSessionIndex());

Assert.assertEquals(2, dbUtil.getTotalNumber());
}


Expand All @@ -185,12 +154,4 @@ public void testInitSessionClientWithNullAnalyticsClient() {
ClickstreamContext context = mock(ClickstreamContext.class);
new SessionClient(context);
}

/**
* close db.
*/
@After
public void tearDown() {
dbUtil.closeDB();
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ org.gradle.jvmargs=-Xmx4g
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

VERSION_NAME=0.11.0
VERSION_NAME=0.11.1

POM_GROUP=software.aws.solution
POM_ARTIFACT_ID=clickstream
Expand Down

0 comments on commit 5ee509e

Please sign in to comment.