Overview
fetchExperiences is a client-side method on the MoEngage Personalize SDK. Call it at runtime typically on page load or component mount - with a list of experience keys, and it returns the personalized content that MoEngage has resolved for the current user.
Experience keys are identifiers configured in the MoEngage dashboard for Personalize API experiences. Each key maps to a placement on your website - a homepage banner, a cart offer slot, a product listing card, and so on. MoEngage evaluates the current user against your active experiences and returns only the experiences the user qualifies for. Experiences that cannot be resolved for the user are returned in a separate failures array with a structured reason code.
Your website owns the rendering layer. MoEngage provides the decision and the content payload.
Implementing fetchExperiences
Pre-requisites
SDK installation
- Refer to this article to integrate the Web SDK on your website.
- Refer to this article to integrate the Personalize SDK on your website.
Creating a Personalize API experience
Refer to this article to create a Personalize API experience.When to use
UsefetchExperiences when your website renders personalized content using its own components and MoEngage provides the content payload and decisioning. Common use cases include personalized banners, offer cards, loyalty modules, product listing promotions, cart upsells, and dynamic recommendation blocks.
Implement through a centralized personalization layer rather than independently from unrelated page components. This makes it easier to manage fallback behaviour, attribution, and experience key governance across your site.
Method signature
The method returns a Promise that resolves with a response object containing
experiences and failures.
Fetching experiences
Fetch specific experiences
Use this when the page has fixed placements and you know exactly which experience keys to request.Fetch experiences with custom attributes
Pass custom attributes when your MoEngage audiences use runtime values for targeting - such as locale, page type, or country.Fetch all eligible active experiences
Pass an empty array to evaluate the current user against all active experiences. MoEngage returns up to 25 eligible results.How it works
- The page initializes the MoEngage SDK and establishes user identity and consent.
- Your code calls
fetchExperienceswith the relevant experience keys and any custom attributes. - MoEngage evaluates the user against active campaign and associated segment rules, control groups, A/B variants, and decision policies.
- The Promise resolves with a response object containing
experiencesandfailures. - Your code reads, validates, and renders the payload from each resolved experience.
- Your code passes the
experience_contextandoffering_context(if present in the response) back to MoEngage impression and click tracking calls.
Response
Response structure
The resolved response contains two top-level keys:experiences and failures. Both can be present in the same response - a single call can return some resolved experiences and some failures simultaneously.
Response fields
Payload formats
The shape of the payload depends on how the experience is configured in MoEngage. There are two formats.Format 1 - Direct field values
Each content field is returned as a separate key underpayload. Read values directly - no parsing required.
Use bracket notation for experience keys that contain hyphens -
result.experiences['homepage-banner']. Dot notation (result.experiences.homepage-banner) treats - as the subtraction operator and produces a runtime error that can be difficult to trace.Format 2 - Serialized JSON offer array
One payload field contains a JSON-encoded string representing a ranked list of offers returned by a Decision Policy. Parse it withJSON.parse() before use.
Handling failures
When an experience key appears infailures, it was not served to the current user. Your implementation should suppress the placement or render default content.
E001–E003 and E008 are expected runtime states. E004–E007 indicate a configuration issue in MoEngage and should trigger a log entry or alert for investigation.
Implementation examples
Full example - reading a direct field-value payload
The click handler below usesattachClickHandler() as a sample reference. Replace this with whichever event binding pattern your frontend framework or component library uses.
Full example - reading a serialized JSON offer array payload
When an experience payload contains offering data (Format 2), each offer in the array has its ownoffering_context. Track an impression and click for each offer that is shown or interacted with.
Refer to Offerings events tracking for the full method reference.
The click handler below uses attachClickHandler(offer, index) as a sample reference. Replace this with whichever event binding pattern your frontend framework or component library uses.
Tracking impressions and clicks
Call the appropriate MoEngage SDK tracking methods after rendering each resolved experience and its offers.- For every resolved experience key, call
Moengage.personalize.trackImpression(experience_context)after rendering. - When a user interacts with the rendered experience, call
Moengage.personalize.trackClick(experience_context, extraAttributes).extraAttributesis optional — use it to pass additional context about the CTA clicked. - For experiences that contain offering data, call
Moengage.personalize.offeringShown(offering_context)for each offer rendered. Each offer in the array has its ownoffering_context— pass it as-is and do not reuse contexts across offers. - On offer click, call
Moengage.personalize.offeringClicked(offering_context, experience_context). Passing both contexts tracks the click for the offering and the parent experience in a single call.