MoEngageSDKPersonalize
@objc
public class MoEngageSDKPersonalize : NSObject
Entry point for the MoEngage Personalization SDK.
Use this class to:
- Fetch experience metadata (to discover available experiences)
- Fetch experience campaign data for one or more experience keys
- Track experience impression and click events
- Track offering impression and click events
-
Shared singleton instance.
Declaration
Swift
@objc public static let sharedInstance: MoEngageSDKPersonalize
-
Fetches metadata for experience campaigns from the MoEngage backend (Swift-only).
Use this API from Swift code for native enum support with full type safety. Use this to discover available experiences and their statuses before fetching full campaign data.
Example
// Multiple statuses MoEngageSDKPersonalize.sharedInstance.fetchExperiencesMeta( status: [.active, .paused], onSuccess: { metadata in print("Found \(metadata.experienceCampaignMeta.count) experiences") }, onFailure: { error in print("Error: \(error.message)") } ) // Single status MoEngageSDKPersonalize.sharedInstance.fetchExperiencesMeta( status: [.active], onSuccess: { metadata in /* ... */ }, onFailure: { error in /* ... */ } ) // All statuses MoEngageSDKPersonalize.sharedInstance.fetchExperiencesMeta( status: [], onSuccess: { metadata in /* ... */ }, onFailure: { error in /* ... */ } )Declaration
Swift
public func fetchExperiencesMeta( status: [MoEngageExperienceStatus], onSuccess: @escaping MoEngageMetaSuccessCallback, onFailure: @escaping MoEngagePersonalizeFailureCallback, workspaceId: String? = nil )Parameters
statusFilter by experience status. Pass an empty array
[]to fetch all statuses.onSuccessCalled on the main thread with metadata wrapper containing source and list of experience metadata.
onFailureCalled on the main thread with a
MoEngageExperienceFailureReasonon SDK-level error.workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace. -
Fetches metadata for experience campaigns from the MoEngage backend (Objective-C compatible).
Use this API from Objective-C code. Pass status values as boxed NSNumbers using the
MoEngageExperienceStatusenum constants.Objective-C Example
// Multiple statuses NSArray<NSNumber *> *statuses = @[ @(MoEngageExperienceStatusActive), @(MoEngageExperienceStatusPaused) ]; [[MoEngageSDKPersonalize sharedInstance] fetchExperiencesMetaWithStatusRawValues:statuses onSuccess:^(MoEngageExperienceCampaignMetaData *metadata) { NSLog(@"Found %lu experiences", (unsigned long)metadata.experienceCampaignMeta.count); } onFailure:^(MoEngageExperienceFailureReason *error) { NSLog(@"Error: %@", error.message); } workspaceId:nil]; // Single status [[MoEngageSDKPersonalize sharedInstance] fetchExperiencesMetaWithStatusRawValues:@[@(MoEngageExperienceStatusActive)] onSuccess:^(MoEngageExperienceCampaignMetaData *metadata) { /* ... */ } onFailure:^(MoEngageExperienceFailureReason *error) { /* ... */ } workspaceId:nil]; // All statuses [[MoEngageSDKPersonalize sharedInstance] fetchExperiencesMetaWithStatusRawValues:@[] onSuccess:^(MoEngageExperienceCampaignMetaData *metadata) { /* ... */ } onFailure:^(MoEngageExperienceFailureReason *error) { /* ... */ } workspaceId:nil];Note
For Swift code, usefetchExperiencesMeta(status:onSuccess:onFailure:workspaceId:)which accepts[MoEngageExperienceStatus]directly.Declaration
Swift
@objc(fetchExperiencesMetaWithStatusRawValues:onSuccess:onFailure:workspaceId:) public func fetchExperiencesMetaObjC( statusRawValues: [NSNumber], onSuccess: @escaping MoEngageMetaSuccessCallback, onFailure: @escaping MoEngagePersonalizeFailureCallback, workspaceId: String? = nil )Parameters
statusRawValuesArray of NSNumber containing
MoEngageExperienceStatusraw values. Pass empty array@[]to fetch all statuses. Invalid values are filtered out.onSuccessCalled on the main thread with metadata wrapper containing source and list of experience metadata.
onFailureCalled on the main thread with a
MoEngageExperienceFailureReasonon SDK-level error.workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace.
-
Fetches campaign data for a single experience key.
Uses cache-first strategy: checks local cache first, falls back to network if cache is missing or expired.
Declaration
Swift
@objc public func fetchExperience( experienceKey: String, attributes: [String: String] = [:], onSuccess: @escaping MoEngageExperienceSuccessCallback, onFailure: @escaping MoEngagePersonalizeFailureCallback, workspaceId: String? = nil )Parameters
experienceKeyThe experience key to fetch.
attributesOptional custom key-value attributes sent with the request.
onSuccessCalled on the main thread with the result containing experiences and/or failures.
onFailureCalled on the main thread with a
MoEngageExperienceFailureReasonon SDK-level error.workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace.
-
Fetches campaign data for one or more experience keys.
Uses cache-first strategy: checks local cache first, falls back to network if cache is missing or expired.
If even one key is invalid (not present in the local metadata cache), the entire request returns a failure.
Declaration
Swift
public func fetchExperiences( experienceKeys: Set<String>, attributes: [String: String] = [:], onSuccess: @escaping MoEngageExperienceSuccessCallback, onFailure: @escaping MoEngagePersonalizeFailureCallback, workspaceId: String? = nil )Parameters
experienceKeysThe set of experience keys to fetch.
attributesOptional custom key-value attributes sent with the request.
onSuccessCalled on the main thread with the result containing experiences and/or failures.
onFailureCalled on the main thread with a
MoEngageExperienceFailureReasonon SDK-level error.workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace. -
Objective-C compatible overload for
fetchExperiences(experienceKeys:attributes:onSuccess:onFailure:workspaceId:).Accepts an
NSArray<NSString *>(bridged as[String]) and converts toSet<String>internally.Note
For Swift code, usefetchExperiences(experienceKeys:attributes:onSuccess:onFailure:workspaceId:)which acceptsSet<String>directly.Declaration
Swift
@objc(fetchExperiencesWithKeys:attributes:onSuccess:onFailure:workspaceId:) public func fetchExperiencesObjC( experienceKeys: [String], attributes: [String: String] = [:], onSuccess: @escaping MoEngageExperienceSuccessCallback, onFailure: @escaping MoEngagePersonalizeFailureCallback, workspaceId: String? = nil )
-
Tracks an impression event for a single experience campaign.
Declaration
Swift
@objc public func trackExperienceShown( campaign: MoEngageExperienceCampaign, workspaceId: String? = nil )Parameters
campaignThe experience campaign that was shown.
workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace. -
Tracks impression events for multiple experience campaigns.
Declaration
Swift
@objc public func trackExperiencesShown( campaigns: [MoEngageExperienceCampaign], workspaceId: String? = nil )Parameters
campaignsThe experience campaigns that were shown.
workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace. -
Tracks a click event for a single experience campaign.
Declaration
Swift
@objc public func trackExperienceClicked( campaign: MoEngageExperienceCampaign, workspaceId: String? = nil )Parameters
campaignThe experience campaign that was clicked.
workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace.
-
Tracks an impression event for a specific offering.
Pass the
offering_contextattributes of the specific offering that was shown. The offering must have required attributes (moe_offering_id,moe_offering_name,moe_offering_type,moe_decision_policy_id,moe_decision_policy_name).Declaration
Swift
@objc public func trackOfferingShown( offeringAttributes: [String: Any], workspaceId: String? = nil )Parameters
offeringAttributesThe
offering_contextattributes of the offering that was shown.workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace. -
Tracks impression events for multiple offerings.
Declaration
Swift
@objc public func trackOfferingsShown( offeringsAttributes: [[String: Any]], workspaceId: String? = nil )Parameters
offeringsAttributesArray of
offering_contextattribute dictionaries for each offering shown.workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace. -
Tracks a click event for a specific offering within an experience campaign.
Fires both
MOE_PERSONALIZATION_MESSAGE_CLICKED(experience-level) andMOE_OFFERING_CLICKED(offering-level) events. Only one offering can be clicked at a time — pass the attributes of the specific offering clicked.Declaration
Swift
@objc public func trackOfferingClicked( campaign: MoEngageExperienceCampaign, offeringAttributes: [String: Any], workspaceId: String? = nil )Parameters
campaignThe experience campaign containing the clicked offering.
offeringAttributesThe
offering_contextattributes of the specific offering that was clicked.workspaceIdOptional MoEngage workspace (App ID).
niluses the default workspace.