Skip to content

Commit 70cea7e

Browse files
committed
Exclude features from IAM preview
* Redisplay, tags, outcomes, impression should not be included on IAM preview
1 parent 02b7060 commit 70cea7e

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ + (instancetype _Nullable)instancePreviewFromPayload:(OSNotificationPayload * _N
6666
}
6767

6868
- (NSString *)description {
69-
return [NSString stringWithFormat:@"OSInAppMessageOutcome name: %@\nweight: %@unique: %s\n", _name, _weight, _unique ? "YES" : "NO"];
69+
return [NSString stringWithFormat:@"OSInAppMessageOutcome name: %@ weight: %@ unique: %s\n", _name, _weight, _unique ? "YES" : "NO"];
7070
}
7171

7272
@end

iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#import "OSJSONHandling.h"
3333
#import "OneSignal.h"
3434

35-
@interface OSInAppMessageTag : NSObject <OSJSONDecodable>
35+
@interface OSInAppMessageTag : NSObject <OSJSONEncodable, OSJSONDecodable>
3636

3737
@property (strong, nonatomic, nullable) NSDictionary *tagsToAdd;
3838
@property (strong, nonatomic, nullable) NSArray *tagsToRemove;

iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#import "OSInAppMessageTag.h"
29+
#import "OneSignalHelper.h"
2930

3031
@implementation OSInAppMessageTag
3132

@@ -64,6 +65,18 @@ + (instancetype _Nullable)instancePreviewFromPayload:(OSNotificationPayload * _N
6465
return nil;
6566
}
6667

68+
69+
- (NSDictionary *)jsonRepresentation {
70+
let json = [NSMutableDictionary new];
71+
72+
if (_tagsToAdd)
73+
json[@"adds"] = _tagsToAdd;
74+
if (_tagsToRemove)
75+
json[@"removes"] = _tagsToRemove;
76+
77+
return json;
78+
}
79+
6780
- (NSString *)description {
6881
return [NSString stringWithFormat:@"OSInAppMessageTag tagsToAdd: %@ \ntagsToRemove: %@", _tagsToAdd, _tagsToRemove];
6982
}

iOS_SDK/OneSignalSDK/Source/OSMessagingController.m

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ - (void)messageViewControllerWasDismissed {
435435
OSInAppMessage *showingIAM = self.messageDisplayQueue.firstObject;
436436
[self.seenInAppMessages addObject:showingIAM.messageId];
437437
[OneSignalUserDefaults.initStandard saveSetForKey:OS_IAM_SEEN_SET_KEY withValue:self.seenInAppMessages];
438+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Dismissing IAM save seenInAppMessages: %@", _seenInAppMessages]];
438439
// Remove dismissed IAM from messageDisplayQueue
439440
[self.messageDisplayQueue removeObjectAtIndex:0];
440441
[self persistInAppMessageForRedisplay:showingIAM];
@@ -477,8 +478,8 @@ - (void)hideWindow {
477478
}
478479

479480
- (void)persistInAppMessageForRedisplay:(OSInAppMessage *)message {
480-
// If the IAM doesn't have the re display prop there is no need to save it
481-
if (![message.displayStats isRedisplayEnabled])
481+
// If the IAM doesn't have the re display prop or is a preview IAM there is no need to save it
482+
if (![message.displayStats isRedisplayEnabled] || message.isPreview)
482483
return;
483484

484485
let displayTimeSeconds = self.dateGenerator();
@@ -511,6 +512,7 @@ - (void)handlePromptActions:(NSArray<NSObject<OSInAppMessagePrompt> *> *)promptA
511512
_currentPromptAction.hasPrompted = YES;
512513
[_currentPromptAction handlePrompt:^(BOOL accepted) {
513514
_currentPromptAction = nil;
515+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"IAM prompt to handle finished accepted: %@", accepted ? @"YES" : @"NO"]];
514516
[self handlePromptActions:promptActions];
515517
}];
516518
} else if (!_viewController) { // IAM dismissed by action
@@ -531,11 +533,30 @@ - (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInApp
531533
if (self.actionClickBlock)
532534
self.actionClickBlock(action);
533535

536+
if (message.isPreview) {
537+
[self processPreviewInAppMessage:message withAction:action];
538+
return;
539+
}
540+
541+
// The following features are for non preview IAM
542+
// Make sure no click, outcome, tag tracking is performed for IAM previews
534543
[self sendClickRESTCall:message withAction:action];
535544
[self sendTagCallWithAction:action];
536545
[self sendOutcomes:action.outcomes];
537546
}
538547

548+
/*
549+
* Show the developer what will happen with a non IAM preview
550+
*/
551+
- (void)processPreviewInAppMessage:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action {
552+
if (action.tags)
553+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Tags detected inside of the action click payload, ignoring because action came from IAM preview\nTags: %@", action.tags.jsonRepresentation]];
554+
555+
if (action.outcomes.count > 0) {
556+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Outcomes detected inside of the action click payload, ignoring because action came from IAM preview: %@", [action.outcomes description]]];
557+
}
558+
}
559+
539560
/*
540561
* Checks if a click being available:
541562
* 1. Redisplay is enabled and click is available within message
@@ -548,11 +569,10 @@ - (BOOL)isClickAvailable:(OSInAppMessage *)message withClickId:(NSString *)click
548569

549570
- (void)sendClickRESTCall:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action {
550571
let clickId = action.clickId;
551-
// Make sure no click tracking is performed for IAM previews
552572
// If the IAM clickId exists within the cached clickedClickIds return early so the click is not tracked
553573
// unless that click is from an IAM with redisplay
554574
// Handles body, button, or image clicks
555-
if (message.isPreview || ![self isClickAvailable:message withClickId:clickId])
575+
if (![self isClickAvailable:message withClickId:clickId])
556576
return;
557577
// Add clickId to clickedClickIds
558578
[self.clickedClickIds addObject:clickId];

0 commit comments

Comments
 (0)