Skip to content

Commit 088f89b

Browse files
zhu-xiaoweixiaoweii
andauthored
feat: add preset attributes screen name and screen unique id (#38)
Co-authored-by: xiaoweii <xiaoweii@amazom.com>
1 parent 1b6eb58 commit 088f89b

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ public JSONObject toJSONObject() {
482482
}
483483
}
484484

485+
String screenName = ScreenRefererTool.getCurrentScreenName();
486+
String screenUniqueId = ScreenRefererTool.getCurrentScreenUniqueId();
487+
if (screenName != null) {
488+
try {
489+
attributes.put(Event.ReservedAttribute.SCREEN_NAME, screenName);
490+
attributes.put(Event.ReservedAttribute.SCREEN_UNIQUE_ID, screenUniqueId);
491+
} catch (final JSONException jsonException) {
492+
LOG.error("Error serializing session information " + jsonException.getMessage());
493+
}
494+
}
495+
485496
// ****************************************************
486497
// ====SDK Details Attributes -- Prefix with 'sdk_'====
487498
// ****************************************************

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ public void recordViewScreen(Activity activity) {
9797
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW);
9898
long currentTimestamp = event.getEventTimestamp();
9999
startEngageTimestamp = currentTimestamp;
100-
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
101100
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
102-
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
103101
event.addAttribute(Event.ReservedAttribute.PREVIOUS_SCREEN_NAME, ScreenRefererTool.getPreviousScreenName());
104102
event.addAttribute(Event.ReservedAttribute.PREVIOUS_SCREEN_ID, ScreenRefererTool.getPreviousScreenId());
105103
event.addAttribute(Event.ReservedAttribute.PREVIOUS_SCREEN_UNIQUE_ID,
@@ -138,9 +136,6 @@ public void recordUserEngagement() {
138136
final AnalyticsEvent event =
139137
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.USER_ENGAGEMENT);
140138
event.addAttribute(Event.ReservedAttribute.ENGAGEMENT_TIMESTAMP, lastEngageTime);
141-
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
142-
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
143-
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
144139
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
145140
}
146141
}
@@ -222,9 +217,6 @@ public void handleAppStart() {
222217
final AnalyticsEvent event =
223218
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.APP_START);
224219
event.addAttribute(Event.ReservedAttribute.IS_FIRST_TIME, isFirstTime);
225-
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
226-
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
227-
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
228220
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
229221
isFirstTime = false;
230222
}
@@ -235,9 +227,6 @@ public void handleAppStart() {
235227
public void handleAppEnd() {
236228
final AnalyticsEvent event =
237229
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.APP_END);
238-
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
239-
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
240-
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
241230
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
242231
}
243232

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,9 @@ public void testHandleAppStart() throws Exception {
637637
JSONObject appStart2 = eventList.get(3).getJSONObject("attributes");
638638
assertFalse(appStart2.getBoolean(Event.ReservedAttribute.IS_FIRST_TIME));
639639
assertTrue(appStart2.has(ReservedAttribute.SCREEN_NAME));
640-
assertTrue(appStart2.has(Event.ReservedAttribute.SCREEN_ID));
640+
assertTrue(appStart2.has(ReservedAttribute.SCREEN_UNIQUE_ID));
641641
assertEquals(activity1.getClass().getSimpleName(), appStart2.getString(ReservedAttribute.SCREEN_NAME));
642-
assertEquals(activity1.getClass().getCanonicalName(), appStart2.getString(ReservedAttribute.SCREEN_ID));
642+
assertEquals(String.valueOf(activity1.hashCode()), appStart2.getString(ReservedAttribute.SCREEN_UNIQUE_ID));
643643
}
644644
}
645645

@@ -664,7 +664,6 @@ public void testAppEnd() throws Exception {
664664
JSONObject attributes = jsonObject.getJSONObject("attributes");
665665
assertEquals(Event.PresetEvent.APP_END, eventType);
666666
assertTrue(attributes.has(ReservedAttribute.SCREEN_NAME));
667-
assertTrue(attributes.has(ReservedAttribute.SCREEN_ID));
668667
assertTrue(attributes.has(ReservedAttribute.SCREEN_UNIQUE_ID));
669668
}
670669
}

0 commit comments

Comments
 (0)