Overview
The MoEngage Android 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 info directly through a streamlined, native interface.Integration MoEngage Personalization
To begin using MoEngage Personalization in your application, once you have configured the BOM, add the required artifact in the app/build.gradle file as shown below:build.gradle.kts(kotlin)
Implementation Workflow
TheMoEPersonalizeHelper SDK object is designed to simplify the retrieval and interaction with dynamic, personalized content. Below is a breakdown of the code divided by its primary responsibilities.
1. Fetch Meta Experience
Ensure you invoke the metadata call prior to fetching a specific payload or experience. You can use this call to fetch all experience keys under the provided status, providing the context necessary to properly configure subsequent requests.fetchExperiencesMeta first to retrieve the experience key you need.
The onSuccess callback returns an ExperienceCampaignsMetadata object containing all necessary metadata for campaign execution in the main thread. Conversely, the onFailure callback provides a RequestFailureReasonCode and an optional message to identify the specific reason for the request’s failure.
2. Fetch Personalized Content
Once the metadata is fetched, you can retrieve the actual personalized payloads. The SDK provides methods to fetch either a single experience or multiple experiences simultaneously.EXPERIENCE_KEY is the unique key that is used in the experience campaign while creating the campaign on the MoEngage dashboard. You can fetch these keys using the fetchExperiencesMeta call.
onSuccess callback returns an ExperienceCampaignsResult object containing all necessary metadata for campaign execution in the main thread. 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 by passing a Set<String> of
experienceKeys.
3. Track Impressions
After fetching and rendering the personalized content on the UI, it is essential to track user interactions to measure campaign performance. To measure performance, you must track when an experience is shown. This requires acampaignEntity. You can use these methods to log “Impressions” (experienceShown / experiencesShown) when the UI renders the content.
3a. Track Impressions for Experience Campaigns
3b. Track Impressions for Offering Campaigns
Offerings are specific, personalized items (such as a product recommendation or a coupon) contained within a campaign.4. Track Clicks
4a. Track Clicks for Experience Campaigns
You can use these methods to log “Clicks” (experienceClicked) when the user interacts with the rendered UI element.
4b. Track Clicks for Offering Campaigns
Offerings are specific, personalized items (such as a product recommendation or a coupon) contained within a campaign.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.
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.