Use dynamic impression tracking with the Personalize Edge SDK’s triggerImpression() method to support entries with multiple experiences and variants. You can extract the applied variants from the Content Delivery API (CDA) response and programmatically trigger impressions based on the resolved variant aliases.
We recommend this approach to minimize developer involvement when rolling out new and updated experiences. The CDA response includes a publish_details.variants object, which shows the resolved variant(s) for a specific entry based on active experiences and audience conditions determined by Personalize.
When using Personalize, experiences and variants are resolved dynamically at runtime based on the user’s audience membership. Because the content served can be a dynamic mix of variants, it is essential to extract the applied variants from the CDA response. This ensures your impression tracking reflects exactly what was shown to the user, enabling accurate measurement and analytics.
The GET Manifest endpoint, also known as the Manifest API, returns the active variants for a user. When a user visits your site, Personalize evaluates all Active Experiences configured for that page and determines which variant to show for each experience.
This variant alias can then be used to request the personalized entry content from the Contentstack Content Delivery API (CDA).
Note: The manifest only indicates which variant should be displayed, not whether the variant content actually exists or was rendered. Only trigger impressions after confirming that the corresponding variant content was retrieved and shown on the page.
Example: JavaScript Edge SDK
import Personalize from '@contentstack/personalize-edge-sdk';
const personalizeSDK = await Personalize.init(projectUid);
const variantAliases = personalizeSDK.getVariantAliases();
console.log(variantAliases); // example: ['cs_personalize_0_0', 'cs_personalize_1_1']Example: REST API (GET /manifest)
curl -X GET 'https://personalize-edge.contentstack.com/manifest' \
-H 'X-Project-Uid: <your_personalize_project_uid>' \
-H 'Cookie: cs_personalize_user_uid=<anonymous_user_id>' \
-H 'X-Page-Url: https://www.mysite.com/homepage'Sample Response:
{
"experiences": [
{
"shortUid": "0",
"activeVariantShortUid": "0"
},
{
"shortUid": "1",
"activeVariantShortUid": "1"
}
]
}Note: Replace the request URL domain, x-project-uid header, and cs_personalize_user_uid cookie with actual values.
Use the active variants to fetch personalized entry data via the Contentstack CDA (REST, GraphQL, or SDK). Make sure to include the publish_details field to access applied variant metadata.
REST API: Entry variant API
SDK: Get Variants
Each key in the variants object is a Variant UID. Each value includes an alias in the format cs_personalize_<experience_uid>_<variant_uid>.
{
"entry": {
"title": "Dynamic Banner",
"publish_details": {
"variants": {
"<first_variant_uid>": {
"alias": "cs_personalize_0_0",
"environment": "<your_environment>"
},
"<second_variant_uid>": {
"alias": "cs_personalize_1_1",
"environment": "<your_environment>"
}
}
}
}
}Note: Each value includes metadata, including the alias, which is needed to register impressions.
You can extract variant aliases using the CDA response. These aliases are required to register impressions using the triggerImpressions() method or the Edge API.
const variants = entry?.publish_details?.variants || {};
const variantAliases = Object.values(variants).map((v) => v.alias);Once you have extracted the active variant aliases, register impression events for each one. This step is critical for tracking which variants were shown to the user and measuring the performance of your personalization efforts.
// after initializing the SDK
personalizeSDK.triggerImpressions({
aliases: variantAliases
});Note: Ensure the variant content is rendered before calling triggerImpressions() to avoid false impressions.
curl -X POST 'https://personalize-edge.contentstack.com/events' \
--header 'x-cs-personalize-user-uid: <user_id>' \
--header 'x-project-uid: <project_uid>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '[
{
"type": "IMPRESSION",
"experienceShortUid": "0",
"variantShortUid": "0"
},
{
"type": "IMPRESSION",
"experienceShortUid": "1",
"variantShortUid": "1"
}
]'Replace all placeholder values with the actual values from your project setup.