Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
.upToNextMajor(from: "8.0.0")),
.package(name: "Rokt-Widget",
url: "https://github.com/ROKT/rokt-sdk-ios",
.upToNextMajor(from: "4.16.0")),
.upToNextMajor(from: "4.16.1")),
],
targets: [
.target(
Expand Down
7 changes: 7 additions & 0 deletions mParticle-Rokt-Swift/MPRoktLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class MPRoktLayout {
config: RoktConfig? = nil,
onEvent: ((RoktEvent) -> Void)? = nil
) {
// Capture the timestamp when the SwiftUI component is rendered
let options = PlacementOptions(
jointSdkSelectPlacements: Int64(Date().timeIntervalSince1970 * 1000),
dynamicPerformanceMarkers: [:]
)

MPRoktLayout.mpLog("Initializing MPRoktLayout with arguments sdkTriggered:\(sdkTriggered.wrappedValue), viewName:\(viewName ?? "nil"), locationName:\(locationName), attributes:\(attributes)")
confirmUser(attributes: attributes) { identifyCalled in
let preparedAttributes = MPKitRokt.prepareAttributes(attributes, filteredUser: Optional<FilteredMParticleUser>.none, performMapping: true)
Expand All @@ -43,6 +49,7 @@ public class MPRoktLayout {
locationName: locationName,
attributes: preparedAttributes,
config: config,
placementOptions: options,
onEvent: onEvent
)
// The Binding variable provided by the client allows us to trigger a re-render of the UI but we only want to do this if the value was true to start
Expand Down
4 changes: 2 additions & 2 deletions mParticle-Rokt.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Pod::Spec.new do |s|
objc.source_files = 'mParticle-Rokt/*.{h,m}'
objc.public_header_files = 'mParticle-Rokt/*.h'
objc.dependency 'mParticle-Apple-SDK', '~> 8.0'
objc.dependency 'Rokt-Widget', '~> 4.15'
objc.dependency 'Rokt-Widget', '~> 4.16'
end

# Swift subspec
s.subspec 'Swift' do |swift|
swift.source_files = 'mParticle-Rokt-Swift/*.swift'
swift.dependency 'mParticle-Rokt/ObjC'
swift.dependency 'mParticle-Apple-SDK', '~> 8.0'
swift.dependency 'Rokt-Widget', '~> 4.15'
swift.dependency 'Rokt-Widget', '~> 4.16'
end

# Default includes both
Expand Down
2 changes: 2 additions & 0 deletions mParticle-Rokt/MPKitRokt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "mParticle_Apple_SDK-Swift.h"
#endif

@class MPRoktPlacementOptions;

@interface MPKitRokt : NSObject <MPKitProtocol>

@property (nonatomic, strong, nonnull) NSDictionary *configuration;
Expand Down
11 changes: 9 additions & 2 deletions mParticle-Rokt/MPKitRokt.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ - (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier
embeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews
config:(MPRoktConfig * _Nullable)mpRoktConfig
callbacks:(MPRoktEventCallback * _Nullable)callbacks
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]];
filteredUser:(FilteredMParticleUser * _Nonnull)filteredUser
options:(MPRoktPlacementOptions * _Nullable)options {
[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: %@ \n options: %@", identifier, attributes, embeddedViews, mpRoktConfig, callbacks, filteredUser.userIdentities, options]];
NSDictionary<NSString *, NSString *> *finalAtt = [MPKitRokt prepareAttributes:attributes filteredUser:filteredUser performMapping:NO];

// Log custom event for selectPlacements call
Expand All @@ -130,11 +131,17 @@ - (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier
//Convert MPRoktConfig to RoktConfig
RoktConfig *roktConfig = [MPKitRokt convertMPRoktConfig:mpRoktConfig];
NSDictionary<NSString *, RoktEmbeddedView *> *confirmedViews = [self confirmEmbeddedViews:embeddedViews];

PlacementOptions *placementOptions = [[PlacementOptions alloc] initWithJointSdkSelectPlacements:0 dynamicPerformanceMarkers:@{}];
if (options) {
placementOptions = [[PlacementOptions alloc] initWithJointSdkSelectPlacements:options.jointSdkSelectPlacements dynamicPerformanceMarkers:@{}];
Comment thread
thomson-t marked this conversation as resolved.
}

[Rokt executeWithViewName:identifier
attributes:finalAtt
placements:confirmedViews
config:roktConfig
placementOptions:placementOptions
onLoad:callbacks.onLoad
onUnLoad:callbacks.onUnLoad
onShouldShowLoadingIndicator:callbacks.onShouldShowLoadingIndicator
Expand Down
90 changes: 86 additions & 4 deletions mParticle_RoktTests/mParticle_RoktTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ - (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier
embeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews
config:(MPRoktConfig * _Nullable)mpRoktConfig
callbacks:(MPRoktEventCallback * _Nullable)callbacks
filteredUser:(FilteredMParticleUser * _Nonnull)filteredUser;
filteredUser:(FilteredMParticleUser * _Nonnull)filteredUser
options:(MPRoktPlacementOptions * _Nullable)options;
- (MPKitExecStatus *)setWrapperSdk:(MPWrapperSdk)wrapperSdk version:(nonnull NSString *)wrapperSdkVersion;

- (MPKitExecStatus *)purchaseFinalized:(NSString *)placementId
Expand Down Expand Up @@ -164,6 +165,7 @@ - (void)testExecuteWithIdentifier {
}]
placements:OCMOCK_ANY
config:nil
placementOptions:OCMOCK_ANY
onLoad:nil
onUnLoad:nil
onShouldShowLoadingIndicator:nil
Expand All @@ -175,7 +177,8 @@ - (void)testExecuteWithIdentifier {
embeddedViews:embeddedViews
config:nil
callbacks:nil
filteredUser:user];
filteredUser:user
options:nil];

// Verify
XCTAssertNotNil(status);
Expand All @@ -201,6 +204,7 @@ - (void)testExecuteSandboxDetection {
}]
placements:OCMOCK_ANY
config:nil
placementOptions:OCMOCK_ANY
onLoad:nil
onUnLoad:nil
onShouldShowLoadingIndicator:nil
Expand All @@ -212,7 +216,83 @@ - (void)testExecuteSandboxDetection {
embeddedViews:embeddedViews
config:nil
callbacks:nil
filteredUser:user];
filteredUser:user
options:nil];

// Verify
XCTAssertNotNil(status);
XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess);
OCMVerifyAll(mockRoktSDK);
}

- (void)testExecuteWithIdentifierWithOptions {
id mockRoktSDK = OCMClassMock([Rokt class]);

MPRoktEmbeddedView *view = [[MPRoktEmbeddedView alloc] init];
NSString *identifier = @"TestView";
NSDictionary *embeddedViews = @{@"placement1": view};
NSDictionary *attributes = @{@"attr1": @"value1", @"sandbox": @"false"};
FilteredMParticleUser *user = [[FilteredMParticleUser alloc] init];

// Create placement options with a custom timestamp value
MPRoktPlacementOptions *options = [[MPRoktPlacementOptions alloc] initWithTimestamp:42];

// Expect Rokt execute call and verify placementOptions carries the jointSdkSelectPlacements value
OCMExpect([mockRoktSDK executeWithViewName:identifier
attributes:OCMOCK_ANY
placements:OCMOCK_ANY
config:nil
placementOptions:[OCMArg checkWithBlock:^BOOL(PlacementOptions *opts) {
return opts != nil;
}]
onLoad:nil
onUnLoad:nil
onShouldShowLoadingIndicator:nil
onShouldHideLoadingIndicator:nil
onEmbeddedSizeChange:nil]);

MPKitExecStatus *status = [self.kitInstance executeWithIdentifier:identifier
attributes:attributes
embeddedViews:embeddedViews
config:nil
callbacks:nil
filteredUser:user
options:options];

// Verify
XCTAssertNotNil(status);
XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess);
OCMVerifyAll(mockRoktSDK);
}

- (void)testExecuteWithIdentifierNilOptionsCreatesDefaultPlacementOptions {
id mockRoktSDK = OCMClassMock([Rokt class]);

NSString *identifier = @"TestView";
NSDictionary *attributes = @{@"attr1": @"value1", @"sandbox": @"false"};
FilteredMParticleUser *user = [[FilteredMParticleUser alloc] init];

// When options is nil, a default PlacementOptions with jointSdkSelectPlacements=0 should be created
OCMExpect([mockRoktSDK executeWithViewName:identifier
attributes:OCMOCK_ANY
placements:OCMOCK_ANY
config:nil
placementOptions:[OCMArg checkWithBlock:^BOOL(PlacementOptions *opts) {
return opts != nil;
}]
onLoad:nil
onUnLoad:nil
onShouldShowLoadingIndicator:nil
onShouldHideLoadingIndicator:nil
onEmbeddedSizeChange:nil]);

MPKitExecStatus *status = [self.kitInstance executeWithIdentifier:identifier
attributes:attributes
embeddedViews:nil
config:nil
callbacks:nil
filteredUser:user
options:nil];

// Verify
XCTAssertNotNil(status);
Expand Down Expand Up @@ -783,6 +863,7 @@ - (void)testExecuteWithIdentifierLogsSelectPlacementEventWithPreparedAttributes
attributes:OCMOCK_ANY
placements:OCMOCK_ANY
config:OCMOCK_ANY
placementOptions:OCMOCK_ANY
onLoad:OCMOCK_ANY
onUnLoad:OCMOCK_ANY
onShouldShowLoadingIndicator:OCMOCK_ANY
Expand All @@ -795,7 +876,8 @@ - (void)testExecuteWithIdentifierLogsSelectPlacementEventWithPreparedAttributes
embeddedViews:nil
config:nil
callbacks:nil
filteredUser:user];
filteredUser:user
options:nil];

// Verify that logEvent was called with the correct MPEvent object
OCMVerifyAll(mockMParticleInstance);
Expand Down
2 changes: 1 addition & 1 deletion mParticle_RoktTests/mParticle_Rokt_SwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct mParticle_Rokt_SwiftTests {
// Then
#expect(true, "logSelectPlacementEvent should handle MParticle instance state gracefully")
}

// MARK: - Integration Tests

@MainActor @available(iOS 15, *)
Expand Down
Loading