title: How high in the <head> section can you safely put the Google Tag Manager code?
body: <p>Google Tag Manager instructs developers to:</p>
  
  <blockquote>
    <p>Paste this code [THE TRACKING CODE] as <strong><em>high</em></strong> in the <code>&lt;head&gt;</code> of the page
    as possible:</p>
    
    <p><code>&lt;!-- Google Tag Manager --&gt;
    &lt;script&gt;(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new
    Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&amp;l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-XXXXXXX');&lt;/script&gt; &lt;!--
    End Google Tag Manager --&gt;</code></p>
  </blockquote>
  
  <p>My question is, how high can that code be properly placed?  Properly meaning, able to function on >95% of browsers without issues/warnings/errors, and/or according to HTML best practices.</p>
  
  <p>Can it go right after the opening <code>&lt;head&gt;</code> tag? Does it really matter as long as it is in the <code>&lt;head&gt;</code> section somewhere?</p>
  
  <p>For reference/example, below is the HTML boilerplate.  What's the best spot for the tracking code in the boilerplate?</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html class="no-js" lang=""&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;meta http-equiv="x-ua-compatible" content="ie=edge"&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;meta name="description" content=""&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  
          &lt;link rel="manifest" href="site.webmanifest"&gt;
          &lt;link rel="apple-touch-icon" href="icon.png"&gt;
          &lt;!-- Place favicon.ico in the root directory --&gt;
  
          &lt;link rel="stylesheet" href="css/normalize.css"&gt;
          &lt;link rel="stylesheet" href="css/main.css"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;!--[if lte IE 9]&gt;
              &lt;p class="browserupgrade"&gt;You are using an &lt;strong&gt;outdated&lt;/strong&gt; browser. Please &lt;a href="https://browsehappy.com/"&gt;upgrade your browser&lt;/a&gt; to improve your experience and security.&lt;/p&gt;
          &lt;![endif]--&gt;
  
          &lt;!-- Add your site or application content here --&gt;
          &lt;p&gt;Hello world! This is HTML5 Boilerplate.&lt;/p&gt;
          &lt;script src="js/vendor/modernizr-{{MODERNIZR_VERSION}}.min.js"&gt;&lt;/script&gt;
          &lt;script src="https://code.jquery.com/jquery-{{JQUERY_VERSION}}.min.js" integrity="{{JQUERY_SRI_HASH}}" crossorigin="anonymous"&gt;&lt;/script&gt;
          &lt;script&gt;window.jQuery || document.write('&lt;script src="js/vendor/jquery-{{JQUERY_VERSION}}.min.js"&gt;&lt;\/script&gt;')&lt;/script&gt;
          &lt;script src="js/plugins.js"&gt;&lt;/script&gt;
          &lt;script src="js/main.js"&gt;&lt;/script&gt;
  
          &lt;!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. --&gt;
          &lt;script&gt;
              window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;
              ga('create','UA-XXXXX-Y','auto');ga('send','pageview')
          &lt;/script&gt;
          &lt;script src="https://www.google-analytics.com/analytics.js" async defer&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>