Skip to main content
menu_icon.png

Everything you need to switch from Optimizely Classic to X in one place: See the Optimizely X Web Transition Guide.

x
Optimizely Knowledge Base

Implement Optimizely with a tag manager

relevant products:
  • Optimizely Classic
  • Optimizely X Web Experimentation
  • Optimizely X Web Personalization

This article will help you:
  • Evaluate the tradeoffs of implementing Optimizely inside or outside of a tag manager
  • Use best practices for implementing Optimizely with a tag manager

Are you considering using a tag manager to load Optimizely's snippet? Many Optimizely customers use a tag management system (TMS) to manage multiple on-site tags, such as analytics and remarketing scripts, without involving their IT departments.

This article describes the best practices for implementing Optimizely with a tag manager.

Here are guides for implementing the Optimizely snippet with a tag manager: 

Load Optimizely synchronously

Optimizely be implemented in the <head> tag of your site, before any other analytics tags run and before your page elements load. This is because Optimizely applies visual changes to your website.

To make sure that Optimizely loads and integrates correctly, you must make sure that Optimizely can finish loading before other tags on your page execute. This is called synchronous loading because all tags load one after the other. There are two ways to ensure synchronous loading:

  • Load Optimizely in the <head> tag of your page, outside of a tag manager (recommended, especially with Google Tag Manager).

  • Use a tag manager that supports synchronous loading such as Tealium or Ensighten (not Google Tag Manager).

Potential pitfalls and best practices

Here are some potential pitfalls to loading Optimizely through a tag manager that doesn’t support synchronous loading, especially Google Tag Manager:

  • If you partially deploy Optimizely on your site, you may not deploy Optimizely on some pages where you want to track goals or events. This will cause goals or events not to track.

  • Another person in your organization who is unfamiliar with Optimizely may change your configuration and cause side effects.

  • If you load Optimizely asynchronously, your analytics integrations may not function properly and you could see a "flicker" or "flash" effect, where the original page shows briefly before the variation loads. For these reasons, we recommend loading Optimizely outside of your tag manager, whenever possible.

 
Tip:

You can use your tag manager to deploy data layer events in Optimizely that you might normally place on your page, like custom event goals. Here's a great walkthrough from Trevor Fox.

  • If you're loading Optimizely and a tag manager on your site, we recommend loading Optimizely outside of your tag manager (especially if you're using Google Tag Manager).

    Place the Optimizely snippet at the top of the <head> tag of your site, then place your tag manager below the Optimizely snippet, just like you would normally place your analytics tags below Optimizely code.

    Here's an example:

    <head>
       <script type="text/javascript" src="//cdn.optimizely.com/js/12345678.js"></script>
    </head>
    <body>
       // Insert Tag Manager Code Here
    </body>