Install Optimize with Google Tag Manager

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

If you want to deploy Optimize with Google Tag Manager, follow the instructions below. If you use another tag management system (TMS), follow their instructions to add Optimize to your existing Google Analytics tag.

Custom tracker settings

Users of custom tracker settings must use the shared Google Analytics Settings variable in Tag Manager and Analytics to ensure that all tracker settings match between tags.

Step 1: Collect the necessary information

You need the following information to install Optimize:

  1. Your Analytics tracking ID.
  2. Your Optimize container ID.
  3. Confirm that your Tag Manager and Analytics tracker settings use the shared Google Analytics Settings variable.

Step 2: Configure Optimize in Tag Manager

Once you have the information above, follow these steps to 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.
  5. Optional: Expand Global Function Name (Universal Analytics) and select a Google Analytics Settings variable. The Google Analytics Settings variable lets you rename the global function used by the Universal Analytics Tag.
  6. Save the tag without triggers. Note: the pageview trigger must be configured in the Analytics tag that will fire the Optimize tag.
  7. Open the Analytics page view tag for the Analytics property linked to your Optimize container.
  8. Click Tag Configuration > Advanced Settings > Tag Sequencing.
  9. 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.
  10. Configure the Optimize tag to fire once per page, then save it.
  11. Publish your Tag Manager container for the changes to take effect. 

Learn more in the Tag Setup Guide for Optimize in the Tag Manager help center.

  • 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.
  • If you used a Global Function Name instead of a Universal Analytics Settings variable, you can remove the value from the Global Function Name field. When you save, you will only be able to rename the global function using a Universal Analytics Settings variable going forward.

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:

  1. Any dataLayer initialization code. Note: the dataLayer variable should never be reassigned after the anti-flicker snippet (when used).
  2. 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.
  3. The optional anti-flicker snippet, when used to mitigate page flicker.
Was this helpful?
How can we improve it?
Clear search
Close search
Google apps
Main menu
Search Help Center