Install Optimize with Google Tag Manager

Add Optimize to your website using GTM.

Note: If you use the global site tag (gtag.js), follow these instructions instead.

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.  

If Optimize is installed via Tag Manager, use the page view trigger type. Page hiding will not work properly if the Optimize tag isn't using a page view trigger because DOM ready and window loaded take too long to load the Optimize container.

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. Select a Google Analytics Settings variable.
  6. Click Save and save the tag without triggers.
  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.

Snippet placement best practices

For optimal performance place your Tag Manager tag at the very top of the <head> of every page you wish to optimize.

The only items that should appear above the global site tag are:

  1. Data layer initialization. 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 that you wish to use in Optimize experiences. For example jQuery or any JavaScript library that you wish to use in implementation or targeting. Note: jQuery isn't installed by Optimize by default.
  3. The optional anti-flicker snippet which can be used to avoid flicker.
Was this helpful?
How can we improve it?

Need more help?

Sign in for additional support options to quickly solve your issue