If you integrate external services into your web project, you normally have to juggle a large number of code snippets. In addition to requiring some pro­gram­ming know-how, this also demands a high level of oversight. To address this, Google released Google Tag Manager a few years ago, which sig­ni­fic­antly sim­pli­fies in­teg­rat­ing different codes.

What is Google Tag Manager?

The Google Tag Manager (GTM) is a web-based tag man­age­ment system from Google that lets you centrally manage tracking, marketing, and analytics tags without having to modify the source code directly every time you make a change. Instead of manually inserting in­di­vidu­al snippets into your website or app, you control all tags through a single interface and publish versioned changes with just a few clicks. With these tags, you can analyse and evaluate user behaviour on your website to improve your UX. Ori­gin­ally, GTM was primarily intended for Google services like Google Analytics or Google Ads, but today it supports a wide range of third-party tags, including:

  • Tracking, re­market­ing, affiliate, and con­ver­sion tags
  • In­teg­ra­tions for consent man­age­ment platforms (CMP)
  • Testing tools or per­son­al­isa­tion solutions
  • Custom JavaS­cript tags

In today’s tracking landscape, Google Tag Manager plays a central role in:

  • im­ple­ment­ing Google Analytics 4 (GA4),
  • in­teg­rat­ing con­ver­sion tracking for Google Ads,
  • setting up Consent Mode v2,
  • enabling server-side tracking with server-side tagging,
  • using a struc­tured data layer to pass event and e-commerce data.
Google Ads Man­age­ment Service
Search engine ad­vert­ising services
  • Our experts run your campaign
  • Increase your online vis­ib­il­ity
  • Save money thanks to greater ef­fi­ciency

How does Google Tag Manager work exactly?

Google Tag Manager (GTM) acts as a central control unit for tracking and marketing tags. After you add a container snippet to your website’s source code once, this connects your site to the GTM platform. All ad­di­tion­al tracking codes are no longer embedded directly in the HTML code, but are managed in the container via the tag manager’s web-based interface.

In Google Tag Manager, you create tags that send specific data to analytics or ad­vert­ising platforms. Triggers define when these tags fire, such as when someone views a page, clicks a button, or submits a form. You can test changes first and then publish them as a new container version. This allows you to adjust tracking flexibly without editing the source code each time.

Sensible data pro­cessing using server-side tagging

In addition to the classic web container, Google Tag Manager also supports server-side tagging. This requires an ad­di­tion­al container of the ‘Server’ type, which does not run in the browser but on a dedicated server or in a cloud en­vir­on­ment.

Unlike tra­di­tion­al client-side tracking, events are not sent directly from the browser or web container to third-party services such as Google Analytics or Google Ads. Instead, the data is first sent to your own server endpoint. The server container processes this in­form­a­tion and then forwards it to the relevant target platforms in a con­trolled way. This model offers several ad­vant­ages:

✓ Greater data control: You decide which para­met­ers are passed on to external services.

✓ More flexible data pro­cessing: Event data can be filtered, adjusted, or enriched on the server side.

✓ More robust data col­lec­tion: Because fewer third-party scripts run directly in the browser, tracking can be less affected by ad blockers and browser re­stric­tions.

✓ Better found­a­tion for privacy and consent logic: Sensitive in­form­a­tion can be an­onymised or removed before it is forwarded.

However, server-side tagging does not auto­mat­ic­ally replace legal re­quire­ments such as consent prompts. Even in server-side setups, consent decisions must be taken into account and processed correctly. For smaller websites, a classic web container is usually suf­fi­cient. For larger, data-driven projects, es­pe­cially in e-commerce or per­form­ance marketing, server-side tagging can be an important building block of a modern tracking ar­chi­tec­ture.

Tags, triggers, and variables in Google Tag Manager

For the container to correctly capture the desired events, in­ter­ac­tions, and states and forward them to analytics, marketing, or third-party services, three core com­pon­ents work together in Google Tag Manager: tags, triggers, and variables. GTM provides numerous templates for all three elements. You can also use custom con­fig­ur­a­tions or custom code. The following brief overviews explain exactly what roles tags, triggers, and variables play.

Tags

Tags are the central control units in Google Tag Manager. They define which in­form­a­tion is sent to which services. Func­tion­ally, a tag cor­res­ponds to a tracking or marketing snippet, but instead of being embedded directly in the source code, it is managed centrally in the container. Typical tag types include:

  • Google tags
  • Google Ads con­ver­sion tags
  • Re­market­ing tags
  • Consent ini­tial­isa­tion tags
  • Custom HTML or JavaS­cript tags
  • Server-side for­ward­ing tags (for server con­tain­ers)

