Optimize for non-Webflow sites

API: Track recorded variations

Updated

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 (ab is Test, rbp is Personalize, and cc is 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:

  1. A variation is selected by the system
  2. The variation is applied to the page
  3. Associated events (e.g., for analytics) are sent
  4. 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.