Skip to content

Commit

Permalink
Merge pull request #735 from OneSignal/feature/iam_carousel
Browse files Browse the repository at this point in the history
Iam carousel page impressions
  • Loading branch information
emawby authored Dec 23, 2020
2 parents fc3ba57 + 1374c71 commit 77cb220
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 54 deletions.
12 changes: 12 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@
DE20425E24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
DE20425F24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
DE20426024E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
DE367CC724EEF2BE00165207 /* OSInAppMessagePage.m in Sources */ = {isa = PBXBuildFile; fileRef = DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */; };
DE367CC824EEF2BE00165207 /* OSInAppMessagePage.m in Sources */ = {isa = PBXBuildFile; fileRef = DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */; };
DE367CC924EEF2BE00165207 /* OSInAppMessagePage.m in Sources */ = {isa = PBXBuildFile; fileRef = DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */; };
DE367CCA24EEF2C800165207 /* OSInAppMessagePage.h in Headers */ = {isa = PBXBuildFile; fileRef = DE367CC524EEF2A800165207 /* OSInAppMessagePage.h */; };
DE5EFECA24D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */; };
DE98772B2591656200DE07D5 /* NSDateFormatter+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */; };
DE9877332591656200DE07D5 /* NSDateFormatter+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */; };
Expand Down Expand Up @@ -730,6 +734,8 @@
DE16C14624D3727200670EFA /* OneSignalLifecycleObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalLifecycleObserver.h; sourceTree = "<group>"; };
DE20425C24E21C1500350E4F /* UIApplication+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIApplication+OneSignal.h"; sourceTree = "<group>"; };
DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+OneSignal.m"; sourceTree = "<group>"; };
DE367CC524EEF2A800165207 /* OSInAppMessagePage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessagePage.h; sourceTree = "<group>"; };
DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessagePage.m; sourceTree = "<group>"; };
DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageViewControllerOverrider.m; sourceTree = "<group>"; };
DE5EFECB24D8DC0E0032632D /* OSInAppMessageViewControllerOverrider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageViewControllerOverrider.h; sourceTree = "<group>"; };
DE9877292591654600DE07D5 /* NSDateFormatter+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSDateFormatter+OneSignal.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1286,6 +1292,8 @@
7A880F302404AE7B0081F5E8 /* OSInAppMessagePushPrompt.m */,
7AD172362416D52D00A78B19 /* OSInAppMessageLocationPrompt.h */,
7AD172372416D53B00A78B19 /* OSInAppMessageLocationPrompt.m */,
DE367CC524EEF2A800165207 /* OSInAppMessagePage.h */,
DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -1395,6 +1403,7 @@
7AF98684244A32D900C36EAE /* OSOutcomeEventsV2Repository.h in Headers */,
CA8E18FC2193A1A5009DA223 /* NSTimerOverrider.h in Headers */,
91B6EA451E86555200B5CF01 /* OSObservable.h in Headers */,
DE367CCA24EEF2C800165207 /* OSInAppMessagePage.h in Headers */,
CACBAA9C218A6243000ACAA5 /* OSInAppMessageView.h in Headers */,
912412351E73342200E41FD7 /* OneSignalTrackIAP.h in Headers */,
7AF9868A244A556300C36EAE /* OSOutcomeEventsFactory.h in Headers */,
Expand Down Expand Up @@ -1699,6 +1708,7 @@
CAB269E021B2038B00F8A43C /* OSInAppMessageBridgeEvent.m in Sources */,
91B6EA411E85D38F00B5CF01 /* OSObservable.m in Sources */,
7AF986432444C47400C36EAE /* OSNotificationTracker.m in Sources */,
DE367CC724EEF2BE00165207 /* OSInAppMessagePage.m in Sources */,
4529DF0C1FA932AC00CEAB1D /* OneSignalTrackFirebaseAnalytics.m in Sources */,
7A676BE524981CEC003957CC /* OSDeviceState.m in Sources */,
7AFE856B2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */,
Expand Down Expand Up @@ -1791,6 +1801,7 @@
7AF986442444C47400C36EAE /* OSNotificationTracker.m in Sources */,
912412271E73342200E41FD7 /* OneSignalMobileProvision.m in Sources */,
912412331E73342200E41FD7 /* OneSignalTracker.m in Sources */,
DE367CC824EEF2BE00165207 /* OSInAppMessagePage.m in Sources */,
91B6EA421E85D38F00B5CF01 /* OSObservable.m in Sources */,
7AC8D3A924993A0F0023EDE8 /* OSDeviceState.m in Sources */,
CA810FD2202BA97600A60FED /* OSEmailSubscription.m in Sources */,
Expand Down Expand Up @@ -1938,6 +1949,7 @@
7AECE59823674AB700537907 /* OSUnattributedFocusTimeProcessor.m in Sources */,
7A5A818224897693002E07C8 /* MigrationTests.m in Sources */,
7AECE5A023675F6300537907 /* OSFocusTimeProcessorFactory.m in Sources */,
DE367CC924EEF2BE00165207 /* OSInAppMessagePage.m in Sources */,
9129C6C01E89E7AB009CB6A0 /* OSSubscription.m in Sources */,
7AC8D3A824993A0E0023EDE8 /* OSDeviceState.m in Sources */,
CA63AFC52022670A00E340FB /* ReattemptRequest.m in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion iOS_SDK/OneSignalSDK/Source/OSInAppMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@interface OSInAppMessage ()

@property (strong, nonatomic, nonnull) NSMutableSet <NSString *> *clickedClickIds;
@property (strong, nonatomic, nonnull) NSMutableSet <NSString *> *viewedPageIds;

@end

Expand All @@ -40,6 +41,7 @@ @implementation OSInAppMessage
- (instancetype)init {
if (self = [super init]) {
self.clickedClickIds = [[NSMutableSet alloc] init];
self.viewedPageIds = [NSMutableSet new];
self.isTriggerChanged = false;
}

Expand All @@ -61,7 +63,7 @@ - (BOOL)isClickAvailable:(NSString *)clickId {
}

- (void)clearClickIds {
_clickedClickIds = [[NSMutableSet alloc] init];
_clickedClickIds = [NSMutableSet new];
}

- (void)addClickId:(NSString *)clickId {
Expand Down
5 changes: 5 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ + (instancetype _Nullable)instanceWithJson:(NSDictionary *)json {
if ([json[@"name"] isKindOfClass:[NSString class]])
action.clickName = json[@"name"];

if ([json[@"pageId"] isKindOfClass:[NSString class]])
action.pageId = json[@"pageId"];

if ([json[@"url_target"] isKindOfClass:[NSString class]] && OS_IS_VALID_URL_ACTION(json[@"url_target"]))
action.urlActionType = OS_URL_ACTION_TYPE_FROM_STRING(json[@"url_target"]);
else
Expand All @@ -72,6 +75,8 @@ + (instancetype _Nullable)instanceWithJson:(NSDictionary *)json {
action.closesMessage = [json[@"close"] boolValue];
else
action.closesMessage = true; // Default behavior

[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"OSInAppMessageAction %@", json]];

NSMutableArray *outcomes = [NSMutableArray new];
//TODO: when backend is ready check that key matches
Expand Down
10 changes: 8 additions & 2 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
#import <Foundation/Foundation.h>
#import "OSJSONHandling.h"
#import "OSInAppMessageAction.h"
#import "OSInAppMessagePage.h"
#import "OSInAppMessagingDefines.h"

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, OSInAppMessageBridgeEventType) {
OSInAppMessageBridgeEventTypePageRenderingComplete,
OSInAppMessageBridgeEventTypeActionTaken,
OSInAppMessageBridgeEventTypePageResize
OSInAppMessageBridgeEventTypePageResize,
OSInAppMessageBridgeEventTypePageChange,
};

@interface OSInAppMessageBridgeEventRenderingComplete : NSObject <OSJSONDecodable>
Expand All @@ -48,12 +50,16 @@ typedef NS_ENUM(NSUInteger, OSInAppMessageBridgeEventType) {
@property (nonatomic) NSNumber *height;
@end

@interface OSInAppMessageBridgeEventPageChange : NSObject <OSJSONDecodable>
@property (nonatomic) OSInAppMessagePage *page;
@end

@interface OSInAppMessageBridgeEvent : NSObject <OSJSONDecodable>
@property (nonatomic) OSInAppMessageBridgeEventType type;
@property (nonatomic) OSInAppMessageBridgeEventRenderingComplete *renderingComplete;
@property (nonatomic) OSInAppMessageBridgeEventResize *resize;
@property (nonatomic, nullable) OSInAppMessageBridgeEventPageChange *pageChange;
@property (strong, nonatomic, nullable) OSInAppMessageAction *userAction;
@end


NS_ASSUME_NONNULL_END
70 changes: 50 additions & 20 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@

@implementation OSInAppMessageBridgeEvent

+ (instancetype _Nullable)instanceWithData:(NSData *)data {
+ (instancetype)instanceWithData:(NSData *)data {
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

if (error || !json) {
[OneSignal onesignal_Log:ONE_S_LL_WARN message:[NSString stringWithFormat:@"Unable to decode JS-bridge event with error: %@", error.description ?: @"Unknown Error"]];
return nil;
Expand All @@ -51,26 +50,35 @@ + (instancetype _Nullable)instanceWithJson:(NSDictionary *)json {
else
return nil;

if (instance.type == OSInAppMessageBridgeEventTypeActionTaken) {
// deserialize the action JSON
if ([json[@"body"] isKindOfClass:[NSDictionary class]]) {

let action = [OSInAppMessageAction instanceWithJson:json[@"body"]];

if (!action)
switch (instance.type) {
case OSInAppMessageBridgeEventTypeActionTaken: {
// deserialize the action JSON
if ([json[@"body"] isKindOfClass:[NSDictionary class]]) {

let action = [OSInAppMessageAction instanceWithJson:json[@"body"]];

if (!action)
return nil;

instance.userAction = action;
}
else
return nil;

instance.userAction = action;
break;
}
case OSInAppMessageBridgeEventTypePageRenderingComplete: {
instance.renderingComplete = [OSInAppMessageBridgeEventRenderingComplete instanceWithJson:json];
break;
}
case OSInAppMessageBridgeEventTypePageResize: {
instance.resize = [OSInAppMessageBridgeEventResize instanceWithJson:json];
break;
}
case OSInAppMessageBridgeEventTypePageChange: {
instance.pageChange = [OSInAppMessageBridgeEventPageChange instanceWithJson:json];
break;
}
else
return nil;
}
else if (instance.type == OSInAppMessageBridgeEventTypePageRenderingComplete) {
instance.renderingComplete = [OSInAppMessageBridgeEventRenderingComplete instanceWithJson:json];
} else if (instance.type == OSInAppMessageBridgeEventTypePageResize) {
instance.resize = [OSInAppMessageBridgeEventResize instanceWithJson:json];
}

return instance;
}

Expand All @@ -90,7 +98,7 @@ + (instancetype _Nullable)instanceWithData:(NSData *)data {
return nil;
}

+ (instancetype _Nullable)instanceWithJson:(NSDictionary *)json {
+ (instancetype)instanceWithJson:(NSDictionary *)json {
let instance = [OSInAppMessageBridgeEventRenderingComplete new];

if (json[@"displayLocation"])
Expand Down Expand Up @@ -140,3 +148,25 @@ - (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessageBridgeEventResize height: %@", _height];
}
@end

@implementation OSInAppMessageBridgeEventPageChange
+ (instancetype)instanceWithData:(NSData *)data {
return nil;
}

+ (instancetype)instanceWithJson:(NSDictionary *)json {
let instance = [OSInAppMessageBridgeEventPageChange new];
instance.page = [OSInAppMessagePage instanceWithJson:json];
return instance;
}

+ (instancetype _Nullable)instancePreviewFromNotification:(OSNotification * _Nonnull)notification {
return nil;
}

- (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessageBridgeEventPageChange pageId: %@ pageIndex: %@", _page.pageId, _page.pageIndex];
}

@end

36 changes: 36 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessagePage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Modified MIT License
*
* Copyright 2020 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#import <Foundation/Foundation.h>
#import "OSJSONHandling.h"

@interface OSInAppMessagePage : NSObject <OSJSONDecodable>

@property (strong, nonatomic, nonnull) NSString *pageId;
@property (strong, nonatomic, nonnull) NSNumber *pageIndex;

@end
60 changes: 60 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessagePage.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Modified MIT License
*
* Copyright 2020 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#import "OSInAppMessagePage.h"

@implementation OSInAppMessagePage

+ (instancetype _Nullable)instanceWithData:(NSData * _Nonnull)data {
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

if (error || !json) {
[OneSignal onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"OSInAppMessagePage Unable to decode in-app message JSON: %@", error.description ?: @"No Data"]];
return nil;
}

return [self instanceWithJson:json];
}

+ (instancetype _Nullable)instanceWithJson:(NSDictionary * _Nonnull)json {
OSInAppMessagePage *page = [OSInAppMessagePage new];

if ([json[@"pageId"] isKindOfClass:[NSString class]])
page.pageId = json[@"pageId"];

if ([json[@"pageIndex"] isKindOfClass:[NSNumber class]])
page.pageIndex = json[@"pageIndex"];

return page;
}

+ (instancetype _Nullable)instancePreviewFromNotification:(OSNotification * _Nonnull)notification {
return nil;
}

@end
1 change: 1 addition & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol OSInAppMessageViewControllerDelegate <NSObject>

- (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action;
- (void)messageViewDidDisplayPage:(OSInAppMessage *)message withPageId:(NSString *)pageId;
- (void)messageViewControllerWasDismissed;
- (void)webViewContentFinishedLoading;

Expand Down
Loading

0 comments on commit 77cb220

Please sign in to comment.