Skip to content

Commit 2a6e164

Browse files
committed
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.
1 parent f7bfb7c commit 2a6e164

5 files changed

Lines changed: 129 additions & 2 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: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 54;
6+
objectVersion = 60;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -12,6 +12,8 @@
1212
7E15B2092D9AE82000C1FF3E /* mParticle-Apple-SDK in Frameworks */ = {isa = PBXBuildFile; productRef = 7E15B2082D9AE82000C1FF3E /* mParticle-Apple-SDK */; };
1313
7E15B20B2D9AE82600C1FF3E /* Rokt-Widget in Frameworks */ = {isa = PBXBuildFile; productRef = 7E15B20A2D9AE82600C1FF3E /* Rokt-Widget */; };
1414
7EE7F13E2DA95BEE006C5440 /* OCMock in Frameworks */ = {isa = PBXBuildFile; productRef = 7EE7F13D2DA95BEE006C5440 /* OCMock */; };
15+
B3D778532E02845700D887A4 /* MPRoktEventMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D778512E02845700D887A4 /* MPRoktEventMapper.swift */; };
16+
B3D778582E028ACD00D887A4 /* MPRoktEventMapper.h in Headers */ = {isa = PBXBuildFile; fileRef = B3D778572E028ACD00D887A4 /* MPRoktEventMapper.h */; };
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,8 @@
3032
/* End PBXContainerItemProxy section */
3133

