Google Optimize will no longer be available after September 30, 2023. Your experiments and personalizations can continue to run until that date. Learn more

Install Optimize with Google Tag Manager

Add Optimize to your website using Google Tag Manager

We strongly recommend using the optimize.js installation method as it offers the best performance and is the easiest way to install Optimize.

This article describes how to deploy Optimize with Google Tag Manager. If you use another tag management system, follow their instructions to add Optimize to your existing Google Analytics tag.


Before you can install the snippet on your website, you must have:

  • A Google Analytics account and property
  • A Google Analytics property installed on your website
  • A Google Tag Manager container installed on your website
  • A Google Optimize account and container linked to the Google Analytics property

You also need the ability to edit your website source code directly or make changes in Tag Manager.

Configure Optimize in Tag Manager

  1. Sign in to Tag Manager and select an account.
  2. Click Tags > New.
  3. Click Tag Configuration > Google Optimize.
  4. Enter your Optimize container ID, which you can find under Container details in the container settings in Optimize.
  5. Optional: Expand More Settings and open the Domain Settings dropdown to choose the domain from which you want to install Google Optimize. We recommend using the default domain for better performance and to avoid being throttled. However, choose the domain if you already configured this domain in your Content Security Policy.
  6. Optional: (Universal Analytics only) Select Override global function name (Universal Analytics only) to rename the global object in Universal Analytics using a Google Analytics Settings variable. The Google Analytics Settings variable for the Optimize tag must match the global function name for the Universal Analytics tag. Learn more about renaming the global object.
  7. Save the tag without triggers. Note: The pageview trigger must be configured in the Analytics tag that will fire the Optimize tag.
  8. Enable tag sequencing:
    1. Open the Google Analytics: Universal Analytics or Google Analytics: GA4 Configuration tag for the Analytics property linked to your Optimize container.
    2. Click Tag Configuration > Advanced Settings > Tag Sequencing.
    3. Check the box to fire a tag before this tag fires. Under the Setup Tag heading, click the menu and select the desired Optimize tag.
    4. Configure the Optimize tag to fire once per page, then save it.
  9. Publish your Tag Manager container for the changes to take effect.
Note: Page hiding will not work properly if the Analytics pageview tag isn't using a page view trigger because DOM ready and window loaded take too long to load the Optimize container.

Snippet installation best practices

For optimal performance, place the Optimize snippet at the top of the <HEAD> tag on every web page you wish to optimize.

The only items that should appear above the Optimize snippet are:

  • Any dataLayer initialization code. Note: the dataLayer variable should never be reassigned after the anti-flicker snippet (when used).
  • Any scripts that declare JavaScript variables, functions, or set cookies you use in Optimize, like jQuery or JavaScript libraries used in implementation or targeting. Note: jQuery isn't installed by Optimize by default.
  • The optional anti-flicker snippet, when used to mitigate page flicker.

If you use a content security policy, see Optimize security requirements to make sure your content security policy allows for the domain in the snippet on your site (i.e., or

Was this helpful?
How can we improve it?
Clear search
Close search
Google apps
Main menu
Search Help Center