Skip to content

Commit 73d0eaf

Browse files
thomson-tjamesnroktBrandonStalnaker
authored
feat: SQDSDKS-7423 - Add event mapping functionality and new MPRoktEventMapper class (#16)
* feat: SQDSDKS-7423 - Add event mapping functionality and new MPRoktEventMapper class - Introduced MPRoktEventMapper class for mapping Rokt events to mParticle events. - Added methods in MPKitRokt for handling events with identifiers and global events. - Updated podspec to include Swift source files and public header files. --------- Co-authored-by: James Newman <james.newman@rokt.com> Co-authored-by: Brandon Stalnaker <brandon.stalnaker@rokt.com>
1 parent f7bfb7c commit 73d0eaf

6 files changed

Lines changed: 237 additions & 29 deletions

File tree

mParticle-Rokt.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Pod::Spec.new do |s|
1515
s.swift_version = '5.3'
1616

1717
s.ios.deployment_target = "12.0"
18-
s.ios.source_files = 'mParticle-Rokt/*.{h,m}'
18+
s.ios.source_files = 'mParticle-Rokt/*.{h,m,swift}'
19+
s.ios.public_header_files = 'mParticle-Rokt/*.h'
1920
s.ios.dependency 'mParticle-Apple-SDK', '~> 8.0'
2021
s.ios.dependency 'Rokt-Widget', '~> 4.10'
2122
end

mParticle-Rokt.xcodeproj/project.pbxproj

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
/* Begin PBXBuildFile section */
1010
2502325C2D7A7BF3004794A2 /* Rokt-Widget in Frameworks */ = {isa = PBXBuildFile; productRef = 2502325B2D7A7BF3004794A2 /* Rokt-Widget */; };
11-
536803952B7BAE11000A10BE /* mParticle-Apple-SDK in Frameworks */ = {isa = PBXBuildFile; productRef = 536803942B7BAE11000A10BE /* mParticle-Apple-SDK */; };
12-
7E15B2092D9AE82000C1FF3E /* mParticle-Apple-SDK in Frameworks */ = {isa = PBXBuildFile; productRef = 7E15B2082D9AE82000C1FF3E /* mParticle-Apple-SDK */; };
1311
7E15B20B2D9AE82600C1FF3E /* Rokt-Widget in Frameworks */ = {isa = PBXBuildFile; productRef = 7E15B20A2D9AE82600C1FF3E /* Rokt-Widget */; };
12+
7EDDAAB02E05A88E00D089CF /* mParticle-Apple-SDK in Frameworks */ = {isa = PBXBuildFile; productRef = 7EDDAAAF2E05A88E00D089CF /* mParticle-Apple-SDK */; };
13+
7EDDAAB22E05A89B00D089CF /* mParticle-Apple-SDK in Frameworks */ = {isa = PBXBuildFile; productRef = 7EDDAAB12E05A89B00D089CF /* mParticle-Apple-SDK */; };
1414
7EE7F13E2DA95BEE006C5440 /* OCMock in Frameworks */ = {isa = PBXBuildFile; productRef = 7EE7F13D2DA95BEE006C5440 /* OCMock */; };
15+
B34CE55A2E04356F00712DE1 /* MPRoktEventMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D778512E02845700D887A4 /* MPRoktEventMapper.swift */; };
16+
B3D778532E02845700D887A4 /* MPRoktEventMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D778512E02845700D887A4 /* MPRoktEventMapper.swift */; };
1517
DBB01A601DC1478A00A7B188 /* mParticle_Rokt.h in Headers */ = {isa = PBXBuildFile; fileRef = DBB01A5E1DC1478A00A7B188 /* mParticle_Rokt.h */; settings = {ATTRIBUTES = (Public, ); }; };
1618
DBB01A681DC1480700A7B188 /* MPKitRokt.h in Headers */ = {isa = PBXBuildFile; fileRef = DBB01A661DC1480700A7B188 /* MPKitRokt.h */; };
1719
DBB01A691DC1480700A7B188 /* MPKitRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = DBB01A671DC1480700A7B188 /* MPKitRokt.m */; };
@@ -30,6 +32,7 @@
3032
/* End PBXContainerItemProxy section */
3133

