Skip to content

Commit

Permalink
feat: add preset attributes screen name and screen unique id (#38)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaoweii <[email protected]>
  • Loading branch information
zhu-xiaowei and xiaoweii authored Sep 12, 2023
1 parent 1b6eb58 commit 088f89b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ public JSONObject toJSONObject() {
}
}

String screenName = ScreenRefererTool.getCurrentScreenName();
String screenUniqueId = ScreenRefererTool.getCurrentScreenUniqueId();
if (screenName != null) {
try {
attributes.put(Event.ReservedAttribute.SCREEN_NAME, screenName);
attributes.put(Event.ReservedAttribute.SCREEN_UNIQUE_ID, screenUniqueId);
} catch (final JSONException jsonException) {
LOG.error("Error serializing session information " + jsonException.getMessage());
}
}

// ****************************************************
// ====SDK Details Attributes -- Prefix with 'sdk_'====
// ****************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ public void recordViewScreen(Activity activity) {
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW);
long currentTimestamp = event.getEventTimestamp();
startEngageTimestamp = currentTimestamp;
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
event.addAttribute(Event.ReservedAttribute.PREVIOUS_SCREEN_NAME, ScreenRefererTool.getPreviousScreenName());
event.addAttribute(Event.ReservedAttribute.PREVIOUS_SCREEN_ID, ScreenRefererTool.getPreviousScreenId());
event.addAttribute(Event.ReservedAttribute.PREVIOUS_SCREEN_UNIQUE_ID,
Expand Down Expand Up @@ -138,9 +136,6 @@ public void recordUserEngagement() {
final AnalyticsEvent event =
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.USER_ENGAGEMENT);
event.addAttribute(Event.ReservedAttribute.ENGAGEMENT_TIMESTAMP, lastEngageTime);
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
}
}
Expand Down Expand Up @@ -222,9 +217,6 @@ public void handleAppStart() {
final AnalyticsEvent event =
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.APP_START);
event.addAttribute(Event.ReservedAttribute.IS_FIRST_TIME, isFirstTime);
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
isFirstTime = false;
}
Expand All @@ -235,9 +227,6 @@ public void handleAppStart() {
public void handleAppEnd() {
final AnalyticsEvent event =
this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.APP_END);
event.addAttribute(Event.ReservedAttribute.SCREEN_NAME, ScreenRefererTool.getCurrentScreenName());
event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId());
event.addAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID, ScreenRefererTool.getCurrentScreenUniqueId());
this.clickstreamContext.getAnalyticsClient().recordEvent(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ public void testHandleAppStart() throws Exception {
JSONObject appStart2 = eventList.get(3).getJSONObject("attributes");
assertFalse(appStart2.getBoolean(Event.ReservedAttribute.IS_FIRST_TIME));
assertTrue(appStart2.has(ReservedAttribute.SCREEN_NAME));
assertTrue(appStart2.has(Event.ReservedAttribute.SCREEN_ID));
assertTrue(appStart2.has(ReservedAttribute.SCREEN_UNIQUE_ID));
assertEquals(activity1.getClass().getSimpleName(), appStart2.getString(ReservedAttribute.SCREEN_NAME));
assertEquals(activity1.getClass().getCanonicalName(), appStart2.getString(ReservedAttribute.SCREEN_ID));
assertEquals(String.valueOf(activity1.hashCode()), appStart2.getString(ReservedAttribute.SCREEN_UNIQUE_ID));
}
}

Expand All @@ -664,7 +664,6 @@ public void testAppEnd() throws Exception {
JSONObject attributes = jsonObject.getJSONObject("attributes");
assertEquals(Event.PresetEvent.APP_END, eventType);
assertTrue(attributes.has(ReservedAttribute.SCREEN_NAME));
assertTrue(attributes.has(ReservedAttribute.SCREEN_ID));
assertTrue(attributes.has(ReservedAttribute.SCREEN_UNIQUE_ID));
}
}
Expand Down

0 comments on commit 088f89b

Please sign in to comment.