Skip to content

Commit

Permalink
Exclude features from IAM preview
Browse files Browse the repository at this point in the history
   * Redisplay, tags, outcomes, impression should not be included on IAM preview
  • Loading branch information
Jeasmine committed Mar 23, 2020
1 parent 02b7060 commit 70cea7e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ + (instancetype _Nullable)instancePreviewFromPayload:(OSNotificationPayload * _N
}

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

@end
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#import "OSJSONHandling.h"
#import "OneSignal.h"

@interface OSInAppMessageTag : NSObject <OSJSONDecodable>
@interface OSInAppMessageTag : NSObject <OSJSONEncodable, OSJSONDecodable>

@property (strong, nonatomic, nullable) NSDictionary *tagsToAdd;
@property (strong, nonatomic, nullable) NSArray *tagsToRemove;
Expand Down
13 changes: 13 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

#import "OSInAppMessageTag.h"
#import "OneSignalHelper.h"

@implementation OSInAppMessageTag

Expand Down Expand Up @@ -64,6 +65,18 @@ + (instancetype _Nullable)instancePreviewFromPayload:(OSNotificationPayload * _N
return nil;
}


- (NSDictionary *)jsonRepresentation {
let json = [NSMutableDictionary new];

if (_tagsToAdd)
json[@"adds"] = _tagsToAdd;
if (_tagsToRemove)
json[@"removes"] = _tagsToRemove;

return json;
}

- (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessageTag tagsToAdd: %@ \ntagsToRemove: %@", _tagsToAdd, _tagsToRemove];
}
Expand Down
28 changes: 24 additions & 4 deletions iOS_SDK/OneSignalSDK/Source/OSMessagingController.m
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ - (void)messageViewControllerWasDismissed {
OSInAppMessage *showingIAM = self.messageDisplayQueue.firstObject;
[self.seenInAppMessages addObject:showingIAM.messageId];
[OneSignalUserDefaults.initStandard saveSetForKey:OS_IAM_SEEN_SET_KEY withValue:self.seenInAppMessages];
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Dismissing IAM save seenInAppMessages: %@", _seenInAppMessages]];
// Remove dismissed IAM from messageDisplayQueue
[self.messageDisplayQueue removeObjectAtIndex:0];
[self persistInAppMessageForRedisplay:showingIAM];
Expand Down Expand Up @@ -477,8 +478,8 @@ - (void)hideWindow {
}

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

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

if (message.isPreview) {
[self processPreviewInAppMessage:message withAction:action];
return;
}

// The following features are for non preview IAM
// Make sure no click, outcome, tag tracking is performed for IAM previews
[self sendClickRESTCall:message withAction:action];
[self sendTagCallWithAction:action];
[self sendOutcomes:action.outcomes];
}

/*
* Show the developer what will happen with a non IAM preview
*/
- (void)processPreviewInAppMessage:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action {
if (action.tags)
[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]];

if (action.outcomes.count > 0) {
[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]]];
}
}

/*
* Checks if a click being available:
* 1. Redisplay is enabled and click is available within message
Expand All @@ -548,11 +569,10 @@ - (BOOL)isClickAvailable:(OSInAppMessage *)message withClickId:(NSString *)click

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

0 comments on commit 70cea7e

Please sign in to comment.