Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// swift-tools-version:5.3
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "mParticle-Rokt",
platforms: [ .iOS(.v11), .tvOS(.v11) ],
platforms: [ .iOS(.v15), .tvOS(.v15) ],
products: [
.library(
name: "mParticle-Rokt",
Expand Down
4 changes: 0 additions & 4 deletions mParticle-Rokt/MPKitRokt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
#if defined(__has_include) && __has_include(<mParticle_Apple_SDK/mParticle.h>)
#import <mParticle_Apple_SDK/mParticle.h>
#import <mParticle_Apple_SDK/mParticle_Apple_SDK-Swift.h>
#elif defined(__has_include) && __has_include(<mParticle_Apple_SDK_NoLocation/mParticle.h>)
#import <mParticle_Apple_SDK_NoLocation/mParticle.h>
#import <mParticle_Apple_SDK_NoLocation/mParticle_Apple_SDK-Swift.h>
#else
#import "mParticle.h"
#import "mParticle_Apple_SDK-Swift.h"
#endif

@interface MPKitRokt : NSObject <MPKitProtocol>
Expand Down
95 changes: 59 additions & 36 deletions mParticle-Rokt/MPKitRokt.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#import "MPKitRokt.h"
#import <Rokt_Widget/Rokt_Widget-Swift.h>

NSString * const kMPRemoteConfigKitHashesKey = @"hs";
NSString * const kMPRoktRemoteConfigKitHashesKey = @"hs";
NSString * const kMPRemoteConfigUserAttributeFilter = @"ua";
NSString * const MPKitRoktErrorDomain = @"com.mparticle.kits.rokt";
NSString * const MPKitRoktErrorMessageKey = @"mParticle-Rokt Error";
NSString * const kMPPlacementAttributesMapping = @"placementAttributesMapping";
NSString * const kMPHashedEmailUserIdentityType = @"hashedEmailUserIdentityType";
NSString * const kMPRoktPlacementAttributesMapping = @"placementAttributesMapping";
NSString * const kMPRoktHashedEmailUserIdentityType = @"hashedEmailUserIdentityType";
NSString * const kMPRoktEmbeddedViewClassName = @"MPRoktEmbeddedView";
NSInteger const kMPRoktKitCode = 181;

Expand Down Expand Up @@ -55,17 +55,24 @@ - (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configu

// Initialize Rokt SDK here
[MPKitRokt MPLog:[NSString stringWithFormat:@"Attempting to initialize Rokt with Kit Version: %@", kitVersion]];
[Rokt initWithRoktTagId:partnerId mParticleSdkVersion:sdkVersion mParticleKitVersion:kitVersion onInitComplete:^(BOOL InitComplete) {
if (InitComplete) {
[self start];
[MPKitRokt MPLog:@"Rokt Init Complete"];
NSDictionary *userInfo = @{mParticleKitInstanceKey:[[self class] kitCode]};
[[NSNotificationCenter defaultCenter] postNotificationName:@"mParticle.Rokt.Initialized"
object:nil
userInfo:userInfo];

// Subscribe to global events to receive InitComplete
[Rokt globalEventsOnEvent:^(RoktEvent * _Nonnull event) {
if ([event isKindOfClass:[InitComplete class]]) {
InitComplete *initComplete = (InitComplete *)event;
if (initComplete.success) {
[self start];
[MPKitRokt MPLog:@"Rokt Init Complete"];
NSDictionary *userInfo = @{mParticleKitInstanceKey:[[self class] kitCode]};
[[NSNotificationCenter defaultCenter] postNotificationName:@"mParticle.Rokt.Initialized"
object:nil
userInfo:userInfo];
}
}
}];

[Rokt initWithRoktTagId:partnerId mParticleSdkVersion:sdkVersion mParticleKitVersion:kitVersion];

return [self execStatus:MPKitReturnCodeSuccess];
}

Expand All @@ -91,33 +98,35 @@ - (void)start {
///
/// \param embeddedViews A dictionary of RoktEmbeddedViews with their names
///
/// \param callbacks Object that contains all possible callbacks for selectPlacements
/// \param onEvent Callback block that receives RoktEvent objects for all placement events
///
/// \param filteredUser The current user when this placement was requested. Filtered for the kit as per settings in the mParticle UI
///
- (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier
attributes:(NSDictionary<NSString *, NSString *> * _Nonnull)attributes
embeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews
config:(MPRoktConfig * _Nullable)mpRoktConfig
callbacks:(MPRoktEventCallback * _Nullable)callbacks
onEvent:(void (^ _Nullable)(MPRoktEvent * _Nonnull))onEvent
filteredUser:(FilteredMParticleUser * _Nonnull)filteredUser {
[MPKitRokt MPLog:[NSString stringWithFormat:@"Rokt Kit recieved `executeWithIdentifier` method with the following arguments: \n identifier: %@ \n attributes: %@ \n embeddedViews: %@ \n config: %@ \n callbacks: %@ \n filteredUser identities: %@", identifier, attributes, embeddedViews, mpRoktConfig, callbacks, filteredUser.userIdentities]];
[MPKitRokt MPLog:[NSString stringWithFormat:@"Rokt Kit recieved `executeWithIdentifier` method with the following arguments: \n identifier: %@ \n attributes: %@ \n embeddedViews: %@ \n config: %@ \n onEvent: %@ \n filteredUser identities: %@", identifier, attributes, embeddedViews, mpRoktConfig, onEvent, filteredUser.userIdentities]];
NSDictionary<NSString *, NSString *> *finalAtt = [MPKitRokt prepareAttributes:attributes filteredUser:filteredUser performMapping:NO];

//Convert MPRoktConfig to RoktConfig
RoktConfig *roktConfig = [MPKitRokt convertMPRoktConfig:mpRoktConfig];
NSDictionary<NSString *, RoktEmbeddedView *> *confirmedViews = [self confirmEmbeddedViews:embeddedViews];

[Rokt executeWithViewName:identifier
attributes:finalAtt
placements:confirmedViews
config:roktConfig
onLoad:callbacks.onLoad
onUnLoad:callbacks.onUnLoad
onShouldShowLoadingIndicator:callbacks.onShouldShowLoadingIndicator
onShouldHideLoadingIndicator:callbacks.onShouldHideLoadingIndicator
onEmbeddedSizeChange:callbacks.onEmbeddedSizeChange
];
[Rokt selectPlacementsWithIdentifier:identifier
attributes:finalAtt
placements:confirmedViews
config:roktConfig
onEvent:^(RoktEvent * _Nonnull event) {
if (onEvent) {
MPRoktEvent *mpEvent = [MPKitRokt mapEvent:event];
if (mpEvent) {
onEvent(mpEvent);
}
}
}];

return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
}
Expand Down Expand Up @@ -254,7 +263,7 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
transformedDictionary[key] = [numberAttribute stringValue];
}
} else if ([obj isKindOfClass:[NSDate class]]) {
transformedDictionary[key] = [MPDateFormatter stringFromDateRFC3339:obj];
transformedDictionary[key] = [MPKitAPI stringFromDateRFC3339:obj];
} else if ([obj isKindOfClass:[NSData class]] && [(NSData *)obj length] > 0) {
transformedDictionary[key] = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
} else if ([obj isKindOfClass:[NSDictionary class]]) {
Expand Down Expand Up @@ -295,8 +304,8 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
NSData *dataAttributeMap;
// Rokt Kit is available though there may not be an attribute map
attributeMap = @[];
if (roktKitConfig[kMPPlacementAttributesMapping] != [NSNull null]) {
strAttributeMap = [roktKitConfig[kMPPlacementAttributesMapping] stringByRemovingPercentEncoding];
if (roktKitConfig[kMPRoktPlacementAttributesMapping] != [NSNull null]) {
strAttributeMap = [roktKitConfig[kMPRoktPlacementAttributesMapping] stringByRemovingPercentEncoding];
dataAttributeMap = [strAttributeMap dataUsingEncoding:NSUTF8StringEncoding];
}

Expand Down Expand Up @@ -475,25 +484,32 @@ + (NSNumber *)getRoktHashedEmailUserIdentityType {
NSDictionary *roktKitConfig = [MPKitRokt getKitConfig];

// Get the string representing which identity to use and convert it to the key (NSNumber)
NSString *hashedIdentityTypeString = roktKitConfig[kMPHashedEmailUserIdentityType];
NSString *hashedIdentityTypeString = roktKitConfig[kMPRoktHashedEmailUserIdentityType];
NSNumber *hashedIdentityTypeNumber = [MPKitRokt identityTypeForString:hashedIdentityTypeString.lowercaseString];

return hashedIdentityTypeNumber;
}

- (MPKitExecStatus *)purchaseFinalized:(NSString *)placementId catalogItemId:(NSString *)catalogItemId success:(NSNumber *)success {
if (placementId != nil && catalogItemId != nil && success != nil) {
if (@available(iOS 15.0, *)) {
[Rokt purchaseFinalizedWithPlacementId:placementId catalogItemId:catalogItemId success:success.boolValue];
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
}
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeUnavailable];
- (MPKitExecStatus *)purchaseFinalized:(NSString *)identifier catalogItemId:(NSString *)catalogItemId success:(NSNumber *)success {
if (identifier != nil && catalogItemId != nil && success != nil) {
[Rokt purchaseFinalizedWithIdentifier:identifier catalogItemId:catalogItemId success:success.boolValue];
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
}
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeFail];
}

- (MPKitExecStatus *)events:(NSString *)identifier onEvent:(void (^)(MPRoktEvent * _Nonnull))onEvent {
[Rokt eventsWithViewName:identifier onEvent:^(RoktEvent * _Nonnull event) {
[Rokt eventsWithIdentifier:identifier onEvent:^(RoktEvent * _Nonnull event) {
MPRoktEvent *mpEvent = [MPKitRokt mapEvent:event];
if (mpEvent) {
onEvent(mpEvent);
}
}];
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
}

- (MPKitExecStatus *)globalEvents:(void (^)(MPRoktEvent * _Nonnull))onEvent {
[Rokt globalEventsOnEvent:^(RoktEvent * _Nonnull event) {
MPRoktEvent *mpEvent = [MPKitRokt mapEvent:event];
if (mpEvent) {
onEvent(mpEvent);
Expand Down Expand Up @@ -863,6 +879,13 @@ + (MPRoktEvent * _Nullable)mapEvent:(RoktEvent *)event {
return [[MPRoktFirstPositiveEngagement alloc] initWithPlacementId:firstPositiveEngagement.placementId];
}

// Check for RoktEvent.EmbeddedSizeChanged
if ([event isKindOfClass:[EmbeddedSizeChanged class]]) {
EmbeddedSizeChanged *embeddedSizeChanged = (EmbeddedSizeChanged *)event;
return [[MPRoktEmbeddedSizeChanged alloc] initWithPlacementId:embeddedSizeChanged.placementId
updatedHeight:embeddedSizeChanged.updatedHeight];
}

// Check for RoktEvent.CartItemInstantPurchase
if ([event isKindOfClass:[CartItemInstantPurchase class]]) {
CartItemInstantPurchase *cartItemInstantPurchase = (CartItemInstantPurchase *)event;
Expand Down
Loading
Loading