Skip to content

Commit 4450088

Browse files
zhu-xiaoweixiaoweii
andcommitted
feat: support closing screen view event recording (#26)
Co-authored-by: xiaoweii <xiaoweii@amazom.com>
1 parent cb541e6 commit 4450088

File tree

12 files changed

+56
-26
lines changed

12 files changed

+56
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ ClickstreamAnalytics.getClickStreamConfiguration()
9191
.withAuthCookie("your authentication cookie")
9292
.withSendEventsInterval(10000)
9393
.withSessionTimeoutDuration(1800000)
94+
.withTrackScreenViewEvents(false)
9495
.withTrackAppExceptionEvents(false)
9596
.withLogEvents(true)
9697
.withCustomDns(CustomOkhttpDns.getInstance())

clickstream/src/main/java/software/aws/solution/clickstream/AWSClickstreamPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void configure(
168168
}
169169

170170
if (pluginConfiguration.has(ConfigurationKey.TRACK_APP_LIFECYCLE_EVENTS.getConfigurationKey())) {
171-
configurationBuilder.withTrackAppLifecycleEvents(pluginConfiguration
171+
configurationBuilder.withTrackScreenViewEvents(pluginConfiguration
172172
.getBoolean(ConfigurationKey.TRACK_APP_LIFECYCLE_EVENTS.getConfigurationKey()));
173173
}
174174

clickstream/src/main/java/software/aws/solution/clickstream/AWSClickstreamPluginConfiguration.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public final class AWSClickstreamPluginConfiguration {
2828
private final String endpoint;
2929
private final long sendEventsInterval;
3030
private final long callTimeOut;
31-
private final boolean isTrackAppLifecycleEvents;
31+
private final boolean isTrackScreenViewEvents;
3232
private final boolean isTrackAppExceptionEvents;
3333
private final boolean isCompressEvents;
3434
private final long sessionTimeOut;
3535

3636
private AWSClickstreamPluginConfiguration(Builder builder) {
3737
this.appId = builder.appId;
38-
this.isTrackAppLifecycleEvents = builder.isTrackAppLifecycleEvents;
38+
this.isTrackScreenViewEvents = builder.isTrackScreenViewEvents;
3939
this.isTrackAppExceptionEvents = builder.isTrackAppExceptionEvents;
4040
this.callTimeOut = builder.callTimeOut;
4141
this.sendEventsInterval = builder.sendEventsInterval;
@@ -72,12 +72,12 @@ long getCallTimeOut() {
7272
}
7373

7474
/**
75-
* Is auto session tracking enabled.
75+
* Is auto screen view tracking enabled.
7676
*
77-
* @return Is auto session tracking enabled.
77+
* @return Is auto screen view tracking enabled.
7878
*/
79-
boolean isTrackAppLifecycleEvents() {
80-
return isTrackAppLifecycleEvents;
79+
boolean isTrackScreenViewEvents() {
80+
return isTrackScreenViewEvents;
8181
}
8282

8383
/**
@@ -135,7 +135,7 @@ static final class Builder {
135135
private long sendEventsInterval = DEFAULT_SEND_EVENTS_INTERVAL;
136136
private final long callTimeOut = DEFAULT_CALL_TIME_OUT;
137137
private boolean isCompressEvents = true;
138-
private boolean isTrackAppLifecycleEvents = true;
138+
private boolean isTrackScreenViewEvents = true;
139139
private boolean isTrackAppExceptionEvents = false;
140140

141141
private long sessionTimeOut = DEFAULT_SESSION_TIME_OUT;
@@ -160,8 +160,8 @@ Builder withCompressEvents(final boolean compressEvents) {
160160
return this;
161161
}
162162

163-
Builder withTrackAppLifecycleEvents(final boolean trackAppLifecycleEvents) {
164-
this.isTrackAppLifecycleEvents = trackAppLifecycleEvents;
163+
Builder withTrackScreenViewEvents(final boolean trackScreenViewEvents) {
164+
this.isTrackScreenViewEvents = trackScreenViewEvents;
165165
return this;
166166
}
167167

clickstream/src/main/java/software/aws/solution/clickstream/ClickstreamManagerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static ClickstreamManager create(Context context,
3636
.withSendEventsInterval(clickstreamPluginConfiguration.getSendEventsInterval())
3737
.withCallTimeOut(clickstreamPluginConfiguration.getCallTimeOut())
3838
.withCompressEvents(clickstreamPluginConfiguration.isCompressEvents())
39-
.withTrackAppLifecycleEvents(clickstreamPluginConfiguration.isTrackAppLifecycleEvents())
39+
.withTrackScreenViewEvents(clickstreamPluginConfiguration.isTrackScreenViewEvents())
4040
.withTrackAppExceptionEvents(clickstreamPluginConfiguration.isTrackAppExceptionEvents())
4141
.withSessionTimeoutDuration(clickstreamPluginConfiguration.getSessionTimeOut());
4242

clickstream/src/main/java/software/aws/solution/clickstream/client/AutoRecordEventClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public AutoRecordEventClient(@NonNull final ClickstreamContext clickstreamContex
7474
* @param activity the activity to record.
7575
*/
7676
public void recordViewScreen(Activity activity) {
77+
if (!clickstreamContext.getClickstreamConfiguration().isTrackScreenViewEvents()) {
78+
return;
79+
}
7780
String screenId = activity.getClass().getCanonicalName();
7881
String screenName = activity.getClass().getSimpleName();
7982
long currentTimestamp = System.currentTimeMillis();

clickstream/src/main/java/software/aws/solution/clickstream/client/ClickstreamConfiguration.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ClickstreamConfiguration {
3131
private long sendEventsInterval;
3232
private long callTimeOut;
3333
private boolean isCompressEvents;
34-
private boolean isTrackAppLifecycleEvents;
34+
private boolean isTrackScreenViewEvents;
3535
private boolean isTrackAppExceptionEvents;
3636
private boolean isLogEvents;
3737
private String authCookie;
@@ -184,22 +184,22 @@ public ClickstreamConfiguration withCompressEvents(final boolean compressEvents)
184184
}
185185

186186
/**
187-
* Is track app lifecycle events.
187+
* Is track app screen view events.
188188
*
189189
* @return Is track appLifecycle events.
190190
*/
191-
public boolean isTrackAppLifecycleEvents() {
192-
return this.isTrackAppLifecycleEvents;
191+
public boolean isTrackScreenViewEvents() {
192+
return this.isTrackScreenViewEvents;
193193
}
194194

195195
/**
196-
* Is track app lifecycle events.
196+
* Is track app screen view events.
197197
*
198-
* @param isTrackAppLifecycleEvents Is track app lifecycle events.
198+
* @param isTrackScreenViewEvents Is track screen view events.
199199
* @return the current ClickstreamConfiguration instance.
200200
*/
201-
public ClickstreamConfiguration withTrackAppLifecycleEvents(final boolean isTrackAppLifecycleEvents) {
202-
this.isTrackAppLifecycleEvents = isTrackAppLifecycleEvents;
201+
public ClickstreamConfiguration withTrackScreenViewEvents(final boolean isTrackScreenViewEvents) {
202+
this.isTrackScreenViewEvents = isTrackScreenViewEvents;
203203
return this;
204204
}
205205

clickstream/src/test/java/software/aws/solution/clickstream/AnalyticsClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void setup() throws Exception {
5757
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
5858
configurationBuilder.withAppId("demo-app")
5959
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
60-
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
60+
.withSendEventsInterval(10000);
6161
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
6262
ClickstreamManager clickstreamManager =
6363
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);

clickstream/src/test/java/software/aws/solution/clickstream/AutoRecordEventClientTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void setup() {
7979
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
8080
configurationBuilder.withAppId("demo-app")
8181
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
82-
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
82+
.withSendEventsInterval(10000).withTrackScreenViewEvents(true);
8383
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
8484
ClickstreamManager clickstreamManager =
8585
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);
@@ -178,6 +178,32 @@ public void testViewOneScreenEvent() throws Exception {
178178
}
179179
}
180180

181+
/**
182+
* test close screen view events in configuration.
183+
*
184+
* @throws Exception exception.
185+
*/
186+
@Test
187+
public void testCloseScreenViewEventsRecord() throws Exception {
188+
clickstreamContext.getClickstreamConfiguration().withTrackScreenViewEvents(false);
189+
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START);
190+
Activity activity = mock(Activity.class);
191+
Bundle bundle = mock(Bundle.class);
192+
callbacks.onActivityCreated(activity, bundle);
193+
callbacks.onActivityStarted(activity);
194+
callbacks.onActivityResumed(activity);
195+
try (Cursor cursor = dbUtil.queryAllEvents()) {
196+
List<String> eventList = new ArrayList<>();
197+
while (cursor.moveToNext()) {
198+
String eventString = cursor.getString(2);
199+
JSONObject jsonObject = new JSONObject(eventString);
200+
String eventName = jsonObject.getString("event_type");
201+
eventList.add(eventName);
202+
}
203+
assertFalse(eventList.contains(Event.PresetEvent.SCREEN_VIEW));
204+
}
205+
}
206+
181207
/**
182208
* test view two different screen and record last screen view event with
183209
* previous screen information.

clickstream/src/test/java/software/aws/solution/clickstream/EventRecorderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void setup() throws Exception {
111111
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
112112
configurationBuilder.withAppId("demo-app")
113113
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
114-
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
114+
.withSendEventsInterval(10000);
115115
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
116116
ClickstreamManager clickstreamManager =
117117
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);

clickstream/src/test/java/software/aws/solution/clickstream/ExceptionHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void setup() throws Exception {
5757
AWSClickstreamPluginConfiguration.Builder configurationBuilder = AWSClickstreamPluginConfiguration.builder();
5858
configurationBuilder.withAppId("demo-app")
5959
.withEndpoint("http://cs-se-serve-1qtj719j88vwn-1291141553.ap-southeast-1.elb.amazonaws.com/collect")
60-
.withSendEventsInterval(10000).withTrackAppLifecycleEvents(false);
60+
.withSendEventsInterval(10000);
6161
AWSClickstreamPluginConfiguration clickstreamPluginConfiguration = configurationBuilder.build();
6262
ClickstreamManager clickstreamManager =
6363
ClickstreamManagerFactory.create(context, clickstreamPluginConfiguration);

0 commit comments

Comments
 (0)