Advanced GTM container implementation

All you have to do to implement the Google Tag Manager container code is enter the Container ID and click save.

However, you have some options to customize the implementation which may be relevant to you. The container code is always placed in the <head> section but you have the option to delay the exceution of the container code.

Why would you do that? Because it may increase the pagespeed but that is not always the case.

The whole idea behind delaying the container code is that when loading af new page the browser is buzy generating the page. Some things are visible to the user and sometings are not. Anything that is not important to be active instantly can be delayed, which will make room for things like generating visual elements.

GTM container code

You have 2 options for delaying the load of the container code. The first option is when the browser fires the requestIdleCallback event, which is fired when the browser is not buzy. The second opttion is the requestIdleCallback event plus 2 seconds.

If it is important for you to measere load times in Google Analytics or anything else that requires instant activity you should not delay the container load.

Whether the delay improves the perceived or measured load speed depends entirely on your website so test it!

sGTM – Server Side Tracking

Server Side Tracking is “the new black” that everyone is talkeing about and GTM Kit is supporting it. If you follow Google’s guide on how to setup server-side tagging you can create your own server-side container and then you must specify your custom GTM Server Side Domain as shown below:

GTM server side

If you customise you server-side container you can also change the sGTM container identifer. If you enter dafsj3j3jkd the container script will request dafsj3j3jkd.js instead of gtm.js