Does it Make Sense to Insert the Google Content Experiements Tag after <meta> tags?

76 views Asked by At

Google instructs us to put the Content-Experiments JavaScript immediately after the <head> tag.

Does it make sense to actually insert it a little later than that, such as after some key compatibility <meta> tags, like:

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge;" />
  <!-- Other important tags? -->
  <!-- Google Analytics Content Experiment code -->
  ...

... or is it totally and absolutely best to put the JavaScript above all else?

3

There are 3 answers

0
starlocke On BEST ANSWER

I found a specific case where it is actually very important to place the Google Analytics Content Experiments stuff AFTER certain <meta> tags.

I use a "dynamically triggered" Content Experiments, and thus, leave a great big JS block at the top. However, that block MUST come after <meta http-equiv="X-UA-Compatible" content="IE=edge" /> (or whatever IE version you like). The consequence of having Content-Exp after the <meta> tag is that IE will drop down to old-school corporate compatibility mode (IE7 behaviour) when navigating to websites that are incorrectly believed to be part of the Local Intranet zone.

0
nyuen On

This should be fine, so long as it's not nested within any other tags. It's the same case with the GTM snippet - ideally it should come immediately after the <body>, but often there are other meta tags the come before (and that may be loaded dynamically). Just make sure you validate the code after you've pasted it in on your site.

0
Eike Pierstorff On

Google instructs you do place the experiment snippet as early as possible in the page because content experiments redirect to the variation pages. If you load assets before the experiment code there might be an unpleasant delay before the redirect starts.

I can for the love of my life not image that meta-tags would delay a js redirect, so you should be fine. I image Google found it easier to say "always on top" than "always on top except for tags that do not delay javascript executions (such as e.g. meta tags)".

Having said that, there is no benefit from having meta tags first, so you might as well put the experiment code first.