Skip to main content

Google Tag Manager

Google Tag Manager (GTM) enables you to run and manage fragments of client-side code on a website. It provides a way to abstract third-party integrations away from the core front-end code of the site itself and approach things in a consistent way across a variety of web properties.

GTM is based around the idea of 'containers' - essentially wrappers for running code snippets ('tags') when certain conditions are met ('triggers'), picking up variables from the website (usually via the data layer) as necessary.

There are two types of GTM 'container'.

  • Web: This is the traditional form of GTM, where all of the managed code executes on the client browser or device and information is passed directly to third-party clients like Google Analytics or Facebook. Official documentation.

  • Server-Side: This is a newer approach in which the container executes on a server application running on your own Google Cloud Platform. As summarised by Simo Ahava in his server side tagging post "the purpose of this setup is to create an endpoint in a server environment that you own. It will act as a sort of a proxy between the hits sent from browsers and devices and the actual endpoints to which the hits are collected." Official documentation.

Site developers / team members will never be directly involved with the server-side container

When implementing GTM, you do not choose between these two types of containers. Every website that uses GTM will only be concerned with a Web container.

We have 3 managed server side containers, owned and maintained by Frontend Enablement (FEDE). These containers 'claim' requests from certain web containers, and decide what happens to the data before anything is passed on to a third party, which brings great advantages in privacy and security. Using a server-side container means we are unambiguously the 'data controller' as defined in GDPR legislation. However it isn't logistically possible to do this for all the hundreds of web domains we have, so only the largest and most important domains are configured to run this way.

The following domains are currently set up in our tagging servers:

sgtm.biomedcentral.com
sgtm.nature.com
sgtm.springer.com
sgtm.springernature.com

Your GTM Container ID and GA Measurement ID need to be manually added to the server side GTM container. This is because the server-side GTM has a whitelist of containers that it will claim requests from.

If you believe your GTM container should be utilising one of our managed server side containers, please contact Frontend Enablement

How to use web containers

A big problem in the past has been a the number of containers that exist. These containers often shared the same code, and often differed only very slightly from another. This is a maintainence nightmare, because if a tag needs updating, that has to be done everywhere and a central role that handles such updates doesn't exist, so containers very quickly diverge.

Often, containers can be shared across many sites. The key to this is using the dataLayer to define any data that is needed to differentiate one site from another. For example, a dataLayer property of measurementId means that the container can have a single GA4 configuration tag with the measurement ID field set to the dataLayer variable.

However, if the data layer is not used for differentiating one site from another, and instead, conditional logic is added to code inside the container, then the benefit of sharing containers is almost completely lost. Lookup tables can be useful here, but there is a tipping point where a shared container becomes unwieldy.

What we don't want happening is using logic within the container that says something like, if the hostname contains x, fire tag a, otherwise fire tag b. This is bad, because it means there are tags within the container that are totally irrelevant for some sites. Those tags will still load onto the page with GTM and so there is an unneccessary performance cost here. Furthermore, this sort of logic can very quickly make containers prone to breakages and become extremely hard to understand and debug.

Is there a container I should use?

The best thing to do is to ask in the Ask Frontend Enablement Teams channel. We can then advise whether an existing container is available.

If there is no existing container that is appropriate, we can create a new container, and add Consent Mode and any basic tags you require, before handing over ownership.

Adding GTM to your website

Examples of how to add GTM to your site can be found on the CMP installation page.