diff --git a/CHANGELOG.md b/CHANGELOG.md index 561960946..7eaa44fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## XX.XX.XX +* Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!) + ## 24.7.5 * ! Minor breaking change ! All active views will now automatically stop when consent for "views" is revoked. diff --git a/sdk/src/androidTest/java/ly/count/android/sdk/ModuleEventsTests.java b/sdk/src/androidTest/java/ly/count/android/sdk/ModuleEventsTests.java index e2ef6602a..0cd842301 100644 --- a/sdk/src/androidTest/java/ly/count/android/sdk/ModuleEventsTests.java +++ b/sdk/src/androidTest/java/ly/count/android/sdk/ModuleEventsTests.java @@ -807,8 +807,8 @@ public void recordEvent_visibilityTracking_onlyAddingItToViewsAndEvents() throws countly.events().recordEvent(ModuleFeedback.RATING_EVENT_KEY, TestUtils.map()); validateEventInRQ(ModuleFeedback.RATING_EVENT_KEY, TestUtils.map(), 1, 0.0d, 0.0d, 4); - countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map()); - validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("cly_v", 0), 1, 0.0d, 0.0d, 5); + countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("visit", 1)); + validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("cly_v", 0, "visit", 1), 1, 0.0d, 0.0d, 5); countly.events().recordEvent(ModuleViews.ORIENTATION_EVENT_KEY, TestUtils.map()); validateEventInRQ(ModuleViews.ORIENTATION_EVENT_KEY, TestUtils.map(), 1, 0.0d, 0.0d, 6); @@ -834,16 +834,16 @@ public void recordEvent_visibilityTracking_bgFgSwitch() throws JSONException { countly.onStart(Mockito.mock(Activity.class)); //foreground - countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map()); - validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("cly_v", 1), 1, 0.0d, 0.0d, 2); + countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("visit", 1)); + validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("cly_v", 1, "visit", 1), 1, 0.0d, 0.0d, 2); countly.events().recordEvent("fg", TestUtils.map()); validateEventInRQ("fg", TestUtils.map("cly_v", 1), 1, 0.0d, 0.0d, 3); countly.onStop(); //background - countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map()); - validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("cly_v", 0), 1, 0.0d, 0.0d, 5); + countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("visit", 1)); + validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("cly_v", 0, "visit", 1), 1, 0.0d, 0.0d, 5); countly.events().recordEvent("bg", TestUtils.map()); validateEventInRQ("bg", TestUtils.map("cly_v", 0), 1, 0.0d, 0.0d, 6); @@ -864,16 +864,16 @@ public void recordEvent_visibilityTracking_notEnabled() throws JSONException { countly.onStart(Mockito.mock(Activity.class)); //foreground - countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map()); - validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map(), 1, 0.0d, 0.0d, 2); + countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("visit", 1)); + validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("visit", 1), 1, 0.0d, 0.0d, 2); countly.events().recordEvent("fg", TestUtils.map()); validateEventInRQ("fg", TestUtils.map(), 1, 0.0d, 0.0d, 3); countly.onStop(); //background - countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map()); - validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map(), 1, 0.0d, 0.0d, 5); + countly.events().recordEvent(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("visit", 1)); + validateEventInRQ(ModuleViews.VIEW_EVENT_KEY, TestUtils.map("visit", 1), 1, 0.0d, 0.0d, 5); countly.events().recordEvent("bg", TestUtils.map()); validateEventInRQ("bg", TestUtils.map(), 1, 0.0d, 0.0d, 6); diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleEvents.java b/sdk/src/main/java/ly/count/android/sdk/ModuleEvents.java index 4e0857817..0261b1761 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleEvents.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleEvents.java @@ -156,18 +156,22 @@ public void recordEventInternal(@Nullable final String key, @Nullable Map(); } - segmentation.put(VISIBILITY_KEY, state); + if (ModuleViews.VIEW_EVENT_KEY.equals(key) && !segmentation.containsKey("visit")) { + L.d("[ModuleEvents] recordEventInternal, visibility key will not be added to the end view event"); + } else { + String appInBackground = deviceInfo.isInBackground(); + int state = 1; // in foreground + if ("true".equals(appInBackground)) { + state = 0; // in background + } + L.d("[ModuleEvents] recordEventInternal, Adding visibility tracking to segmentation app in background:[" + appInBackground + "] cly_v:[" + state + "]"); + + segmentation.put(VISIBILITY_KEY, state); + } } switch (key) {