Use the JavaScript API onVariationRecorded() to fetch what variations visitors view.
Important
All JavaScript APIs in Optimize must be wrapped in a .ready() callback to run properly.
Knowing which variation a visitor actually saw is key for analytics, personalization, and debugging. The onVariationRecorded() API fires a callback as soon as Optimize confirms a variation was recorded, allowing you to log variation views, send data to analytics platforms, or trigger custom logic for personalization.
onVariationRecorded()
intellimize.onVariationRecorded(
result = {
// handle result
},
error = {
// handle error
}
);What the callback returns
-
experienceId,experienceName— optimization name and unique ID -
variationId,variationName— variation name and unique ID -
experienceType— optimization type (abis Test,rbpis Personalize, andccis AI Optimize) -
ccStatus— for AI Optimize, whether the visitor is in the 'holdout' or 'optimized' group
Successful callback returns:
{
experienceId: string,
experienceName: string,
experienceType: 'ab' | 'rbp' | 'cc',
variationId: string,
variationName: string,
ccStatus: 'holdout' | 'optimized'
}Failure callback returns:
{
message: string
}When should the API be called?
Register the onVariationRecorded() callback as early as possible — ideally before the DOM starts rendering. Variations recorded before the callback is registered will not trigger the callback.
A variation is considered “recorded” when:
- A variation is selected by the system
- The variation is applied to the page
- Associated events (e.g., for analytics) are sent
- The system finalizes and records the variation
The callback fires each time a variation is recorded — not just once per page. It triggers as soon as the variation is confirmed, independent of other scripts running on the page.
Single-page app (SPA) usage
Callbacks persist for the life of the Optimize snippet. If your site uses activate() for SPA routing, you don’t need to re-register onVariationRecorded() after each call — it stays active as long as the snippet is in memory.