Unlike older tracking ar­chi­tec­tures, modern GA4 setups with Google Tag Manager work entirely event-based. This means that instead of only measuring page views, you define in­di­vidu­al events such as page_view, add_to_cart, or purchase, which are triggered via cor­res­pond­ing tags.

Triggers

Triggers determine when a tag is fired. In other words, triggers are specific events or user in­ter­ac­tions with the web project that should cause code to execute. Typical triggers include:

  • Page views
  • Clicks on buttons or links
  • Form sub­mis­sions
  • Scroll depth
  • Custom events from the data layer
  • Specific consent statuses

In addition, triggers can be combined with con­di­tions, for example:

  • Only on specific URLs,
  • Only for specific element classes,
  • Only when ad consent is active.

A trigger can be assigned to multiple tags, which makes it possible to ef­fi­ciently map complex tracking logics.

Variables

Variables provide the dynamic values that tags and triggers need. They access in­form­a­tion available when a page loads or when an event occurs. In practice, variables help refine trigger con­di­tions. For example, a trigger can define that a tag should fire on a page view, while a variable can specify exactly which page or URL this should apply to.

In an e-commerce context, product IDs, basket values, or trans­ac­tion IDs can be read via data layer variables and passed on to GA4 or other systems. Common types of variables include:

  • built-in variables, such as URL, click ID, or referrer,
  • data layer variables,
  • custom JavaS­cript variables,
  • consent status variables.

Data layer for struc­tured data transfer in modern tracking

The data layer is a JavaS­cript data structure, usually an array, that acts as the central interface between your website and Google Tag Manager. It passes struc­tured in­form­a­tion to the container. Google Tag Manager con­tinu­ously ‘listens’ for new entries in the data layer and responds with the cor­res­pond­ing triggers and tags. When specific actions occur on your website, such as a purchase, a click, or a form sub­mis­sion, you can ‘push’ the relevant in­form­a­tion into the data layer.

In practice, this can look as follows. A person completes a purchase on your website. The website then writes struc­tured data into the data layer:

dataLayer.push({
  event: "purchase",
  transaction_id: "T12345",
  value: 99.99,
  currency: "GBP"
});
javas­cript

Google Tag Manager detects the purchase event and then activates a defined trigger that fires a tag to track the user’s in­ter­ac­tion. Typical use cases for the data layer include:

  • E-commerce tracking (product data, basket values, trans­ac­tions)
  • Lead tracking (form sub­mis­sions with con­tex­tu­al data)
  • Consent status transfer
  • Custom events
  • Per­son­al­isa­tion logic

Since 2024, Consent Mode v2 has been required in the EU/EEA and the UK for companies that use Google Ads or Google Analytics 4 and want to run per­son­al­ised Google ads. Consent decisions must be trans­mit­ted to Google correctly at a technical level. Google Consent Mode allows Google services to be used even before full user consent has been granted. In this case, only limited, non-per­son­al­ised signals are processed. Full tracking may only be activated once the relevant consent has been given.

Consent Mode v2 therefore includes two ad­di­tion­al consent signals that indicate whether personal ad­vert­ising data may be processed and whether per­son­al­ised ads may be served:

  • ad_user_data
  • ad_personalization

Google Tag Manager takes over the technical control in this context and ensures that tags are correctly fired or blocked depending on the re­spect­ive consent status.

What are the ad­vant­ages of Google Tag Manager?

Google Tag Manager is now much more than a con­veni­ent tool for managing tracking snippets. In modern tracking setups, it plays a central role in data control, privacy man­age­ment, and per­form­ance op­tim­isa­tion. The most important ad­vant­ages include:

