Optimize JavaScript API for third-party developers

The Optimize JavaScript API allows third party analytics developers to detect when visitors are in Optimize experiences and to tag their data with Optimize IDs. Once enabled, customers can filter and view their data by Optimize dimensions (e.g. containerID and experimentID), without leaving the third-party platform. Developers can also use the JavaScript API to generate deep links to Optimize reports providing customers with convenient, one-click access to their Optimize data.

Registering implementation callbacks

Developers can create deep links to Optimize for the current combination and experience by registering implementation callbacks for the following identifiers:

  • containerId
  • combination
  • experimentId

This is an example of a callback that generates a custom URL to a specific variant or combination for multivariate experiments (MVT):

// Should be used in scripts placed after the Optimize or GTM
// installation or the initialization of the dataLayer variable.

gtag('event', 'optimize.callback', {
    callback: (combination, experimentId, containerId) => {
     console.log(`http://optimize.google.com/experiences/${experimentId}?` 
         + `containerId=${containerId}&combination=${combination}`);
    }
 });

You can also omit "combination" to generate a custom URL to the experiment details page, without highlighting a specific variant:

// Should be used in scripts placed after the Optimize or GTM
// installation or the initialization of the dataLayer variable.

gtag('event', 'optimize.callback', {
    callback: (combination, experimentId, containerId) => {
     console.log(`http://optimize.google.com/experiences/${experimentId}?` 
         + `containerId=${containerId}`);
    }
 });

For A/B and redirect tests:

  • combination=0 is the original
  • combination=1 is variant 1
  • etc.

For multivariate tests (MVT):

  • combination=0-1 is combination A0-b1
  • etc.

Optimize automatically identifies and parses the inbound link and directs the customer to the correct experiment details page.

Hotjar + Optimize: new insights on your experiences

The first third-party developer to take advantage of the new Optimize JavaScript API is Hotjar, a provider of session recordings and heatmaps. Hotjar annotates session recordings with Optimize IDs allowing customers to easily filter their reports. Hotjar also generates custom URLs that direct customers to relevant Optimize experiment details.

Related resources:

Was this helpful?
How can we improve it?

Need more help?

Sign in for additional support options to quickly solve your issue