Move Google Analytics tracking code from footer to head tag

Google has stated the tracking code should go at the top of the head tag since they introduced the asynchronous code in 2009. The field found in the settings load the tracking code in the bottom of the page code. The asynchronous code does not slow the page load like previous versions of their tracking code, which was the main reason it was moved to the footer in the past. There is a high possibility on pages that have a lot of JavaScript for the tracking not to run, the lower in the code is loaded, and therefore should be loaded as high as possible in the head.

  • Eric Cox
  • Jun 25 2019
  • Reviewed: Voting Open
  • Attach files
  • Eric Cox commented
    1 Jul, 2019 12:47pm

    Yes, I am aware of that, but at the same time it should be moved to keep in line with Google's standards (for the built in 'Settings' option). I will be removing it from the settings and using a part to put it there as a workaround.

  • Chris Kastner commented
    1 Jul, 2019 12:59am

    You can do this by pasting your tracking code into an Unformatted Text part, checking the "advanced options" box at the bottom, then choosing to display the part in the page <head> tag.  Then simply place this part onto each Template you're using and it will render on each page.  This will add the code towards the end of the <head> tag but should still be okay for GA or GTM.

  • +1