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­nif­i­cant­ly sim­pli­fies in­te­grat­ing different codes.

Key Takeaways

Google Tag Manager (GTM) manages tracking and analytics tags centrally through a single container snippet.

  • Changes are made in the GTM interface without touching the source code
  • The core com­po­nents are tags, triggers, and variables
  • The data layer passes struc­tured event data
  • GTM supports server-side tagging and Consent Mode v2

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­vid­ual 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 analyze and evaluate user behaviour on your website to improve your UX. Orig­i­nal­ly, 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­mar­ket­ing, affiliate, and con­ver­sion tags
  • In­te­gra­tions for consent man­age­ment platforms (CMP)
  • Testing tools or per­son­al­iza­tion solutions
  • Custom JavaScript tags

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

  • im­ple­ment­ing Google Analytics 4 (GA4),
  • in­te­grat­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.

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­ver­tis­ing 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­cess­ing 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­vi­ron­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­for­ma­tion and then forwards it to the relevant target platforms in a con­trolled way. This model offers several ad­van­tages:

✓ Greater data control: You decide which pa­ra­me­ters are passed on to external services.

✓ More flexible data pro­cess­ing: 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 foun­da­tion for privacy and consent logic: Sensitive in­for­ma­tion can be anonymized or removed before it is forwarded.

However, server-side tagging does not au­to­mat­i­cal­ly 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­cial­ly in e-commerce or per­for­mance 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­po­nents 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­u­ra­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­for­ma­tion is sent to which services. Func­tion­al­ly, a tag cor­re­sponds 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­mar­ket­ing tags
  • Consent ini­tial­iza­tion tags
  • Custom HTML or JavaScript 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­vid­ual events such as page_view, add_to_cart, or purchase, which are triggered via cor­re­spond­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­cient­ly map complex tracking logics.

Variables

Variables provide the dynamic values that tags and triggers need. They access in­for­ma­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, cart 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 JavaScript variables,
  • consent status variables.

Data layer for struc­tured data transfer in modern tracking

The data layer is a JavaScript data structure, usually an array, that acts as the central interface between your website and Google Tag Manager. It passes struc­tured in­for­ma­tion to the container. Google Tag Manager con­tin­u­ous­ly “listens” for new entries in the data layer and responds with the cor­re­spond­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­for­ma­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: "USD"
});
javascript

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, cart values, trans­ac­tions)
  • Lead tracking (form sub­mis­sions with con­tex­tu­al data)
  • Consent status transfer
  • Custom events
  • Per­son­al­iza­tion logic

Google Consent Mode is a global feature that lets Google services adjust their behaviour based on a user’s consent choices. Consent decisions are trans­mit­ted to Google at a technical level, and tags fire in full, in a limited way, or not at all depending on what the user has agreed to. Before consent is granted, only limited, non-per­son­al­ized signals are processed; full tracking activates once the relevant consent is in place.

In Canada, no law requires you to use Consent Mode. However, privacy law does shape how you handle consent: under the federal Personal In­for­ma­tion Pro­tec­tion and Elec­tron­ic Documents Act (PIPEDA), or­ga­ni­za­tions generally need to obtain mean­ing­ful consent for col­lect­ing, using, and dis­clos­ing personal in­for­ma­tion, and Quebec’s Law 25 is stricter: if you collect personal in­for­ma­tion with tech­nol­o­gy that can identify, locate, or profile users, such as ad­ver­tis­ing and re­mar­ket­ing cookies, you must tell users about it first, and those functions must be switched off by default until the user actively turns them on. Which rules apply to your site depends on your business and where your users are. Consent Mode is a technical tool that helps you pass users’ consent choices on to Google services, and many busi­ness­es implement it vol­un­tar­i­ly, both to support com­pli­ance and because it improves con­ver­sion mea­sure­ment when cookies are re­strict­ed by browsers like Safari and Firefox.

Consent Mode v2 in­tro­duced two ad­di­tion­al consent signals that indicate whether personal ad­ver­tis­ing data may be processed and whether per­son­al­ized ads may be served:

  • ad_user_data
  • ad_personalization

What are the ad­van­tages of Google Tag Manager?

Google Tag Manager is now much more than a con­ve­nient tool for managing tracking snippets. In modern tracking setups, it plays a central role in data control, privacy man­age­ment, and per­for­mance op­ti­miza­tion. The most important ad­van­tages include:

