Skip to content

Commit

Permalink
feat: support closing screen view event recording (#26)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaoweii <[email protected]>
  • Loading branch information
zhu-xiaowei and xiaoweii committed Aug 18, 2023
1 parent cb541e6 commit ece04bf
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 26 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ ClickstreamAnalytics.getClickStreamConfiguration()
.withAuthCookie("your authentication cookie")
.withSendEventsInterval(10000)
.withSessionTimeoutDuration(1800000)
.withTrackScreenViewEvents(false)
.withTrackAppExceptionEvents(false)
.withLogEvents(true)
.withCustomDns(CustomOkhttpDns.getInstance())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void configure(
}

if (pluginConfiguration.has(ConfigurationKey.TRACK_APP_LIFECYCLE_EVENTS.getConfigurationKey())) {
configurationBuilder.withTrackAppLifecycleEvents(pluginConfiguration
configurationBuilder.withTrackScreenViewEvents(pluginConfiguration
.getBoolean(ConfigurationKey.TRACK_APP_LIFECYCLE_EVENTS.getConfigurationKey()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public final class AWSClickstreamPluginConfiguration {
private final String endpoint;
private final long sendEventsInterval;
private final long callTimeOut;
private final boolean isTrackAppLifecycleEvents;
private final boolean isTrackScreenViewEvents;
private final boolean isTrackAppExceptionEvents;
private final boolean isCompressEvents;
private final long sessionTimeOut;

private AWSClickstreamPluginConfiguration(Builder builder) {
this.appId = builder.appId;
this.isTrackAppLifecycleEvents = builder.isTrackAppLifecycleEvents;
this.isTrackScreenViewEvents = builder.isTrackScreenViewEvents;
this.isTrackAppExceptionEvents = builder.isTrackAppExceptionEvents;
this.callTimeOut = builder.callTimeOut;
this.sendEventsInterval = builder.sendEventsInterval;
Expand Down Expand Up @@ -72,12 +72,12 @@ long getCallTimeOut() {
}

/**
* Is auto session tracking enabled.
* Is auto screen view tracking enabled.
*
* @return Is auto session tracking enabled.
* @return Is auto screen view tracking enabled.
*/
boolean isTrackAppLifecycleEvents() {
return isTrackAppLifecycleEvents;
boolean isTrackScreenViewEvents() {
return isTrackScreenViewEvents;
}

/**
Expand Down Expand Up @@ -135,7 +135,7 @@ static final class Builder {
private long sendEventsInterval = DEFAULT_SEND_EVENTS_INTERVAL;
private final long callTimeOut = DEFAULT_CALL_TIME_OUT;
private boolean isCompressEvents = true;
private boolean isTrackAppLifecycleEvents = true;
private boolean isTrackScreenViewEvents = true;
private boolean isTrackAppExceptionEvents = false;

private long sessionTimeOut = DEFAULT_SESSION_TIME_OUT;
Expand All @@ -160,8 +160,8 @@ Builder withCompressEvents(final boolean compressEvents) {
return this;
}

Builder withTrackAppLifecycleEvents(final boolean trackAppLifecycleEvents) {
this.isTrackAppLifecycleEvents = trackAppLifecycleEvents;
Builder withTrackScreenViewEvents(final boolean trackScreenViewEvents) {
this.isTrackScreenViewEvents = trackScreenViewEvents;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static ClickstreamManager create(Context context,
.withSendEventsInterval(clickstreamPluginConfiguration.getSendEventsInterval())
.withCallTimeOut(clickstreamPluginConfiguration.getCallTimeOut())
.withCompressEvents(clickstreamPluginConfiguration.isCompressEvents())
.withTrackAppLifecycleEvents(clickstreamPluginConfiguration.isTrackAppLifecycleEvents())
.withTrackScreenViewEvents(clickstreamPluginConfiguration.isTrackScreenViewEvents())
.withTrackAppExceptionEvents(clickstreamPluginConfiguration.isTrackAppExceptionEvents())
.withSessionTimeoutDuration(clickstreamPluginConfiguration.getSessionTimeOut());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public AutoRecordEventClient(@NonNull final ClickstreamContext clickstreamContex
* @param activity the activity to record.
*/
public void recordViewScreen(Activity activity) {
if (!clickstreamContext.getClickstreamConfiguration().isTrackScreenViewEvents()) {
return;
}
String screenId = activity.getClass().getCanonicalName();
String screenName = activity.getClass().getSimpleName();
long currentTimestamp = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ClickstreamConfiguration {
private long sendEventsInterval;
private long callTimeOut;
private boolean isCompressEvents;
private boolean isTrackAppLifecycleEvents;
private boolean isTrackScreenViewEvents;
private boolean isTrackAppExceptionEvents;
private boolean isLogEvents;
private String authCookie;
Expand Down Expand Up @@ -184,22 +184,22 @@ public ClickstreamConfiguration withCompressEvents(final boolean compressEvents)
}

/**
* Is track app lifecycle events.
* Is track app screen view events.
*
* @return Is track appLifecycle events.
*/
public boolean isTrackAppLifecycleEvents() {
return this.isTrackAppLifecycleEvents;
public boolean isTrackScreenViewEvents() {
return this.isTrackScreenViewEvents;
}

/**
* Is track app lifecycle events.
* Is track app screen view events.
*
* @param isTrackAppLifecycleEvents Is track app lifecycle events.
* @param isTrackScreenViewEvents Is track screen view events.
* @return the current ClickstreamConfiguration instance.
*/
public ClickstreamConfiguration withTrackAppLifecycleEvents(final boolean isTrackAppLifecycleEvents) {
this.isTrackAppLifecycleEvents = isTrackAppLifecycleEvents;
public ClickstreamConfiguration withTrackScreenViewEvents(final boolean isTrackScreenViewEvents) {
this.isTrackScreenViewEvents = isTrackScreenViewEvents;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setup() throws Exception {
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
configurationBuilder.withAppId("demo-app")
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
.withSendEventsInterval(10000);
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
ClickstreamManager clickstreamManager =
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void setup() {
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
configurationBuilder.withAppId("demo-app")
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
.withSendEventsInterval(10000).withTrackScreenViewEvents(true);
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
ClickstreamManager clickstreamManager =
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);
Expand Down Expand Up @@ -178,6 +178,32 @@ public void testViewOneScreenEvent() throws Exception {
}
}

/**
* test close screen view events in configuration.
*
* @throws Exception exception.
*/
@Test
public void testCloseScreenViewEventsRecord() throws Exception {
clickstreamContext.getClickstreamConfiguration().withTrackScreenViewEvents(false);
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START);
Activity activity = mock(Activity.class);
Bundle bundle = mock(Bundle.class);
callbacks.onActivityCreated(activity, bundle);
callbacks.onActivityStarted(activity);
callbacks.onActivityResumed(activity);
try (Cursor cursor = dbUtil.queryAllEvents()) {
List<String> eventList = new ArrayList<>();
while (cursor.moveToNext()) {
String eventString = cursor.getString(2);
JSONObject jsonObject = new JSONObject(eventString);
String eventName = jsonObject.getString("event_type");
eventList.add(eventName);
}
assertFalse(eventList.contains(Event.PresetEvent.SCREEN_VIEW));
}
}

/**
* test view two different screen and record last screen view event with
* previous screen information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void setup() throws Exception {
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
configurationBuilder.withAppId("demo-app")
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
.withSendEventsInterval(10000);
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
ClickstreamManager clickstreamManager =
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setup() throws Exception {
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
configurationBuilder.withAppId("demo-app")
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
.withSendEventsInterval(10000);
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
ClickstreamManager clickstreamManager =
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void init() {
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
configurationBuilder.withEndpoint(
"http://click-serve-HCJIDWGD3S9F-1166279006.ap-southeast-1.elb.amazonaws.com/collect")
.withSendEventsInterval(15000).withTrackAppLifecycleEvents(false);
.withSendEventsInterval(15000);
clickstreamPluginConfiguration = configurationBuilder.build();
}

Expand All @@ -67,7 +67,7 @@ public void initClientParam() {
"http://click-serve-HCJIDWGD3S9F-1166279006.ap-southeast-1.elb.amazonaws.com/collect");
Assert.assertEquals(clickstreamContext.getClickstreamConfiguration().getSendEventsInterval(), 15000);
Assert.assertTrue(clickstreamContext.getClickstreamConfiguration().isCompressEvents());
Assert.assertFalse(clickstreamContext.getClickstreamConfiguration().isTrackAppLifecycleEvents());
Assert.assertTrue(clickstreamContext.getClickstreamConfiguration().isTrackScreenViewEvents());
Assert.assertFalse(clickstreamContext.getClickstreamConfiguration().isTrackAppExceptionEvents());

Assert.assertEquals(clickstreamContext.getSDKInfo().getName(), "aws-solution-clickstream-sdk");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setup() {
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
configurationBuilder.withAppId("demo-app")
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
.withSendEventsInterval(10000);
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
ClickstreamManager clickstreamManager =
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);
Expand Down

0 comments on commit ece04bf

Please sign in to comment.