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

Snippet placement best practices

Pro tips for the best Optimize performance.

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