Advantage De­scrip­tion
Central tag man­age­ment ✓ Analytics, marketing, and con­ver­sion tags can be con­figured, tested, and published through a single interface
✓ Changes can be made without re­peatedly editing the source code
Greater in­de­pend­ence from IT ✓ Marketing and analytics teams can adjust tags in­de­pend­ently
Con­veni­ent testing and debugging ✓ Preview mode, the debug console, and struc­tured error messages make quality assurance easier
Ver­sion­ing and access control ✓ Work­spaces, change history, and role-based access support con­trolled teamwork
Consent in­teg­ra­tion with Consent Mode v2 ✓ Tags can be fired or blocked depending on consent status
✓ In­teg­ra­tion with consent man­age­ment platforms is possible
Support for server-side tracking ✓ Web and server con­tain­ers allow con­trolled data for­ward­ing via your own server endpoints
High tool com­pat­ib­il­ity ✓ Numerous third-party tags and testing tools can be in­teg­rated
Asyn­chron­ous in­teg­ra­tion ✓ Tags load in­de­pend­ently of the main content and generally do not block the page
Struc­tured data transfer via the data layer ✓ Events and e-commerce data can be passed on in a stand­ard­ised way

How to use Google Tag Manager for your own web project

How do you implement Google Tag Manager? Google Tag Manager is free and web-based, so you do not need to install any software. The only re­quire­ment is a valid Google account. If you already use services such as Gmail or Google Drive, you already have one. Otherwise, you first need to create a Google account.

The following tutorial explains how to use Google Tag Manager for your own web project, create a web container, and integrate Google Analytics 4.

Step 1: Set up a Google Tag Manager account and create a container

  1. Go to the official Google Tag Manager website.
  2. Sign in with your Google account.
  3. Click ‘Create Account’.
  4. Enter an account name (e.g., company name) and the country.
  5. Assign a container name (e.g., domain name) and select the target type. For tra­di­tion­al websites, choose ‘Web’.
  6. Click ‘Create’ and accept the terms of service.

Google now creates the container. Typically, each website uses its own dedicated container.

Step 2: Add the Google Tag Manager container snippet

It may take a moment for Google Tag Manager to create the container. Once the process is complete, Google Tag Manager displays two GTM container code snippets. Add them as follows:

  1. Copy and paste the first container code into the <head> section of your pages.
  2. Copy and paste the second container code into the <body> section.
Image: Google Tag Manager: Container code snippets for your website
Only after you have in­teg­rated the Google Tag Manager snippet into your web project can you configure tags.
Tip

If you use a content man­age­ment system like WordPress, the container snippet can often be in­teg­rated via a plugin or theme.

Step 3: Create the Google tag

When con­figured ac­cord­ingly, the Google tag can auto­mat­ic­ally track page views, scrolling, outbound link clicks, site search, video en­gage­ment, and file downloads. To set up the Google tag, have your GA4 Meas­ure­ment ID ready. You can find it in your Google Analytics account in the format G-XXXXXXXXXX.

Note

The Meas­ure­ment ID cor­res­ponds to the des­tin­a­tion ID used in Google Analytics 4.

Here’s how to set up the Google tag:

  1. In Google Tag Manager, go to ‘Overview’ and select the ‘Add a new tag’ option.
Image: Google Tag Manager: Create a new tag
In the Google Tag Manager workspace, you can set up new tags.
  1. In the Tag Con­fig­ur­a­tion section, select the tag type ‘Google tag’ and enter your Meas­ure­ment ID.
  2. In the Trigger section, select ‘Ini­tial­iz­a­tion – All Pages’.
  3. Name the newly created tag; in this example, we use ‘GA4 Con­fig­ur­a­tion Tag’, and then save the tag.
Image: Overview of existing tags in Google Tag Manager
In the ‘Tags’ menu item, you can view the tags you have set up.

Step 4: GA4 event tags

In addition to the in­form­a­tion that the Google tag measures for you (page views, scrolling, clicks on outbound links, site search, video en­gage­ment, and file downloads), you can also collect other data about user behaviour. For this purpose, Google provides so-called ‘re­com­men­ded events’, which you must activate yourself but which already have a name and pre­defined variables. If you want to track a re­com­men­ded event, you need to set up a cor­res­pond­ing GA4 event tag.

Note

The Google tag forms the basis for GA4 tags: It loads first and es­tab­lishes the con­nec­tion to GA4. The GA4 event tags then run af­ter­wards to send detailed usage data based on the Google tag con­fig­ur­a­tion.

Re­com­men­ded events include the GA4 event generate_lead, for example. This event records user behaviour using pre­defined para­met­ers. Using generate_lead as an example, the following steps show how to activate GA4 event tags in Google Tag Manager.

To activate a GA4 event tag, you first need to identify the right trigger. GA4 specifies the re­com­men­ded event name and the as­so­ci­ated para­met­ers, but not the trigger that starts the trans­mis­sion of the event-specific data. For the generate_lead event, the key question is therefore what technical action creates a lead in your web project? The answer depends on the project. Google Tag Manager offers several suitable options.