Advantage De­scrip­tion
Central tag man­age­ment ✓ Analytics, marketing, and con­ver­sion tags can be con­fig­ured, tested, and published through a single interface
✓ Changes can be made without re­peat­ed­ly editing the source code
Greater in­de­pen­dence from IT ✓ Marketing and analytics teams can adjust tags in­de­pen­dent­ly
Con­ve­nient 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­te­gra­tion with Consent Mode v2 ✓ Tags can be fired or blocked depending on consent status
✓ In­te­gra­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­i­bil­i­ty ✓ Numerous third-party tags and testing tools can be in­te­grat­ed
Asyn­chro­nous in­te­gra­tion ✓ Tags load in­de­pen­dent­ly 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 stan­dard­ized way
rank­ing­Coach
Boost sales with AI-powered online marketing
  • Improve your Google ranking without paying an agency
  • Reply to reviews and generate social media posts faster
  • No SEO or online marketing skills needed

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­te­grat­ed 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­te­grat­ed via a plugin or theme.

Step 3: Create the Google tag

When con­fig­ured ac­cord­ing­ly, the Google tag can au­to­mat­i­cal­ly 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 Mea­sure­ment ID ready. You can find it in your Google Analytics account in the format G-XXXXXXXXXX.

Note

The Mea­sure­ment ID cor­re­sponds to the des­ti­na­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­u­ra­tion section, select the tag type “Google tag” and enter your Mea­sure­ment ID.
  2. In the Trigger section, select “Ini­tial­iza­tion – All Pages.”
  3. Name the newly created tag; in this example, we use “GA4 Con­fig­u­ra­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­for­ma­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 “rec­om­mend­ed events,” which you must activate yourself but which already have a name and pre­de­fined variables. If you want to track a rec­om­mend­ed event, you need to set up a cor­re­spond­ing GA4 event tag.

Note

The Google tag forms the basis for GA4 tags: It loads first and es­tab­lish­es 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­u­ra­tion.

Rec­om­mend­ed events include the GA4 event generate_lead, for example. This event records user behaviour using pre­de­fined pa­ra­me­ters. 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 rec­om­mend­ed event name and the as­so­ci­at­ed pa­ra­me­ters, 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­fig­ured 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 mea­sure­ment ID. If you have not yet created a Google tag for this mea­sure­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 rec­om­mend­ed 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­fig­ured generate_lead tag

Google Consent Mode is worth setting up even though no Canadian law requires it. If you use Google Analytics 4 or Google Ads and rely on per­son­al­ized ad­ver­tis­ing, con­ver­sion tracking, or re­mar­ket­ing, Consent Mode v2 helps you honour user choices and supports com­pli­ance with Canadian privacy re­quire­ments such as PIPEDA and, if you have users in Quebec, Law 25. It also improves mea­sure­ment accuracy when browsers like Safari and Firefox restrict cookies. (If your site also reaches users in the EEA, the UK, or Switzer­land, Google’s EU user consent policy requires you to obtain their consent and pass consent signals to Google, for example via Consent Mode v2, in order to keep using per­son­al­ized ad­ver­tis­ing and re­mar­ket­ing there. A stricter opt-in standard applies in these regions.)

Google Consent Mode sends consent in­for­ma­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. Implement a CMP: First, you need a consent banner (cookie banner) that captures users’ choices. 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. Set the defaults to match the privacy re­quire­ments that apply to your audience. Where users must switch tracking on them­selves, as under Quebec’s Law 25 for tech­nolo­gies that can identify, locate, or profile users, the affected consent types should default to “denied” until a user has agreed. You set this up with a Consent Ini­tial­iza­tion tag (often via a CMP template) that fires with the “Consent Ini­tial­iza­tion – All Pages” trigger.
  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­ized ad­ver­tis­ing ad­di­tion­al­ly require ad_user_data and ad_personalization
Image: Configured user consent for a GA4 tag
Con­fig­ured 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­u­ra­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­u­ra­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­u­ra­tions have not yet been set, you will see a cor­re­spond­ing message at the bottom of the window.
Image: GTM container publication
Before pub­li­ca­tion, GTM indicates that a tag has not yet received consent con­fig­u­ra­tions.
  1. If no tags need to be revised, click “Publish.” Your changes are now live.

Reviewer

Go to Main Menu