Overview
The MoEngage iOS SDK provides a secure framework for delivering personalized campaigns. It simplifies integration by handling user identity and authentication internally, eliminating the need to manage API secrets or manual HTTPS calls. This allows you to fetch and track personalized campaign information directly through a streamlined, native interface.Integration MoEngage Personalization
- SPM (Swift Package Manager)
- CocoaPods
To install the
MoEngagePersonalization through SPM, perform the following steps:- Navigate to File > Add Package.
- Enter the appropriate repository URL:
- https://github.com/moengage/apple-sdk.git (for MoEngage-iOS-SDK versions 9.23.0 and above)
- https://github.com/moengage/MoEngage-iOS-SDK.git (for other versions)
- Select the master branch or your desired version.
- Click Add Package.
- Add the MoEngagePersonalization product to your app target.
Implementation Workflow
TheMoEngageSDKPersonalize singleton is designed to simplify the retrieval and interaction with dynamic, personalized content on iOS. The SDK provides native Swift methods as well as Objective-C-compatible overloads.
1. Fetching Meta Experience
Before fetching any specific payload or experience, you must invoke the metadata call. This step provides the SDK with the necessary configuration and context to accurately process subsequent requests. The SDK offers dedicated methods for both Swift and Objective-C.onSuccess callback returns an ExperienceCampaignsMetadata object containing all necessary metadata for campaign execution. Conversely, the onFailure callback provides a RequestFailureReasonCode and an optional message to identify the specific reason for the request’s failure.
Always call the metadata fetch first to initialize core configurations based on the desired experience status. Use the standard method for Swift arrays, or the ObjC variant if passing raw NSNumber values from Objective-C code.
2. Fetch Personalized Content
Once metadata is fetched, you can retrieve the actual personalized payloads. You can fetch a single experience or multiple experiences simultaneously, with full support for contextual targeting. The code snippet below to fetch a single experience is compatible with both Swift and Objective-C implementations:Objective-C
onSuccess callback returns an ExperienceCampaignsResult object containing all necessary metadata for campaign execution. Conversely, the onFailure callback provides a RequestFailureReasonCode and an optional message to identify the specific reason for the request’s failure.
You can fetch :
- Single Experiences: Retrieve a specific payload using a single experienceKey.
- Bulk Experiences: Retrieve multiple payloads at once. In Swift, pass a Set<String>. For Objective-C, use the
fetchExperiencesObjCmethod which accepts an NSArray bridged as [String].
3. Track Impressions
To accurately measure campaign performance, you must track user interactions after rendering the personalized content on the UI. The below-mentioned tracking code snippets are compatible with both Swift and Objective-C implementations.3a. Track Impressions for Experience Campaigns
Objective-C
trackExperienceShown / trackExperiencesShown) when the UI renders the content.
3b. Track Impressions for Offering Campaigns
Offerings are a distinct subtype of personalized content. The SDK provides dedicated tracking functions that accept offering-specific attributes. The below-mentioned tracking code snippets are compatible with both Swift and Objective-C implementations.Objective-C
offeringAttributes dictionaries to the server, providing highly granular analytics for custom offers.
4. Track Clicks
4a. Track Clicks for Experience Campaigns
Objective-C
trackExperienceClicked) when the user interacts with the UI element.
4b. Track Clicks for Offering Campaigns:
Offerings are a distinct subtype of personalized content. The SDK provides dedicated tracking functions that accept offering-specific attributes. The below-mentioned tracking code snippets are compatible with both Swift and Objective-C implementations.Objective-C
You can use these Offering-specific functions only if the data is part of an offering payload. For all other experience data, use the standard experience shown/clicked functions.
offeringAttributes dictionaries to the server, providing highly granular analytics for custom offers.
For more information, refer to the API documentation.
FAQs
Does the SDK handle UI rendering?
Does the SDK handle UI rendering?
No. The SDK returns raw JSON payloads. You are responsible for parsing the data and building the UI components (e.g., banners or carousels).
Does the SDK cache images or videos?
Does the SDK cache images or videos?
No. The SDK does not download or cache media assets. Use a standard media loading library to handle images, videos, or fonts referenced in the JSON.
Is there a limit on how many experiences I can fetch?
Is there a limit on how many experiences I can fetch?
Yes. You can fetch up to 25 experiences in a single call. If you exceed this, the SDK returns the 25 most recently updated experiences and notifies you of the unfulfilled keys.
What happens if a fetch request is made while the device is offline and no valid cache is available?
What happens if a fetch request is made while the device is offline and no valid cache is available?
The SDK returns an empty payload along with a standardized error code (e.g., NETWORK_ERROR). For more information on all the errors, refer here.