Skip to content

Commit

Permalink
fix: change the screen unique id generation method (#36)
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 9, 2023
1 parent ae5df3c commit 4bf567b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ public void recordViewScreen(Activity activity) {

/**
* get the screen unique id for activity.
* the unique id calculated by appending the last 8 characters of the device id with "_" and the activity hash code.
* the unique id calculated by getting the activity hash code.
*
* @param activity the activity for holding the screen
* @return the unique of the activity
*/
public String getScreenUniqueId(Activity activity) {
String clipDeviceId = StringUtil.trimOrPadString(clickstreamContext.getDeviceId(), DEVICE_ID_CLIP_LENGTH, '_');
return clipDeviceId + "_" + activity.hashCode();
return String.valueOf(activity.hashCode());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ public void testViewOneScreenEvent() throws Exception {
}
}

/**
* test screen view event with screen unique id.
*
* @throws Exception exception.
*/
@Test
public void testScreenViewWithUniqueId() throws Exception {
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()) {
cursor.moveToLast();
String eventString = cursor.getString(2);
JSONObject jsonObject = new JSONObject(eventString);
String eventName = jsonObject.getString("event_type");
assertEquals(eventName, Event.PresetEvent.SCREEN_VIEW);
JSONObject attributes = jsonObject.getJSONObject("attributes");
String screenUniqueId = attributes.getString(ReservedAttribute.SCREEN_UNIQUE_ID);
assertNotNull(screenUniqueId);
assertEquals(screenUniqueId, String.valueOf(activity.hashCode()));
}
}

/**
* test close screen view events in configuration.
*
Expand Down

0 comments on commit 4bf567b

Please sign in to comment.