3234
/* Begin PBXFileReference section */
35+
B3D778512E02845700D887A4 /* MPRoktEventMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPRoktEventMapper.swift; sourceTree = "<group>"; };
3336
DBB01A5B1DC1478A00A7B188 /* mParticle_Rokt.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = mParticle_Rokt.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3437
DBB01A5E1DC1478A00A7B188 /* mParticle_Rokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_Rokt.h; sourceTree = "<group>"; };
3538
DBB01A5F1DC1478A00A7B188 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -45,18 +48,18 @@
4548
isa = PBXFrameworksBuildPhase;
4649
buildActionMask = 2147483647;
4750
files = (
51+
7EDDAAB02E05A88E00D089CF /* mParticle-Apple-SDK in Frameworks */,
4852
2502325C2D7A7BF3004794A2 /* Rokt-Widget in Frameworks */,
49-
536803952B7BAE11000A10BE /* mParticle-Apple-SDK in Frameworks */,
5053
);
5154
runOnlyForDeploymentPostprocessing = 0;
5255
};
5356
FF0BB638217A84E800B0556C /* Frameworks */ = {
5457
isa = PBXFrameworksBuildPhase;
5558
buildActionMask = 2147483647;
5659
files = (
57-
7E15B2092D9AE82000C1FF3E /* mParticle-Apple-SDK in Frameworks */,
5860
FF0BB640217A84E800B0556C /* mParticle_Rokt.framework in Frameworks */,
5961
7EE7F13E2DA95BEE006C5440 /* OCMock in Frameworks */,
62+
7EDDAAB22E05A89B00D089CF /* mParticle-Apple-SDK in Frameworks */,
6063
7E15B20B2D9AE82600C1FF3E /* Rokt-Widget in Frameworks */,
6164
);
6265
runOnlyForDeploymentPostprocessing = 0;
@@ -86,6 +89,7 @@
8689
DBB01A5D1DC1478A00A7B188 /* mParticle-Rokt */ = {
8790
isa = PBXGroup;
8891
children = (
92+
B3D778512E02845700D887A4 /* MPRoktEventMapper.swift */,
8993
DBB01A661DC1480700A7B188 /* MPKitRokt.h */,
9094
DBB01A671DC1480700A7B188 /* MPKitRokt.m */,
9195
DBB01A5E1DC1478A00A7B188 /* mParticle_Rokt.h */,
@@ -140,8 +144,8 @@
140144
);
141145
name = "mParticle-Rokt";
142146
packageProductDependencies = (
143-
536803942B7BAE11000A10BE /* mParticle-Apple-SDK */,
144147
2502325B2D7A7BF3004794A2 /* Rokt-Widget */,
148+
7EDDAAAF2E05A88E00D089CF /* mParticle-Apple-SDK */,
145149
);
146150
productName = "mParticle-Rokt";
147151
productReference = DBB01A5B1DC1478A00A7B188 /* mParticle_Rokt.framework */;
@@ -176,10 +180,12 @@
176180
TargetAttributes = {
177181
DBB01A5A1DC1478A00A7B188 = {
178182
CreatedOnToolsVersion = 8.0;
183+
LastSwiftMigration = 1640;
179184
ProvisioningStyle = Automatic;
180185
};
181186
FF0BB63A217A84E800B0556C = {
182187
CreatedOnToolsVersion = 10.0;
188+
LastSwiftMigration = 1640;
183189
ProvisioningStyle = Automatic;
184190
};
185191
};
@@ -194,9 +200,9 @@
194200
);
195201
mainGroup = DBB01A511DC1478A00A7B188;
196202
packageReferences = (
197-
536803932B7BAE11000A10BE /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */,
198203
2502325A2D7A7BF3004794A2 /* XCRemoteSwiftPackageReference "rokt-sdk-ios" */,
199204
7EE7F13C2DA95BEE006C5440 /* XCRemoteSwiftPackageReference "ocmock" */,
205+
7EDDAAAE2E05A88E00D089CF /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */,
200206
);
201207
productRefGroup = DBB01A5C1DC1478A00A7B188 /* Products */;
202208
projectDirPath = "";
@@ -230,6 +236,7 @@
230236
isa = PBXSourcesBuildPhase;
231237
buildActionMask = 2147483647;
232238
files = (
239+
B34CE55A2E04356F00712DE1 /* MPRoktEventMapper.swift in Sources */,
233240
DBB01A691DC1480700A7B188 /* MPKitRokt.m in Sources */,
234241
);
235242
runOnlyForDeploymentPostprocessing = 0;
@@ -238,6 +245,7 @@
238245
isa = PBXSourcesBuildPhase;
239246
buildActionMask = 2147483647;
240247
files = (
248+
B3D778532E02845700D887A4 /* MPRoktEventMapper.swift in Sources */,
241249
FF0BB63E217A84E800B0556C /* mParticle_RoktTests.m in Sources */,
242250
);
243251
runOnlyForDeploymentPostprocessing = 0;
@@ -278,6 +286,7 @@
278286
COPY_PHASE_STRIP = NO;
279287
CURRENT_PROJECT_VERSION = 1;
280288
DEBUG_INFORMATION_FORMAT = dwarf;
289+
DEFINES_MODULE = YES;
281290
ENABLE_STRICT_OBJC_MSGSEND = YES;
282291
ENABLE_TESTABILITY = YES;
283292
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -329,6 +338,7 @@
329338
COPY_PHASE_STRIP = NO;
330339
CURRENT_PROJECT_VERSION = 1;
331340
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
341+
DEFINES_MODULE = YES;
332342
ENABLE_NS_ASSERTIONS = NO;
333343
ENABLE_STRICT_OBJC_MSGSEND = YES;
334344
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -352,6 +362,7 @@
352362
DBB01A641DC1478A00A7B188 /* Debug */ = {
353363
isa = XCBuildConfiguration;
354364
buildSettings = {
365+
CLANG_ENABLE_MODULES = YES;
355366
CODE_SIGN_IDENTITY = "";
356367
DEFINES_MODULE = YES;
357368
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -371,12 +382,15 @@
371382
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-Rokt";
372383
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
373384
SKIP_INSTALL = YES;
385+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
386+
SWIFT_VERSION = 6.0;
374387
};
375388
name = Debug;
376389
};
377390
DBB01A651DC1478A00A7B188 /* Release */ = {
378391
isa = XCBuildConfiguration;
379392
buildSettings = {
393+
CLANG_ENABLE_MODULES = YES;
380394
CODE_SIGN_IDENTITY = "";
381395
DEFINES_MODULE = YES;
382396
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -396,6 +410,7 @@
396410
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-Rokt";
397411
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
398412
SKIP_INSTALL = YES;
413+
SWIFT_VERSION = 6.0;
399414
};
400415
name = Release;
401416
};
@@ -404,6 +419,7 @@
404419
buildSettings = {
405420
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
406421
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
422+
CLANG_ENABLE_MODULES = YES;
407423
CLANG_ENABLE_OBJC_WEAK = YES;
408424
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
409425
CLANG_WARN_COMMA = YES;
@@ -433,6 +449,8 @@
433449
MTL_FAST_MATH = YES;
434450
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-RoktTests";
435451
PRODUCT_NAME = "$(TARGET_NAME)";
452+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
453+
SWIFT_VERSION = 6.0;
436454
TARGETED_DEVICE_FAMILY = "1,2";
437455
};
438456
name = Debug;
@@ -442,6 +460,7 @@
442460
buildSettings = {
443461
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
444462
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
463+
CLANG_ENABLE_MODULES = YES;
445464
CLANG_ENABLE_OBJC_WEAK = YES;
446465
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
447466
CLANG_WARN_COMMA = YES;
@@ -470,6 +489,7 @@
470489
MTL_FAST_MATH = YES;
471490
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-RoktTests";
472491
PRODUCT_NAME = "$(TARGET_NAME)";
492+
SWIFT_VERSION = 6.0;
473493
TARGETED_DEVICE_FAMILY = "1,2";
474494
};
475495
name = Release;
@@ -515,9 +535,9 @@
515535
minimumVersion = 4.8.1;
516536
};
517537
};
518-
536803932B7BAE11000A10BE /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */ = {
538+
7EDDAAAE2E05A88E00D089CF /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */ = {
519539
isa = XCRemoteSwiftPackageReference;
520-
repositoryURL = "https://github.com/mParticle/mparticle-apple-sdk";
540+
repositoryURL = "https://github.com/mParticle/mparticle-apple-sdk.git";
521541
requirement = {
522542
kind = upToNextMajorVersion;
523543
minimumVersion = 8.4.0;
@@ -539,20 +559,20 @@
539559
package = 2502325A2D7A7BF3004794A2 /* XCRemoteSwiftPackageReference "rokt-sdk-ios" */;
540560
productName = "Rokt-Widget";
541561
};
542-
536803942B7BAE11000A10BE /* mParticle-Apple-SDK */ = {
562+
7E15B20A2D9AE82600C1FF3E /* Rokt-Widget */ = {
543563
isa = XCSwiftPackageProductDependency;
544-
package = 536803932B7BAE11000A10BE /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */;
545-
productName = "mParticle-Apple-SDK";
564+
package = 2502325A2D7A7BF3004794A2 /* XCRemoteSwiftPackageReference "rokt-sdk-ios" */;
565+
productName = "Rokt-Widget";
546566
};
547-
7E15B2082D9AE82000C1FF3E /* mParticle-Apple-SDK */ = {
567+
7EDDAAAF2E05A88E00D089CF /* mParticle-Apple-SDK */ = {
548568
isa = XCSwiftPackageProductDependency;
549-
package = 536803932B7BAE11000A10BE /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */;
569+
package = 7EDDAAAE2E05A88E00D089CF /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */;
550570
productName = "mParticle-Apple-SDK";
551571
};
552-
7E15B20A2D9AE82600C1FF3E /* Rokt-Widget */ = {
572+
7EDDAAB12E05A89B00D089CF /* mParticle-Apple-SDK */ = {
553573
isa = XCSwiftPackageProductDependency;
554-
package = 2502325A2D7A7BF3004794A2 /* XCRemoteSwiftPackageReference "rokt-sdk-ios" */;
555-
productName = "Rokt-Widget";
574+
package = 7EDDAAAE2E05A88E00D089CF /* XCRemoteSwiftPackageReference "mparticle-apple-sdk" */;
575+
productName = "mParticle-Apple-SDK";
556576
};
557577
7EE7F13D2DA95BEE006C5440 /* OCMock */ = {
558578
isa = XCSwiftPackageProductDependency;

mParticle-Rokt/MPKitRokt.m

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "MPKitRokt.h"
22
#import <Rokt_Widget/Rokt_Widget-Swift.h>
3+
#import <mParticle_Rokt/mParticle_Rokt-Swift.h>
34

45
NSString * const kMPRemoteConfigKitHashesKey = @"hs";
56
NSString * const kMPRemoteConfigUserAttributeFilter = @"ua";
@@ -153,10 +154,10 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
153154

154155
- (NSDictionary<NSString *, RoktEmbeddedView *> * _Nullable) confirmEmbeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews {
155156
NSMutableDictionary <NSString *, RoktEmbeddedView *> *safePlacements = [NSMutableDictionary dictionary];
156-
157+
157158
for (NSString* key in embeddedViews) {
158159
MPRoktEmbeddedView *mpView = [embeddedViews objectForKey:key];
159-
160+
160161
if ([mpView isKindOfClass:MPRoktEmbeddedView.class]) {
161162
// Create a new RoktEmbeddedView instance
162163
RoktEmbeddedView *roktView = [[RoktEmbeddedView alloc] initWithFrame:mpView.bounds];
@@ -166,7 +167,7 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
166167
[safePlacements setObject:roktView forKey:key];
167168
}
168169
}
169-
170+
170171
return safePlacements;
171172
}
172173

@@ -296,6 +297,16 @@ - (MPKitExecStatus *)purchaseFinalized:(NSString *)placementId catalogItemId:(NS
296297
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeFail];
297298
}
298299

300+
- (MPKitExecStatus *)events:(NSString *)identifier onEvent:(void (^)(MPRoktEvent * _Nonnull))onEvent {
301+
[Rokt eventsWithViewName:identifier onEvent:^(RoktEvent * _Nonnull event) {
302+
MPRoktEvent *mpEvent = [MPRoktEventMapper mapEvent:event];
303+
if (mpEvent) {
304+
onEvent(mpEvent);
305+
}
306+
}];
307+
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
308+
}
309+
299310
#pragma mark - User attributes and identities
300311

301312
- (MPKitExecStatus *)setUserIdentity:(NSString *)identityString identityType:(MPUserIdentity)identityType {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import Foundation
2+
import mParticle_Apple_SDK
3+
import Rokt_Widget
4+
5+
/// Utility class for mapping Rokt events to mParticle events
6+
@objc(MPRoktEventMapper)
7+
@objcMembers
8+
public class MPRoktEventMapper: NSObject {
9+
10+
/// Maps a RoktEvent to the corresponding MPRoktEvent
11+
/// - Parameter event: The RoktEvent to map
12+
/// - Returns: The mapped MPRoktEvent, or nil if mapping fails
13+
@objc(mapEvent:)
14+
public static func mapEvent(_ event: RoktEvent) -> MPRoktEvent? {
15+
switch event {
16+
case let initComplete as RoktEvent.InitComplete:
17+
return MPRoktEvent.MPRoktInitComplete(success: initComplete.success)
18+
19+
case is RoktEvent.ShowLoadingIndicator:
20+
return MPRoktEvent.MPRoktShowLoadingIndicator()
21+
22+
case is RoktEvent.HideLoadingIndicator:
23+
return MPRoktEvent.MPRoktHideLoadingIndicator()
24+
25+
case let placementInteractive as RoktEvent.PlacementInteractive:
26+
return MPRoktEvent.MPRoktPlacementInteractive(placementId: placementInteractive.placementId)
27+
28+
case let placementReady as RoktEvent.PlacementReady:
29+
return MPRoktEvent.MPRoktPlacementReady(placementId: placementReady.placementId)
30+
31+
case let offerEngagement as RoktEvent.OfferEngagement:
32+
return MPRoktEvent.MPRoktOfferEngagement(placementId: offerEngagement.placementId)
33+
34+
case let openUrl as RoktEvent.OpenUrl:
35+
return MPRoktEvent.MPRoktOpenUrl(placementId: openUrl.placementId, url: openUrl.url)
36+
37+
case let positiveEngagement as RoktEvent.PositiveEngagement:
38+
return MPRoktEvent.MPRoktPositiveEngagement(placementId: positiveEngagement.placementId)
39+
40+
case let placementClosed as RoktEvent.PlacementClosed:
41+
return MPRoktEvent.MPRoktPlacementClosed(placementId: placementClosed.placementId)
42+
43+
case let placementCompleted as RoktEvent.PlacementCompleted:
44+
return MPRoktEvent.MPRoktPlacementCompleted(placementId: placementCompleted.placementId)
45+
46+
case let placementFailure as RoktEvent.PlacementFailure:
47+
return MPRoktEvent.MPRoktPlacementFailure(placementId: placementFailure.placementId)
48+
49+
case let firstPositiveEngagement as RoktEvent.FirstPositiveEngagement:
50+
return MPRoktEvent.MPRoktFirstPositiveEngagement(
51+
placementId: firstPositiveEngagement.placementId
52+
)
53+
54+
case let cartItemInstantPurchase as RoktEvent.CartItemInstantPurchase:
55+
return MPRoktEvent.MPRoktCartItemInstantPurchase(
56+
placementId: cartItemInstantPurchase.placementId,
57+
name: cartItemInstantPurchase.name ?? "",
58+
cartItemId: cartItemInstantPurchase.cartItemId,
59+
catalogItemId: cartItemInstantPurchase.catalogItemId,
60+
currency: cartItemInstantPurchase.currency,
61+
description: cartItemInstantPurchase.description,
62+
linkedProductId: cartItemInstantPurchase.linkedProductId,
63+
providerData: cartItemInstantPurchase.providerData,
64+
quantity: cartItemInstantPurchase.quantity,
65+
totalPrice: cartItemInstantPurchase.totalPrice,
66+
unitPrice: cartItemInstantPurchase.unitPrice
67+
)
68+
69+
default:
70+
return nil
71+
}
72+
}
73+
}

mParticle-Rokt/mParticle_Rokt.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22

33
FOUNDATION_EXPORT double mParticle_RoktVersionNumber;
44
FOUNDATION_EXPORT const unsigned char mParticle_RoktVersionString[];
5-
6-
#if defined(__has_include) && __has_include(<mParticle_Appboy/MPKitAppboy.h>)
7-
#import <mParticle_Rokt/MPKitRokt.h>
8-
#else
9-
#import "MPKitRokt.h"
10-
#endif

0 commit comments

Comments
 (0)