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
32 changes: 22 additions & 10 deletions mParticle-Rokt-Swift/MPRoktLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public class MPRoktLayout {
config: RoktConfig? = nil,
onEvent: ((RoktEvent) -> Void)? = nil
) {
confirmUser(attributes: attributes) {
MPLog.debug("Initializing MPRoktLayout with arguments:", sdkTriggered.wrappedValue, viewName ?? "nil", locationName, attributes)
confirmUser(attributes: attributes) { identifyCalled in
let preparedAttributes = MPKitRokt.prepareAttributes(attributes, filteredUser: Optional<FilteredMParticleUser>.none, performMapping: true)


MPLog.debug("Initializing RoktLayout with arguments:", sdkTriggered.wrappedValue, viewName ?? "nil", locationName, preparedAttributes)
self.roktLayout = RoktLayout.init(
sdkTriggered: sdkTriggered,
viewName: viewName,
Expand All @@ -40,15 +42,23 @@ public class MPRoktLayout {
config: config,
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
if identifyCalled && sdkTriggered.wrappedValue {
Comment thread
BrandonStalnaker marked this conversation as resolved.
MPLog.debug("Triggering Rokt Swift UI re-render")
DispatchQueue.main.async {
sdkTriggered.wrappedValue = false
sdkTriggered.wrappedValue = true
}
}
}
}

func confirmUser(
attributes: [String: String]?,
completion: @escaping () -> Void
completion: @escaping (Bool) -> Void
) {
guard let user = mparticle.identity.currentUser else {
completion()
completion(false)
return
}
let email = attributes?["email"]
Expand Down Expand Up @@ -76,15 +86,17 @@ public class MPRoktLayout {
if emailMismatch || hashedEmailMismatch {
// If there is an existing email or hashed email but it doesn't match what was passed in, warn the customer
if emailMismatch {
print("The existing email on the user (\(userEmailIdentity ?? "nil")) does not match the email passed in to `selectPlacements:` (\(email ?? "nil")). Please remember to sync the email identity to mParticle as soon as you receive it. We will now identify the user before creating the layout")
MPLog.warning("The existing email on the user (\(userEmailIdentity ?? "nil")) does not match the email passed in to `selectPlacements:` (\(email ?? "nil")). Please remember to sync the email identity to mParticle as soon as you receive it. We will now identify the user before creating the layout")
}
if hashedEmailMismatch {
print("The existing hashed email on the user (\(user.identities[hashedEmailIdentity ?? NSNumber(value: -1)] ?? "nil")) does not match the email passed in to `selectPlacements:` (\(hashedEmail ?? "nil")). Please remember to sync the hashed email identity to mParticle as soon as you receive it. We will now identify the user before creating the layout")
MPLog.warning("The existing hashed email on the user (\(user.identities[hashedEmailIdentity ?? NSNumber(value: -1)] ?? "nil")) does not match the email passed in to `selectPlacements:` (\(hashedEmail ?? "nil")). Please remember to sync the hashed email identity to mParticle as soon as you receive it. We will now identify the user before creating the layout")
}

syncIdentities(user: user, email: email, hashedEmail: hashedEmail, hashedEmailKey: hashedEmailIdentity, completion: completion)
syncIdentities(user: user, email: email, hashedEmail: hashedEmail, hashedEmailKey: hashedEmailIdentity) {
completion(true)
}
} else {
completion()
completion(false)
}
}

Expand All @@ -103,11 +115,11 @@ public class MPRoktLayout {

mparticle.identity.identify(identityRequest) {apiResult, error in
if let error = error {
print("Failed to sync email from selectPlacement to user: \(error)")
MPLog.error("Failed to sync email from selectPlacement to user: \(error)")
completion()
} else {
if let identities = apiResult?.user.identities {
print("Updated user identity based off selectPlacement's attributes: \(identities)")
MPLog.debug("Updated user identity based off selectPlacement's attributes: \(identities)")
}
completion()
}
Expand Down
13 changes: 13 additions & 0 deletions mParticle-Rokt/MPKitRokt.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ - (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configu
NSString *kitVersion = @"8.3.1";

// 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
Expand Down Expand Up @@ -98,6 +100,7 @@ - (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier
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]];
NSDictionary<NSString *, NSString *> *finalAtt = [MPKitRokt prepareAttributes:attributes filteredUser:filteredUser performMapping:NO];

//Convert MPRoktConfig to RoktConfig
Expand Down Expand Up @@ -176,6 +179,7 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
finalAttributes = [[NSMutableDictionary alloc] initWithDictionary:@{sandboxKey: sandboxValue}];
}

[MPKitRokt MPLog:[NSString stringWithFormat:@"Sandbox value: %@", finalAttributes[sandboxKey]]];
return finalAttributes;
}

Expand Down Expand Up @@ -208,6 +212,7 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
[finalAtt addEntriesFromDictionary:@{sandboxKey: attributes[sandboxKey]}];
}

[MPKitRokt MPLog:[NSString stringWithFormat:@"Attributes updated with mapped user Attributes and Identities: %@", finalAtt]];
return [self confirmSandboxAttribute:finalAtt];
}

Expand Down Expand Up @@ -744,6 +749,14 @@ - (MPKitExecStatus *)setOptOut:(BOOL)optOut {
return [self execStatus:MPKitReturnCodeSuccess];
}

+ (void)MPLog:(NSString *)string {
NSString *msg = [NSString stringWithFormat:@"%@%@", @"MPRokt -> ", string];
if ([[MParticle sharedInstance] environment] == MPEnvironmentDevelopment) {
NSLog(@"%@", msg);
}
}


+ (MPRoktEvent * _Nullable)mapEvent:(RoktEvent *)event {
if (!event) {
return nil;
Expand Down
Loading