In our example web project, a button click serves as the trigger for the generate_lead event. To set up the tag correctly, follow these steps:

  1. In the side menu, open the ‘Triggers’ section and click ‘New’.
  2. Select the trigger type ‘Click – All Elements’.
  3. Give the trigger a name. In this example, we use ‘Button-Click-Trigger’.
  4. Save the newly created trigger.
Image: Overview of configured triggers
You can view fully con­figured triggers in the workspace under the ‘Triggers’ menu item.
  1. In the Google Tag Manager side menu, open ‘Tags’ and click ‘New’ to create a new tag of the type ‘Google Analytics: GA4 Event’.
  2. Enter your meas­ure­ment ID. If you have not yet created a Google tag for this meas­ure­ment ID container, as described in step 3, the system will detect this and display a note.
  3. In the ‘Event Name’ field, enter the name of the re­com­men­ded event. In this example, this is generate_lead.
  4. Select the trigger you created earlier as the firing condition.
  5. Give the new tag a name, such as ‘generate_lead tag’, and save it.
Image: generate_lead tag in the view
View of the fully con­figured generate_lead tag

If you use Google Analytics 4 or Google Ads and rely on per­son­al­ised ad­vert­ising, con­ver­sion tracking, or re­market­ing, you must enable Google Consent Mode v2 to obtain explicit user consent for certain tracking and ad­vert­ising activ­it­ies. This re­quire­ment applies if your site reaches users in the EU/EEA, the UK, or Switzer­land—in the UK it is un­der­pinned by UK GDPR and PECR, which likewise require prior opt-in consent for ad­vert­ising and most other non-essential cookies (limited ex­cep­tions apply, for example for certain stat­ist­ic­al cookies). Google Consent Mode sends consent in­form­a­tion to Google services and runs tags, depending on the consent status, either:

  • in full,
  • in a limited way,
  • or blocks tags entirely.

To set up Consent Mode v2, proceed as follows:

  1. Im­ple­ment­a­tion of a CMP: First, you need a consent banner (cookie banner) that asks users for their approval. This is done via a Consent Man­age­ment Platform (CMP). Your CMP must support Consent Mode v2 and have it enabled.
  2. Prepare Google Tag Manager: In Google Tag Manager, go to ‘Admin’ and enable the ‘Consent Overview’ in the ‘Container Settings’. After that, you can manage consent settings for your tags.
  3. Set default consent: Before users make a choice, a default value has to be set. In the EU/EEA and UK, this is usually all consent types set to ‘denied’. To do this, you set up a Consent Ini­tial­isa­tion tag (often via a CMP template) that fires with the ‘Consent Ini­tial­iz­a­tion – All Pages’ trigger. This ensures that no full tracking starts before consent is given.
  4. Adjust tags: Review your existing tags (e.g., GA4 or Google Ads) in the ‘Consent Settings’ section for the required consents:
  • GA4 tags require analytics_storage
  • Google Ads tags require ad_storage
  • Tags for per­son­al­ised ad­vert­ising ad­di­tion­ally require ad_user_data and ad_personalization
Image: Configured user consent for a GA4 tag
Con­figured user consent setting for a GA4 tag

Step 6: Test the setup and Google tags (Tag Assistant)

Once you have fully set up your container, you should review your con­fig­ur­a­tions before pub­lish­ing:

  1. In the Google Tag Manager workspace, click ‘Preview’ in the top right corner.
  2. Enter your website URL.
Image: GTM Tag Assistant
To start preview mode, you need to enter the website URL.
  1. Tag Assistant opens. Check the following: Was the GA4 Con­fig­ur­a­tion tag fired? Are events being sent correctly? Are consent rules being respected?

Step 7: Publish the container

If all tests are suc­cess­ful and you want to make your changes live, you can carry out the final step:

  1. In the Google Tag Manager workspace, click ‘Submit’.
  2. Select ‘Publish and Create Version’.
  3. Assign a version name. If there are tags whose consent con­fig­ur­a­tions have not yet been set, you will see a cor­res­pond­ing message at the bottom of the window.
Image: GTM container publication
Before pub­lic­a­tion, GTM indicates that a tag has not yet received consent con­fig­ur­a­tions.
  1. If no tags need to be revised, click ‘Publish’. Your changes are now live.

Reviewer

Go to Main Menu