Skip to content

Commit 4bf567b

Browse files
zhu-xiaoweixiaoweii
andauthored
fix: change the screen unique id generation method (#36)
Co-authored-by: xiaoweii <[email protected]>
1 parent ae5df3c commit 4bf567b

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,13 @@ public void recordViewScreen(Activity activity) {
119119

120120
/**
121121
* get the screen unique id for activity.
122-
* the unique id calculated by appending the last 8 characters of the device id with "_" and the activity hash code.
122+
* the unique id calculated by getting the activity hash code.
123123
*
124124
* @param activity the activity for holding the screen
125125
* @return the unique of the activity
126126
*/
127127
public String getScreenUniqueId(Activity activity) {
128-
String clipDeviceId = StringUtil.trimOrPadString(clickstreamContext.getDeviceId(), DEVICE_ID_CLIP_LENGTH, '_');
129-
return clipDeviceId + "_" + activity.hashCode();
128+
return String.valueOf(activity.hashCode());
130129
}
131130

132131
/**

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,31 @@ public void testViewOneScreenEvent() throws Exception {
206206
}
207207
}
208208

209+
/**
210+
* test screen view event with screen unique id.
211+
*
212+
* @throws Exception exception.
213+
*/
214+
@Test
215+
public void testScreenViewWithUniqueId() throws Exception {
216+
Activity activity = mock(Activity.class);
217+
Bundle bundle = mock(Bundle.class);
218+
callbacks.onActivityCreated(activity, bundle);
219+
callbacks.onActivityStarted(activity);
220+
callbacks.onActivityResumed(activity);
221+
try (Cursor cursor = dbUtil.queryAllEvents()) {
222+
cursor.moveToLast();
223+
String eventString = cursor.getString(2);
224+
JSONObject jsonObject = new JSONObject(eventString);
225+
String eventName = jsonObject.getString("event_type");
226+
assertEquals(eventName, Event.PresetEvent.SCREEN_VIEW);
227+
JSONObject attributes = jsonObject.getJSONObject("attributes");
228+
String screenUniqueId = attributes.getString(ReservedAttribute.SCREEN_UNIQUE_ID);
229+
assertNotNull(screenUniqueId);
230+
assertEquals(screenUniqueId, String.valueOf(activity.hashCode()));
231+
}
232+
}
233+
209234
/**
210235
* test close screen view events in configuration.
211236
*

0 commit comments

Comments
 (0)