Skip to content

Commit

Permalink
Merge pull request #418 from Countly/remove_frm_endv
Browse files Browse the repository at this point in the history
feat: remove visibility from the end view
  • Loading branch information
turtledreams authored Nov 12, 2024
2 parents 8683e36 + 020ebae commit 31d9d8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
20 changes: 12 additions & 8 deletions sdk/src/main/java/ly/count/android/sdk/ModuleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,22 @@ public void recordEventInternal(@Nullable final String key, @Nullable Map<String
_cly.moduleUserProfile.saveInternal();

if (visibilityTracking) {
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 + "]");

if (segmentation == null) {
segmentation = new HashMap<>();
}

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) {
Expand Down

0 comments on commit 31d9d8a

Please sign in to comment.