From 29101ad49548e137bb6c348e0ceb9e23d55b6cf7 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Tue, 6 Feb 2024 15:16:45 +0800 Subject: [PATCH 1/4] feat: support record screen view event manually --- README.md | 21 ++ .../clickstream/AWSClickstreamPlugin.java | 12 +- .../clickstream/ActivityLifecycleManager.java | 11 +- .../clickstream/ClickstreamAnalytics.java | 32 ++- .../client/AutoRecordEventClient.java | 37 +++- .../solution/clickstream/client/Event.java | 5 + .../ActivityLifecycleManagerUnitTest.java | 2 +- .../AutoRecordEventClientTest.java | 187 ++++++++++++++++++ .../solution/clickstream/IntegrationTest.java | 30 +++ 9 files changed, 328 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4e94c27..685f68e 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,27 @@ ClickstreamEvent event = ClickstreamEvent.builder() ClickstreamAnalytics.recordEvent(event); ``` +#### Record Screen View events manually + +By default, SDK will automatically track the preset `_screen_view` event when Activity triggers `onResume`. + +You can also manually record screen view event whether or not automatic screen view tracking is enabled, add the following code to record a Screen View event with two attributes. + +* `SCREEN_NAME` Required. Your screen's name. +* `SCREEN_UNIQUE_ID` Optional. set the hashcode of your Activity, Fragment or View. And if you do not set, SDK will sets a default value based on the current Activity's hashcode. + +```java +import software.aws.solution.clickstream.ClickstreamAnalytcs; + +ClickstreamEvent event = ClickstreamEvent.builder() + .name(ClickstreamAnalytics.Event.SCREEN_VIEW) + .add(ClickstreamAnalytics.Attr.SCREEN_NAME, "HomeFragment") + .add(ClickstreamAnalytics.Attr.SCREEN_UNIQUE_ID, String.valueOf(HomeFragment.hashCode())) + .build(); + +ClickstreamAnalytics.recordEvent(event); +``` + #### Log the event json in debug mode ```java diff --git a/clickstream/src/main/java/software/aws/solution/clickstream/AWSClickstreamPlugin.java b/clickstream/src/main/java/software/aws/solution/clickstream/AWSClickstreamPlugin.java index 8328dd2..072eaab 100644 --- a/clickstream/src/main/java/software/aws/solution/clickstream/AWSClickstreamPlugin.java +++ b/clickstream/src/main/java/software/aws/solution/clickstream/AWSClickstreamPlugin.java @@ -103,7 +103,7 @@ public synchronized void enable() { public void recordEvent(@NonNull String eventName) { final AnalyticsEvent event = analyticsClient.createEvent(eventName); if (event != null) { - analyticsClient.recordEvent(event); + recordAnalyticsEvent(event); } } @@ -121,7 +121,15 @@ public void recordEvent(@NonNull AnalyticsEventBehavior analyticsEvent) { } } clickstreamEvent.addItems(event.getItems()); - analyticsClient.recordEvent(clickstreamEvent); + recordAnalyticsEvent(clickstreamEvent); + } + } + + private void recordAnalyticsEvent(AnalyticsEvent event) { + if (event.getEventType().equals(Event.PresetEvent.SCREEN_VIEW)) { + activityLifecycleManager.onScreenViewManually(event); + } else { + analyticsClient.recordEvent(event); } } diff --git a/clickstream/src/main/java/software/aws/solution/clickstream/ActivityLifecycleManager.java b/clickstream/src/main/java/software/aws/solution/clickstream/ActivityLifecycleManager.java index 7097ee5..46cff59 100644 --- a/clickstream/src/main/java/software/aws/solution/clickstream/ActivityLifecycleManager.java +++ b/clickstream/src/main/java/software/aws/solution/clickstream/ActivityLifecycleManager.java @@ -26,6 +26,7 @@ import com.amazonaws.logging.Log; import com.amazonaws.logging.LogFactory; +import software.aws.solution.clickstream.client.AnalyticsEvent; import software.aws.solution.clickstream.client.AutoRecordEventClient; import software.aws.solution.clickstream.client.ClickstreamManager; import software.aws.solution.clickstream.client.ScreenRefererTool; @@ -92,10 +93,18 @@ public void onActivityResumed(final Activity activity) { autoRecordEventClient.resetLastEngageTime(); } } - autoRecordEventClient.recordViewScreen(activity); + autoRecordEventClient.recordViewScreenAutomatically(activity); isFromForeground = false; } + /** + * Handle Screen View triggered manually. + * @param event the screen view event + */ + public void onScreenViewManually(AnalyticsEvent event) { + autoRecordEventClient.recordViewScreenManually(event); + } + @Override public void onActivityPaused(final Activity activity) { // onPause is always followed by onStop except when the app is interrupted by an event such diff --git a/clickstream/src/main/java/software/aws/solution/clickstream/ClickstreamAnalytics.java b/clickstream/src/main/java/software/aws/solution/clickstream/ClickstreamAnalytics.java index e43de5f..edef764 100644 --- a/clickstream/src/main/java/software/aws/solution/clickstream/ClickstreamAnalytics.java +++ b/clickstream/src/main/java/software/aws/solution/clickstream/ClickstreamAnalytics.java @@ -25,7 +25,8 @@ import com.amazonaws.logging.LogFactory; import software.aws.solution.clickstream.client.AnalyticsClient; import software.aws.solution.clickstream.client.ClickstreamConfiguration; -import software.aws.solution.clickstream.client.Event; +import software.aws.solution.clickstream.client.Event.PresetEvent; +import software.aws.solution.clickstream.client.Event.ReservedAttribute; import software.aws.solution.clickstream.client.util.ThreadUtil; /** @@ -101,7 +102,7 @@ public static void deleteGlobalAttributes(@NonNull String... attributeName) { * @param userProfile user */ public static void addUserAttributes(ClickstreamUserAttribute userProfile) { - Amplify.Analytics.identifyUser(Event.ReservedAttribute.USER_ID_UNSET, userProfile); + Amplify.Analytics.identifyUser(ReservedAttribute.USER_ID_UNSET, userProfile); } /** @@ -213,4 +214,31 @@ public static class Item { */ public static final String ITEM_CATEGORY5 = "item_category5"; } + + /** + * Preset Event. + */ + public static class Event { + + /** + * screen view. + */ + public static final String SCREEN_VIEW = PresetEvent.SCREEN_VIEW; + } + + /** + * Preset Attributes. + */ + public static class Attr { + + /** + * screen name. + */ + public static final String SCREEN_NAME = ReservedAttribute.SCREEN_NAME; + + /** + * screen unique id. + */ + public static final String SCREEN_UNIQUE_ID = ReservedAttribute.SCREEN_UNIQUE_ID; + } } diff --git a/clickstream/src/main/java/software/aws/solution/clickstream/client/AutoRecordEventClient.java b/clickstream/src/main/java/software/aws/solution/clickstream/client/AutoRecordEventClient.java index b199f51..1d9a3e5 100644 --- a/clickstream/src/main/java/software/aws/solution/clickstream/client/AutoRecordEventClient.java +++ b/clickstream/src/main/java/software/aws/solution/clickstream/client/AutoRecordEventClient.java @@ -78,7 +78,7 @@ public AutoRecordEventClient(@NonNull final ClickstreamContext clickstreamContex * * @param activity the activity to record. */ - public void recordViewScreen(Activity activity) { + public void recordViewScreenAutomatically(Activity activity) { if (!clickstreamContext.getClickstreamConfiguration().isTrackScreenViewEvents()) { return; } @@ -93,6 +93,39 @@ public void recordViewScreen(Activity activity) { ScreenRefererTool.setCurrentScreenUniqueId(screenUniqueId); final AnalyticsEvent event = this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW); + recordScreenViewEvent(event); + } + + /** + * record view screen event manually. + * + * @param event the screen view event to be recorded. + */ + public void recordViewScreenManually(AnalyticsEvent event) { + String screenName = event.getStringAttribute(Event.ReservedAttribute.SCREEN_NAME); + if (screenName != null) { + if (ScreenRefererTool.getCurrentScreenName() != null) { + recordUserEngagement(); + } + ScreenRefererTool.setCurrentScreenName(screenName); + String screenUniqueId = event.getStringAttribute(Event.ReservedAttribute.SCREEN_UNIQUE_ID); + if (screenUniqueId != null) { + ScreenRefererTool.setCurrentScreenUniqueId(screenUniqueId); + } + recordScreenViewEvent(event); + } else { + LOG.error("record an _screen_view event without the required screen name attribute"); + final AnalyticsEvent errorEvent = + this.clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.CLICKSTREAM_ERROR); + errorEvent.addAttribute(Event.ReservedAttribute.ERROR_CODE, + Event.ErrorCode.SCREEN_VIEW_MISSING_SCREEN_NAME); + errorEvent.addAttribute(Event.ReservedAttribute.ERROR_MESSAGE, + "record an _screen_view event without the required screen name attribute"); + this.clickstreamContext.getAnalyticsClient().recordEvent(errorEvent); + } + } + + private void recordScreenViewEvent(AnalyticsEvent event) { long currentTimestamp = event.getEventTimestamp(); startEngageTimestamp = currentTimestamp; event.addAttribute(Event.ReservedAttribute.SCREEN_ID, ScreenRefererTool.getCurrentScreenId()); @@ -111,8 +144,6 @@ public void recordViewScreen(Activity activity) { this.clickstreamContext.getAnalyticsClient().recordEvent(event); PreferencesUtil.savePreviousScreenViewTimestamp(preferences, currentTimestamp); isEntrances = false; - LOG.debug("record an _screen_view event, screenId:" + screenId + "lastScreenId:" + - ScreenRefererTool.getPreviousScreenId()); } /** diff --git a/clickstream/src/main/java/software/aws/solution/clickstream/client/Event.java b/clickstream/src/main/java/software/aws/solution/clickstream/client/Event.java index afac4eb..73e9092 100644 --- a/clickstream/src/main/java/software/aws/solution/clickstream/client/Event.java +++ b/clickstream/src/main/java/software/aws/solution/clickstream/client/Event.java @@ -144,6 +144,11 @@ public static final class ErrorCode { */ public static final int ITEM_CUSTOM_ATTRIBUTE_KEY_INVALID = 4005; + /** + * screen view event missing screen name attribute. + */ + public static final int SCREEN_VIEW_MISSING_SCREEN_NAME = 5001; + private ErrorCode() { } } diff --git a/clickstream/src/test/java/software/aws/solution/clickstream/ActivityLifecycleManagerUnitTest.java b/clickstream/src/test/java/software/aws/solution/clickstream/ActivityLifecycleManagerUnitTest.java index 9cf15ee..52af248 100644 --- a/clickstream/src/test/java/software/aws/solution/clickstream/ActivityLifecycleManagerUnitTest.java +++ b/clickstream/src/test/java/software/aws/solution/clickstream/ActivityLifecycleManagerUnitTest.java @@ -150,6 +150,6 @@ public void testScreenView() { callbacks.onActivityCreated(activity, bundle); callbacks.onActivityStarted(activity); callbacks.onActivityResumed(activity); - verify(autoRecordEventClient).recordViewScreen(activity); + verify(autoRecordEventClient).recordViewScreenAutomatically(activity); } } diff --git a/clickstream/src/test/java/software/aws/solution/clickstream/AutoRecordEventClientTest.java b/clickstream/src/test/java/software/aws/solution/clickstream/AutoRecordEventClientTest.java index 27471f5..8bb8421 100644 --- a/clickstream/src/test/java/software/aws/solution/clickstream/AutoRecordEventClientTest.java +++ b/clickstream/src/test/java/software/aws/solution/clickstream/AutoRecordEventClientTest.java @@ -21,6 +21,7 @@ import android.database.Cursor; import android.os.Build; import android.os.Bundle; +import androidx.fragment.app.Fragment; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleRegistry; @@ -35,6 +36,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; +import software.aws.solution.clickstream.client.AnalyticsEvent; import software.aws.solution.clickstream.client.AutoRecordEventClient; import software.aws.solution.clickstream.client.ClickstreamContext; import software.aws.solution.clickstream.client.ClickstreamManager; @@ -487,6 +489,185 @@ public void testAppWarmStartWithoutEngagementTime() throws Exception { } } + /** + * test record screen view event manually without screen name. + * + * @throws Exception exception + */ + @Test + public void testRecordScreenViewManuallyWithoutScreenName() throws Exception { + final AnalyticsEvent event = clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW); + client.recordViewScreenManually(event); + try (Cursor cursor = dbUtil.queryAllEvents()) { + cursor.moveToLast(); + String eventString = cursor.getString(2); + JSONObject jsonObject = new JSONObject(eventString); + String eventName = jsonObject.getString("event_type"); + assertEquals(Event.PresetEvent.CLICKSTREAM_ERROR, eventName); + JSONObject attributes = jsonObject.getJSONObject("attributes"); + Assert.assertEquals(Event.ErrorCode.SCREEN_VIEW_MISSING_SCREEN_NAME, + attributes.getInt(ReservedAttribute.ERROR_CODE)); + } + } + + /** + * test record screen view event manually without screen unique id and + * will add the current Activity's screen unique id. + * + * @throws Exception exception + */ + @Test + public void testRecordScreenViewManuallyWithoutScreenUniqueId() throws Exception { + lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START); + Activity activityA = mock(ActivityA.class); + Fragment fragmentA = mock(FragmentA.class); + Bundle bundle = mock(Bundle.class); + callbacks.onActivityCreated(activityA, bundle); + callbacks.onActivityStarted(activityA); + callbacks.onActivityResumed(activityA); + final AnalyticsEvent event = clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW); + event.addAttribute(ClickstreamAnalytics.Attr.SCREEN_NAME, fragmentA.getClass().getSimpleName()); + client.recordViewScreenManually(event); + try (Cursor cursor = dbUtil.queryAllEvents()) { + cursor.moveToLast(); + String eventString = cursor.getString(2); + JSONObject jsonObject = new JSONObject(eventString); + String eventName = jsonObject.getString("event_type"); + assertEquals(Event.PresetEvent.SCREEN_VIEW, eventName); + JSONObject attributes = jsonObject.getJSONObject("attributes"); + Assert.assertEquals(fragmentA.getClass().getSimpleName(), + attributes.getString(ReservedAttribute.SCREEN_NAME)); + Assert.assertEquals(String.valueOf(activityA.hashCode()), + attributes.getString(ReservedAttribute.SCREEN_UNIQUE_ID)); + } + } + + + /** + * test record screen view event manually between two activity screen view. + * + * @throws Exception exception + */ + @Test + public void testRecordCustomScreenViewBetweenActivityResume() throws Exception { + lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START); + Activity activityA = mock(ActivityA.class); + Activity activityB = mock(ActivityB.class); + Bundle bundle = mock(Bundle.class); + // Record activityA screen view + callbacks.onActivityCreated(activityA, bundle); + callbacks.onActivityStarted(activityA); + callbacks.onActivityResumed(activityA); + + // Record custom Fragment screen view + Fragment fragmentA = mock(FragmentA.class); + String uniqueIDOfFragmentA = String.valueOf(fragmentA.hashCode()); + final AnalyticsEvent event = clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW); + event.addAttribute(ClickstreamAnalytics.Attr.SCREEN_NAME, fragmentA.getClass().getSimpleName()); + event.addAttribute(ClickstreamAnalytics.Attr.SCREEN_UNIQUE_ID, uniqueIDOfFragmentA); + client.recordViewScreenManually(event); + + // Record ActivityB Screen View + callbacks.onActivityPaused(activityA); + callbacks.onActivityCreated(activityB, bundle); + callbacks.onActivityStarted(activityB); + callbacks.onActivityResumed(activityB); + try (Cursor cursor = dbUtil.queryAllEvents()) { + cursor.moveToLast(); + // assert that ActivityB's screen view event previews screen is FragmentA + String eventString = cursor.getString(2); + JSONObject jsonObject = new JSONObject(eventString); + String eventName = jsonObject.getString("event_type"); + assertEquals(Event.PresetEvent.SCREEN_VIEW, eventName); + JSONObject attributes = jsonObject.getJSONObject("attributes"); + Assert.assertEquals(activityB.getClass().getSimpleName(), + attributes.getString(ReservedAttribute.SCREEN_NAME)); + Assert.assertEquals(fragmentA.getClass().getSimpleName(), + attributes.getString(ReservedAttribute.PREVIOUS_SCREEN_NAME)); + Assert.assertEquals(uniqueIDOfFragmentA, + attributes.getString(ReservedAttribute.PREVIOUS_SCREEN_UNIQUE_ID)); + + // assert that FragmentA's attribute contains ActivityA's screen attributes + cursor.moveToPrevious(); + String eventString2 = cursor.getString(2); + JSONObject jsonObject2 = new JSONObject(eventString2); + String eventName2 = jsonObject2.getString("event_type"); + assertEquals(Event.PresetEvent.SCREEN_VIEW, eventName2); + JSONObject attributes2 = jsonObject2.getJSONObject("attributes"); + Assert.assertEquals(fragmentA.getClass().getSimpleName(), + attributes2.getString(ReservedAttribute.SCREEN_NAME)); + Assert.assertEquals(uniqueIDOfFragmentA, + attributes2.getString(ReservedAttribute.SCREEN_UNIQUE_ID)); + Assert.assertEquals(activityA.getClass().getSimpleName(), + attributes2.getString(ReservedAttribute.PREVIOUS_SCREEN_NAME)); + Assert.assertEquals(String.valueOf(activityA.hashCode()), + attributes2.getString(ReservedAttribute.PREVIOUS_SCREEN_UNIQUE_ID)); + } + } + + /** + * test record two screen view event manually when automatic tracking is disabled. + * + * @throws Exception exception + */ + @Test + public void testRecordTwoScreenViewWhenAutoTrackIsDisabled() throws Exception { + clickstreamContext.getClickstreamConfiguration().withTrackScreenViewEvents(false); + Fragment fragmentA = mock(FragmentA.class); + String uniqueIDOfFragmentA = String.valueOf(fragmentA.hashCode()); + Fragment fragmentB = mock(FragmentB.class); + String uniqueIDOfFragmentB = String.valueOf(fragmentB.hashCode()); + final AnalyticsEvent eventA = + clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW); + eventA.addAttribute(ClickstreamAnalytics.Attr.SCREEN_NAME, fragmentA.getClass().getSimpleName()); + eventA.addAttribute(ClickstreamAnalytics.Attr.SCREEN_UNIQUE_ID, uniqueIDOfFragmentA); + client.recordViewScreenManually(eventA); + Thread.sleep(1100); + final AnalyticsEvent eventB = + clickstreamContext.getAnalyticsClient().createEvent(Event.PresetEvent.SCREEN_VIEW); + eventB.addAttribute(ClickstreamAnalytics.Attr.SCREEN_NAME, fragmentB.getClass().getSimpleName()); + eventB.addAttribute(ClickstreamAnalytics.Attr.SCREEN_UNIQUE_ID, uniqueIDOfFragmentB); + client.recordViewScreenManually(eventB); + try (Cursor cursor = dbUtil.queryAllEvents()) { + // assert last screen view + cursor.moveToLast(); + String eventString = cursor.getString(2); + JSONObject jsonObject = new JSONObject(eventString); + String eventName = jsonObject.getString("event_type"); + assertEquals(Event.PresetEvent.SCREEN_VIEW, eventName); + JSONObject attributes = jsonObject.getJSONObject("attributes"); + Assert.assertEquals(fragmentB.getClass().getSimpleName(), + attributes.getString(ReservedAttribute.SCREEN_NAME)); + Assert.assertEquals(uniqueIDOfFragmentB, attributes.getString(ReservedAttribute.SCREEN_UNIQUE_ID)); + Assert.assertEquals(fragmentA.getClass().getSimpleName(), + attributes.getString(ReservedAttribute.PREVIOUS_SCREEN_NAME)); + Assert.assertEquals(uniqueIDOfFragmentA, attributes.getString(ReservedAttribute.PREVIOUS_SCREEN_UNIQUE_ID)); + // assert user engagement of fragmentA + cursor.moveToPrevious(); + String eventString1 = cursor.getString(2); + JSONObject jsonObject1 = new JSONObject(eventString1); + String eventName1 = jsonObject1.getString("event_type"); + assertEquals(Event.PresetEvent.USER_ENGAGEMENT, eventName1); + JSONObject attributes1 = jsonObject1.getJSONObject("attributes"); + Assert.assertTrue(attributes1.getLong(ReservedAttribute.ENGAGEMENT_TIMESTAMP) > 1100); + Assert.assertEquals(fragmentA.getClass().getSimpleName(), + attributes1.getString(ReservedAttribute.SCREEN_NAME)); + Assert.assertEquals(uniqueIDOfFragmentA, attributes1.getString(ReservedAttribute.SCREEN_UNIQUE_ID)); + // assert screen view of fragmentA + cursor.moveToPrevious(); + String eventString2 = cursor.getString(2); + JSONObject jsonObject2 = new JSONObject(eventString2); + String eventName2 = jsonObject2.getString("event_type"); + assertEquals(Event.PresetEvent.SCREEN_VIEW, eventName2); + JSONObject attributes2 = jsonObject2.getJSONObject("attributes"); + Assert.assertEquals(fragmentA.getClass().getSimpleName(), + attributes2.getString(ReservedAttribute.SCREEN_NAME)); + Assert.assertEquals(uniqueIDOfFragmentA, attributes2.getString(ReservedAttribute.SCREEN_UNIQUE_ID)); + Assert.assertFalse(attributes2.has(ReservedAttribute.PREVIOUS_SCREEN_NAME)); + Assert.assertFalse(attributes2.has(ReservedAttribute.PREVIOUS_SCREEN_UNIQUE_ID)); + } + } + /** * test app version not update. * @@ -754,4 +935,10 @@ static class ActivityA extends Activity { static class ActivityB extends Activity { } + + static class FragmentA extends Fragment { + } + + static class FragmentB extends Fragment { + } } diff --git a/clickstream/src/test/java/software/aws/solution/clickstream/IntegrationTest.java b/clickstream/src/test/java/software/aws/solution/clickstream/IntegrationTest.java index 91e703e..cb62388 100644 --- a/clickstream/src/test/java/software/aws/solution/clickstream/IntegrationTest.java +++ b/clickstream/src/test/java/software/aws/solution/clickstream/IntegrationTest.java @@ -195,6 +195,36 @@ public void testRecordOneEvent() throws Exception { cursor.close(); } + /** + * test record Screen View Event manually. + * + * @throws Exception exception + */ + @Test + public void testRecordScreenViewEvent() throws Exception { + executeBackground(); + ClickstreamEvent event = + ClickstreamEvent.builder() + .name(ClickstreamAnalytics.Event.SCREEN_VIEW) + .add(ClickstreamAnalytics.Attr.SCREEN_NAME, "HomeFragment") + .add(ClickstreamAnalytics.Attr.SCREEN_UNIQUE_ID, "23ac31df") + .build(); + ClickstreamAnalytics.recordEvent(event); + assertEquals(1, dbUtil.getTotalNumber()); + + Cursor cursor = dbUtil.queryAllEvents(); + cursor.moveToFirst(); + String eventString = cursor.getString(2); + JSONObject jsonObject = new JSONObject(eventString); + JSONObject attribute = jsonObject.getJSONObject("attributes"); + Assert.assertEquals(ClickstreamAnalytics.Event.SCREEN_VIEW, jsonObject.getString("event_type")); + Assert.assertEquals("HomeFragment", attribute.getString(ClickstreamAnalytics.Attr.SCREEN_NAME)); + Assert.assertEquals(0, attribute.getInt(Event.ReservedAttribute.ENTRANCES)); + Thread.sleep(1500); + assertEquals(0, dbUtil.getTotalNumber()); + cursor.close(); + } + /** * test add items. * From 39a17e104008f539a6bfdea0275ee547b10a5acf Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Tue, 20 Feb 2024 14:52:18 +0800 Subject: [PATCH 2/4] fix: typo in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 685f68e..11d401c 100644 --- a/README.md +++ b/README.md @@ -208,10 +208,10 @@ ClickstreamAnalytics.recordEvent(event); By default, SDK will automatically track the preset `_screen_view` event when Activity triggers `onResume`. -You can also manually record screen view event whether or not automatic screen view tracking is enabled, add the following code to record a Screen View event with two attributes. +You can also manually record screen view events whether or not automatic screen view tracking is enabled, add the following code to record a screen view event with two attributes. * `SCREEN_NAME` Required. Your screen's name. -* `SCREEN_UNIQUE_ID` Optional. set the hashcode of your Activity, Fragment or View. And if you do not set, SDK will sets a default value based on the current Activity's hashcode. +* `SCREEN_UNIQUE_ID` Optional. Set the hashcode of your Activity, Fragment, or View. If you do not set, SDK will set a default value based on the current Activity's hashcode. ```java import software.aws.solution.clickstream.ClickstreamAnalytcs; From c2644cea03c3b2f613820f36f869316e80c813ef Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Wed, 21 Feb 2024 08:59:36 +0800 Subject: [PATCH 3/4] fix: when two test suite are skipped --- integrationtest/devicefarm/automate_device_farm.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/integrationtest/devicefarm/automate_device_farm.py b/integrationtest/devicefarm/automate_device_farm.py index 37822e6..ad9112e 100644 --- a/integrationtest/devicefarm/automate_device_farm.py +++ b/integrationtest/devicefarm/automate_device_farm.py @@ -148,14 +148,15 @@ def download_artifacts(jobs_response, save_path): filename = artifact['type'] + "_" + artifact['name'] + "." + artifact['extension'] if str(filename).endswith(".logcat") or str(filename).endswith(".zip"): artifact_save_path = os.path.join(path_to, filename) - if str(filename).endswith(".logcat"): - logcat_paths.append(artifact_save_path) print("Downloading " + artifact_save_path) with open(artifact_save_path, 'wb') as fn, \ requests.get(artifact['url'], allow_redirects=True) as request: fn.write(request.content) if str(filename).endswith(".zip"): - unzip_and_copy(artifact_save_path) + result = unzip_and_copy(artifact_save_path) + if result and str(filename).endswith(".logcat"): + logcat_paths.append(artifact_save_path) + return logcat_paths @@ -182,3 +183,6 @@ def unzip_and_copy(zip_path): modified_content = re.sub(r'\bTestShopping\b', "AppiumTest " + device_name, content) with open(result_path, 'w', encoding='utf-8') as file: file.write(modified_content) + if content.__contains__("skipped=\"2\""): + return False + return True From 8990d3eb03160d7521cd20926d6952caa9afdc72 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Wed, 21 Feb 2024 09:15:16 +0800 Subject: [PATCH 4/4] fix: ignore logcat_paths for skipped --- integrationtest/devicefarm/automate_device_farm.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/integrationtest/devicefarm/automate_device_farm.py b/integrationtest/devicefarm/automate_device_farm.py index ad9112e..25ad15b 100644 --- a/integrationtest/devicefarm/automate_device_farm.py +++ b/integrationtest/devicefarm/automate_device_farm.py @@ -142,20 +142,21 @@ def download_artifacts(jobs_response, save_path): type=artifact_type, arn=test['arn'] )['artifacts'] + is_valid_test = True for artifact in artifacts: path_to = os.path.join(save_path, job_name) os.makedirs(path_to, exist_ok=True) filename = artifact['type'] + "_" + artifact['name'] + "." + artifact['extension'] if str(filename).endswith(".logcat") or str(filename).endswith(".zip"): artifact_save_path = os.path.join(path_to, filename) + if is_valid_test and str(filename).endswith(".logcat"): + logcat_paths.append(artifact_save_path) print("Downloading " + artifact_save_path) with open(artifact_save_path, 'wb') as fn, \ requests.get(artifact['url'], allow_redirects=True) as request: fn.write(request.content) if str(filename).endswith(".zip"): - result = unzip_and_copy(artifact_save_path) - if result and str(filename).endswith(".logcat"): - logcat_paths.append(artifact_save_path) + is_valid_test = unzip_and_copy(artifact_save_path) return logcat_paths