@@ -51,6 +51,9 @@ class OSInAppMessageController implements OSDynamicTriggerControllerObserver, OS
51
51
// This means their impression has been successfully posted to our backend and should not be counted again
52
52
@ NonNull
53
53
final private Set <String > impressionedMessages ;
54
+ // This means their impression has been successfully posted to our backend and should not be counted again
55
+ @ NonNull
56
+ final private Set <String > viewedPageIds ;
54
57
// IAM clicks that have been successfully posted to our backend and should not be counted again
55
58
@ NonNull
56
59
final private Set <String > clickedClickIds ;
@@ -75,6 +78,7 @@ protected OSInAppMessageController(OneSignalDbHelper dbHelper, OSLogger logger)
75
78
dismissedMessages = OSUtils .newConcurrentSet ();
76
79
messageDisplayQueue = new ArrayList <>();
77
80
impressionedMessages = OSUtils .newConcurrentSet ();
81
+ viewedPageIds = OSUtils .newConcurrentSet ();
78
82
clickedClickIds = OSUtils .newConcurrentSet ();
79
83
triggerController = new OSTriggerController (this );
80
84
systemConditionController = new OSSystemConditionController (this );
@@ -96,6 +100,14 @@ protected OSInAppMessageController(OneSignalDbHelper dbHelper, OSLogger logger)
96
100
if (tempImpressionsSet != null )
97
101
impressionedMessages .addAll (tempImpressionsSet );
98
102
103
+ Set <String > tempPageImpressionsSet = OneSignalPrefs .getStringSet (
104
+ OneSignalPrefs .PREFS_ONESIGNAL ,
105
+ OneSignalPrefs .PREFS_OS_PAGE_IMPRESSIONED_IAMS ,
106
+ null
107
+ );
108
+ if (tempPageImpressionsSet != null )
109
+ viewedPageIds .addAll (tempPageImpressionsSet );
110
+
99
111
Set <String > tempClickedMessageIdsSet = OneSignalPrefs .getStringSet (
100
112
OneSignalPrefs .PREFS_ONESIGNAL ,
101
113
OneSignalPrefs .PREFS_OS_CLICKED_CLICK_IDS_IAMS ,
@@ -417,18 +429,30 @@ else if (action.getUrlTarget() == OSInAppMessageAction.OSInAppMessageActionUrlTy
417
429
}
418
430
}
419
431
432
+ private void saveViewedPageIdsToPrefs () {
433
+ OneSignalPrefs .saveStringSet (
434
+ OneSignalPrefs .PREFS_ONESIGNAL ,
435
+ OneSignalPrefs .PREFS_OS_PAGE_IMPRESSIONED_IAMS ,
436
+ // Post success, store impressioned pages to disk
437
+ viewedPageIds );
438
+ }
439
+
420
440
private void fireRESTCallForPageChange (@ NonNull final OSInAppMessage message , @ NonNull final OSInAppMessagePage page ) {
421
441
final String variantId = variantIdForMessage (message );
422
442
if (variantId == null )
423
443
return ;
424
444
425
445
final String pageId = page .getPageId ();
426
446
447
+ final String messagePrefixedPageId = message .messageId + pageId ;
448
+
427
449
// Never send multiple page impressions for the same message UUID unless that page change is from an IAM with redisplay
428
- if (message .getViewedPageIds ().contains (pageId ))
450
+ if (viewedPageIds .contains (messagePrefixedPageId )) {
451
+ OneSignal .onesignalLog (OneSignal .LOG_LEVEL .VERBOSE , "Already sent page impression for id: " + pageId );
429
452
return ;
453
+ }
430
454
431
- message . addPageId ( page . getPageId () );
455
+ viewedPageIds . add ( messagePrefixedPageId );
432
456
433
457
try {
434
458
JSONObject json = new JSONObject () {{
@@ -443,18 +467,14 @@ private void fireRESTCallForPageChange(@NonNull final OSInAppMessage message, @N
443
467
@ Override
444
468
void onSuccess (String response ) {
445
469
printHttpSuccessForInAppMessageRequest ("page impression" , response );
446
- /*OneSignalPrefs.saveStringSet(
447
- OneSignalPrefs.PREFS_ONESIGNAL,
448
- OneSignalPrefs.PREFS_OS_PAGE_IMPRESSIONED_IAMS,
449
- // Post success, store impressioned page to disk
450
- impressionedMessages);*/
470
+ saveViewedPageIdsToPrefs ();
451
471
}
452
472
453
473
@ Override
454
474
void onFailure (int statusCode , String response , Throwable throwable ) {
455
475
printHttpErrorForInAppMessageRequest ("page impression" , statusCode , response );
456
- // Post failed, impressionedMessage should be removed and this way another post can be attempted
457
- message . getViewedPageIds (). remove (page . getPageId () );
476
+ // Post failed, viewed page should be removed and this way another post can be attempted
477
+ viewedPageIds . remove (messagePrefixedPageId );
458
478
}
459
479
});
460
480
} catch (JSONException e ) {
@@ -548,8 +568,11 @@ private void setDataForRedisplay(OSInAppMessage message) {
548
568
549
569
dismissedMessages .remove (message .messageId );
550
570
impressionedMessages .remove (message .messageId );
571
+ // Pages from different IAMs should not impact each other so we can clear the entire
572
+ // list when an IAM is dismissed or we are re-displaying the same one
573
+ viewedPageIds .clear ();
574
+ saveViewedPageIdsToPrefs ();
551
575
message .clearClickIds ();
552
- message .clearPageIds ();
553
576
}
554
577
}
555
578
}
0 commit comments