-
Notifications
You must be signed in to change notification settings - Fork 72
feat: Update Rokt public methods to match Rokt 5.0 #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jamesnrokt
wants to merge
4
commits into
workstation/9.0-Release
Choose a base branch
from
feat/adjust-select-placements
base: workstation/9.0-Release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,6 +236,191 @@ func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { | |
|
|
||
| --- | ||
|
|
||
| ### MPRokt API Changes | ||
|
|
||
| The `MPRokt` interface has been updated to align with the Rokt SDK 4.14.x API. These changes consolidate multiple callback parameters into a unified event-based callback pattern and standardize parameter naming. | ||
|
|
||
| #### What Has Changed | ||
|
|
||
| - The `MPRoktEventCallback` class has been removed and replaced with MPRoktEvent | ||
| - The `selectPlacements:` method's `callbacks:` parameter has been replaced with `onEvent:` | ||
| - The `purchaseFinalized:` method's `placementId:` parameter has been renamed to `identifier:` | ||
| - A new `globalEvents:` method has been added for subscribing to global Rokt events | ||
| - A new `MPRoktEmbeddedSizeChanged` event class has been added | ||
|
|
||
| #### Migration Steps | ||
|
|
||
| ##### selectPlacements Method | ||
|
|
||
| **Before (Objective-C):** | ||
|
|
||
| ```objective-c | ||
| MPRoktEventCallback *callbacks = [[MPRoktEventCallback alloc] init]; | ||
| callbacks.onLoad = ^{ | ||
| // Handle load | ||
| }; | ||
| callbacks.onUnLoad = ^{ | ||
| // Handle unload | ||
| }; | ||
| callbacks.onShouldShowLoadingIndicator = ^{ | ||
| // Show loading indicator | ||
| }; | ||
| callbacks.onShouldHideLoadingIndicator = ^{ | ||
| // Hide loading indicator | ||
| }; | ||
| callbacks.onEmbeddedSizeChange = ^(NSString *placementId, CGFloat height) { | ||
| // Handle size change | ||
| }; | ||
|
|
||
| [[MParticle sharedInstance].rokt selectPlacements:@"checkout" | ||
| attributes:attributes | ||
| embeddedViews:embeddedViews | ||
| config:config | ||
| callbacks:callbacks]; | ||
| ``` | ||
|
|
||
| **After (Objective-C):** | ||
|
|
||
| ```objective-c | ||
| [[MParticle sharedInstance].rokt selectPlacements:@"checkout" | ||
| attributes:attributes | ||
| embeddedViews:embeddedViews | ||
| config:config | ||
| onEvent:^(MPRoktEvent * _Nonnull event) { | ||
| if ([event isKindOfClass:[MPRoktEvent.MPRoktShowLoadingIndicator class]]) { | ||
| // Show loading indicator | ||
| } else if ([event isKindOfClass:[MPRoktEvent.MPRoktHideLoadingIndicator class]]) { | ||
| // Hide loading indicator | ||
| } else if ([event isKindOfClass:[MPRoktEvent.MPRoktPlacementReady class]]) { | ||
| // Handle load/ready | ||
| } else if ([event isKindOfClass:[MPRoktEvent.MPRoktPlacementClosed class]]) { | ||
| // Handle unload/closed | ||
| } else if ([event isKindOfClass:[MPRoktEvent.MPRoktEmbeddedSizeChanged class]]) { | ||
| MPRoktEvent.MPRoktEmbeddedSizeChanged *sizeEvent = (MPRoktEvent.MPRoktEmbeddedSizeChanged *)event; | ||
| // Handle size change with sizeEvent.placementId and sizeEvent.updatedHeight | ||
| } | ||
| }]; | ||
| ``` | ||
|
|
||
| **Before (Swift):** | ||
|
|
||
| ```swift | ||
| let callbacks = MPRoktEventCallback() | ||
| callbacks.onLoad = { | ||
| // Handle load | ||
| } | ||
| callbacks.onUnLoad = { | ||
| // Handle unload | ||
| } | ||
| callbacks.onShouldShowLoadingIndicator = { | ||
| // Show loading indicator | ||
| } | ||
| callbacks.onShouldHideLoadingIndicator = { | ||
| // Hide loading indicator | ||
| } | ||
| callbacks.onEmbeddedSizeChange = { placementId, height in | ||
| // Handle size change | ||
| } | ||
|
|
||
| MParticle.sharedInstance().rokt.selectPlacements("checkout", | ||
| attributes: attributes, | ||
| embeddedViews: embeddedViews, | ||
| config: config, | ||
| callbacks: callbacks) | ||
| ``` | ||
|
|
||
| **After (Swift):** | ||
|
|
||
| ```swift | ||
| MParticle.sharedInstance().rokt.selectPlacements("checkout", | ||
| attributes: attributes, | ||
| embeddedViews: embeddedViews, | ||
| config: config) { event in | ||
| switch event { | ||
| case is MPRoktEvent.MPRoktShowLoadingIndicator: | ||
| // Show loading indicator | ||
| case is MPRoktEvent.MPRoktHideLoadingIndicator: | ||
| // Hide loading indicator | ||
| case is MPRoktEvent.MPRoktPlacementReady: | ||
| // Handle load/ready | ||
| case is MPRoktEvent.MPRoktPlacementClosed: | ||
| // Handle unload/closed | ||
| case let sizeEvent as MPRoktEvent.MPRoktEmbeddedSizeChanged: | ||
| // Handle size change with sizeEvent.placementId and sizeEvent.updatedHeight | ||
| default: | ||
| break | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ##### purchaseFinalized Method | ||
|
|
||
| **Before (Objective-C):** | ||
|
|
||
| ```objective-c | ||
| [[MParticle sharedInstance].rokt purchaseFinalized:@"checkout" | ||
| catalogItemId:@"item123" | ||
| success:YES]; | ||
| ``` | ||
|
|
||
| **After (Objective-C):** | ||
|
|
||
| ```objective-c | ||
| [[MParticle sharedInstance].rokt purchaseFinalized:@"checkout" | ||
| catalogItemId:@"item123" | ||
| success:YES]; | ||
| ``` | ||
|
|
||
| Note: The method signature remains the same, but the parameter name has changed from `placementId:` to `identifier:`. If you're using named parameters, update accordingly. | ||
|
Comment on lines
+356
to
+374
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe squish this into before and after since there is no difference between the two examples? |
||
|
|
||
| ##### New globalEvents Method | ||
|
|
||
| The new `globalEvents:` method allows you to subscribe to global Rokt events from all sources, including events not associated with a specific view (such as `InitComplete`). | ||
|
|
||
| **Objective-C:** | ||
|
|
||
| ```objective-c | ||
| [[MParticle sharedInstance].rokt globalEvents:^(MPRoktEvent * _Nonnull event) { | ||
| if ([event isKindOfClass:[MPRoktEvent.MPRoktInitComplete class]]) { | ||
| MPRoktEvent.MPRoktInitComplete *initEvent = (MPRoktEvent.MPRoktInitComplete *)event; | ||
| if (initEvent.success) { | ||
| // Rokt SDK initialized successfully | ||
| } | ||
| } | ||
| }]; | ||
| ``` | ||
|
|
||
| **Swift:** | ||
|
|
||
| ```swift | ||
| MParticle.sharedInstance().rokt.globalEvents { event in | ||
| if let initEvent = event as? MPRoktEvent.MPRoktInitComplete { | ||
| if initEvent.success { | ||
| // Rokt SDK initialized successfully | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### Event Mapping Reference | ||
|
|
||
| | Old Callback | New Event Class | | ||
| | ------------------------------ | ---------------------------- | | ||
| | `onLoad` | `MPRoktPlacementReady` | | ||
| | `onUnLoad` | `MPRoktPlacementClosed` | | ||
| | `onShouldShowLoadingIndicator` | `MPRoktShowLoadingIndicator` | | ||
| | `onShouldHideLoadingIndicator` | `MPRoktHideLoadingIndicator` | | ||
| | `onEmbeddedSizeChange` | `MPRoktEmbeddedSizeChanged` | | ||
|
|
||
| #### Notes | ||
|
|
||
| - All `MPRoktEvent` subclasses are nested classes within `MPRoktEvent` | ||
| - The `onEvent` callback receives all event types, so use type checking to handle specific events | ||
| - The `MPRoktEmbeddedSizeChanged` event provides both `placementId` and `updatedHeight` properties | ||
| - Remove any references to `MPRoktEventCallback` from your code | ||
|
|
||
| --- | ||
|
|
||
| ## Migrating from versions < 8.0.0 | ||
|
|
||
| For migration guidance from SDK 7.x to SDK 8.x, please see [migration-guide-v8.md](migration-guide-v8.md). | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.