Skip to main content

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

  1. Refer to this article to integrate the Web SDK on your website.
  2. 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

Use fetchExperiences 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.
Use explicit experience keys for fixed placements. Pass empty-array only when your frontend is built to handle a dynamic set of returned experiences - such as a dynamic offer feed or a discovery-style content area. With empty-array mode, your rendering logic must decide where each returned experience belongs, what to do when a required placement is not returned, and how to handle more results than available slots.

How it works

  1. The page initializes the MoEngage SDK and establishes user identity and consent.
  2. Your code calls fetchExperiences with the relevant experience keys and any custom attributes.
  3. MoEngage evaluates the user against active campaign and associated segment rules, control groups, A/B variants, and decision policies.
  4. The Promise resolves with a response object containing experiences and failures.
  5. Your code reads, validates, and renders the payload from each resolved experience.
  6. Your code passes the experience_context and offering_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 under payload. Read values directly - no parsing required.
Read values directly using optional chaining:
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 with JSON.parse() before use.
Do not call JSON.parse() on every payload field. Parse only fields you know contain serialized JSON. Calling JSON.parse() on a plain string value such as a title or URL will throw an error.

Handling failures

When an experience key appears in failures, 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 uses attachClickHandler() 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 own offering_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). extraAttributes is 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 own offering_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.
Refer to Personalize API Experience events tracking and Offerings events tracking for the full method reference. For further assistance, please contact your MoEngage Customer Success Manager (CSM) or the Support team.