3234
/* Begin PBXFileReference section */
35+
B3D778512E02845700D887A4 /* MPRoktEventMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPRoktEventMapper.swift; sourceTree = "<group>"; };
36+
B3D778572E028ACD00D887A4 /* MPRoktEventMapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPRoktEventMapper.h; sourceTree = "<group>"; };
3337
DBB01A5B1DC1478A00A7B188 /* mParticle_Rokt.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = mParticle_Rokt.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3438
DBB01A5E1DC1478A00A7B188 /* mParticle_Rokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_Rokt.h; sourceTree = "<group>"; };
3539
DBB01A5F1DC1478A00A7B188 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -86,6 +90,8 @@
8690
DBB01A5D1DC1478A00A7B188 /* mParticle-Rokt */ = {
8791
isa = PBXGroup;
8892
children = (
93+
B3D778572E028ACD00D887A4 /* MPRoktEventMapper.h */,
94+
B3D778512E02845700D887A4 /* MPRoktEventMapper.swift */,
8995
DBB01A661DC1480700A7B188 /* MPKitRokt.h */,
9096
DBB01A671DC1480700A7B188 /* MPKitRokt.m */,
9197
DBB01A5E1DC1478A00A7B188 /* mParticle_Rokt.h */,
@@ -117,6 +123,7 @@
117123
isa = PBXHeadersBuildPhase;
118124
buildActionMask = 2147483647;
119125
files = (
126+
B3D778582E028ACD00D887A4 /* MPRoktEventMapper.h in Headers */,
120127
DBB01A601DC1478A00A7B188 /* mParticle_Rokt.h in Headers */,
121128
DBB01A681DC1480700A7B188 /* MPKitRokt.h in Headers */,
122129
);
@@ -176,10 +183,12 @@
176183
TargetAttributes = {
177184
DBB01A5A1DC1478A00A7B188 = {
178185
CreatedOnToolsVersion = 8.0;
186+
LastSwiftMigration = 1640;
179187
ProvisioningStyle = Automatic;
180188
};
181189
FF0BB63A217A84E800B0556C = {
182190
CreatedOnToolsVersion = 10.0;
191+
LastSwiftMigration = 1640;
183192
ProvisioningStyle = Automatic;
184193
};
185194
};
@@ -230,6 +239,7 @@
230239
isa = PBXSourcesBuildPhase;
231240
buildActionMask = 2147483647;
232241
files = (
242+
B3D778522E02845700D887A4 /* MPRoktEventMapper.swift in Sources */,
233243
DBB01A691DC1480700A7B188 /* MPKitRokt.m in Sources */,
234244
);
235245
runOnlyForDeploymentPostprocessing = 0;
@@ -238,6 +248,7 @@
238248
isa = PBXSourcesBuildPhase;
239249
buildActionMask = 2147483647;
240250
files = (
251+
B3D778532E02845700D887A4 /* MPRoktEventMapper.swift in Sources */,
241252
FF0BB63E217A84E800B0556C /* mParticle_RoktTests.m in Sources */,
242253
);
243254
runOnlyForDeploymentPostprocessing = 0;
@@ -352,6 +363,7 @@
352363
DBB01A641DC1478A00A7B188 /* Debug */ = {
353364
isa = XCBuildConfiguration;
354365
buildSettings = {
366+
CLANG_ENABLE_MODULES = YES;
355367
CODE_SIGN_IDENTITY = "";
356368
DEFINES_MODULE = YES;
357369
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -371,12 +383,15 @@
371383
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-Rokt";
372384
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
373385
SKIP_INSTALL = YES;
386+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
387+
SWIFT_VERSION = 6.0;
374388
};
375389
name = Debug;
376390
};
377391
DBB01A651DC1478A00A7B188 /* Release */ = {
378392
isa = XCBuildConfiguration;
379393
buildSettings = {
394+
CLANG_ENABLE_MODULES = YES;
380395
CODE_SIGN_IDENTITY = "";
381396
DEFINES_MODULE = YES;
382397
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -396,6 +411,7 @@
396411
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-Rokt";
397412
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
398413
SKIP_INSTALL = YES;
414+
SWIFT_VERSION = 6.0;
399415
};
400416
name = Release;
401417
};
@@ -404,6 +420,7 @@
404420
buildSettings = {
405421
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
406422
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
423+
CLANG_ENABLE_MODULES = YES;
407424
CLANG_ENABLE_OBJC_WEAK = YES;
408425
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
409426
CLANG_WARN_COMMA = YES;
@@ -433,6 +450,8 @@
433450
MTL_FAST_MATH = YES;
434451
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-RoktTests";
435452
PRODUCT_NAME = "$(TARGET_NAME)";
453+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
454+
SWIFT_VERSION = 6.0;
436455
TARGETED_DEVICE_FAMILY = "1,2";
437456
};
438457
name = Debug;
@@ -442,6 +461,7 @@
442461
buildSettings = {
443462
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
444463
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
464+
CLANG_ENABLE_MODULES = YES;
445465
CLANG_ENABLE_OBJC_WEAK = YES;
446466
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
447467
CLANG_WARN_COMMA = YES;
@@ -470,6 +490,7 @@
470490
MTL_FAST_MATH = YES;
471491
PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-RoktTests";
472492
PRODUCT_NAME = "$(TARGET_NAME)";
493+
SWIFT_VERSION = 6.0;
473494
TARGETED_DEVICE_FAMILY = "1,2";
474495
};
475496
name = Release;

mParticle-Rokt/MPKitRokt.m

Lines changed: 21 additions & 0 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 "MPRoktEventMapper.h"
34

45
NSString * const kMPRemoteConfigKitHashesKey = @"hs";
56
NSString * const kMPRemoteConfigUserAttributeFilter = @"ua";
@@ -296,6 +297,26 @@ - (MPKitExecStatus *)purchaseFinalized:(NSString *)placementId catalogItemId:(NS
296297
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeFail];
297298
}
298299

300+
- (MPKitExecStatus *)eventsWithIdentifier:(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+
310+
- (MPKitExecStatus *)globalEventsOnEvent:(void (^)(MPRoktEvent * _Nonnull))onEvent {
311+
[Rokt globalEventsOnEvent:^(RoktEvent * _Nonnull event) {
312+
MPRoktEvent *mpEvent = [MPRoktEventMapper mapEvent:event];
313+
if (mpEvent) {
314+
onEvent(mpEvent);
315+
}
316+
}];
317+
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
318+
}
319+
299320
#pragma mark - User attributes and identities
300321

301322
- (MPKitExecStatus *)setUserIdentity:(NSString *)identityString identityType:(MPUserIdentity)identityType {

mParticle-Rokt/MPRoktEventMapper.h

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

0 commit comments

Comments
 (0)