serkankaya.
Türkçe sürüm
Let’s work together ↗

Google Tag Manager Setup: A Step-by-Step GTM Guide

How to set up Google Tag Manager: create an account and container, add the code, set up the GA4 tag, use the dataLayer, preview and publish, step by step.

Google Tag Manager setup means creating a GTM account and web container, adding the container code to every page of the site, then setting up the first tag, testing it in preview mode and publishing. Adding the code is a short job; the real difference comes from writing down what you will measure before you add it and testing before you publish.

In this post I walk through the setup from the point of view of a software developer and performance marketer. I cover every step in order, from creating the account to where the code goes, from the GA4 tag to dataLayer events, and from preview to version management. If you are thinking about moving to server-side measurement, the web container is the first step there too; I explain the bigger picture in what is server-side tracking.

How does Google Tag Manager work?

Google Tag Manager is a management layer that loads every other tag through a single container code added to the site. By Google’s definition, a container is the collection of tags, triggers, variables and related settings installed on a site or app.[1] When you make a change in the GTM interface and publish it, the code on the site pulls the new configuration automatically.

To understand GTM, separating three concepts is enough:

  • Tag: Code that sends data to a platform. A GA4 tag, a Google Ads conversion tag or the Meta Pixel are all tags. A tag answers the question “what is sent?”
  • Trigger: The rule that decides under which condition a tag runs. A trigger answers the question “when is it sent?”
  • Variable: A field that supplies a value to a tag or trigger. The page URL, the clicked link or the order value are all variables.

Together, these three parts form the following flow:

Site (GTM code) Trigger Tag GA4, Ads, Meta
An event on the page runs a trigger, the trigger fires the tag, and the tag sends the data to the relevant platform.

This also explains the difference between GTM and gtag.js. gtag.js is a JavaScript library that sends data to Google products and is written directly into the code. GTM is a system that manages many tags, gtag.js included. For a single GA4 setup, gtag.js may be enough; when several platforms and events are measured, GTM makes maintenance clearly easier.

What should you prepare before the setup?

The most important thing to prepare before the setup is a short measurement plan. A measurement plan is a table that lists which events are sent on the site, with which parameters and to which platforms. Without this table, GTM slowly fills up with tags nobody can explain.

A simple measurement plan has these columns:

EventWhen?ParametersTarget platform
generate_leadWhen a form is submitted successfullyform_id, form_nameGA4, Google Ads, Meta
click_whatsappWhen the WhatsApp button is clickedpage_locationGA4, Meta
purchaseOn the order confirmation pagetransaction_id, value, currencyGA4, Google Ads, Meta

Beyond the plan, check three kinds of access in advance. You need access to the site code or the CMS panel. You need at least the Editor role on the GA4 property.[3] Finally, check whether the site already has hard-coded tags; adding the same tag to GTM without removing a GA4 tag written into the code leads to double counting.

How do you set up Google Tag Manager?

Short answer

How do you set up Google Tag Manager?

To set up Google Tag Manager, you first create an account and a Web container named after the site domain at tagmanager.google.com. Then you add the container code as high in the head tag as possible on every page, set up the first tag, test it in preview mode and publish it.

  1. Sign in with your Google account at tagmanager.google.com.
  2. Enter an account name and country to create a new account.
  3. Create a Web container with the site domain.
  4. Add the container code to the top of the head tag on every page.
  5. Define the first tag and trigger.
  6. Test in preview mode and publish with a version note.

The setup follows the order in Google’s own help pages. The steps below give that order together with small decisions that work in practice.

  1. Create an account

    At tagmanager.google.com, click Create Account on the Accounts tab. Use the company name as the account name. Google notes that one GTM account per company is usually enough.

  2. Create a web container

    Use the site main domain (for example www.example.com) as the container name and choose Web as the container type. One container per website is enough, not one per page.

  3. Add the code to the site

    Click the container ID that starts with GTM- in the workspace. If you use a CMS, choose the platform integration; otherwise copy the code by hand and paste it at the top of the head tag on every page.

  4. Verify the installation

    Enter the site address in the test field of the install dialog and run the test. Then confirm in preview mode, with Tag Assistant, that the container loads.

  5. Set up the first tag

    For GA4, add the Google tag or the Google Analytics destination, enter the measurement ID and set it to run on all pages.

  6. Test and publish

    Once you see the tag fire in preview, publish with the Submit button and add a version name and description.

How should the account and container structure look?

An account stands for the company; a container stands for a single website or app. According to Google’s help page, the container types are Web, iOS, Android, AMP and Server.[1] Using the top-level address of the site as the container name is recommended; you do not need a separate container for each page.

For a company with several brands, the structure is this: one GTM account and one Web container per domain. If the Turkish and English versions of the same site live on the same domain, one container for both languages keeps reporting and maintenance simple. Grant user permissions per person as well; give an agency or a freelancer the lowest permission they need rather than admin rights.

Where do you add the GTM code on a site?

The GTM code snippet goes on every page of the site, as high in the head tag as possible. Google’s current installation page shows the first code block pasted right after the opening <head> tag.[2] The earlier the code loads, the fewer visitors who leave quickly are missed.

The code shown in Google’s install dialog looks like this, with your container ID:

<head>
  <!-- Google Tag Manager -->
  <script async src="https://www.googletagmanager.com/gtm.js?id=GTM-AB12CDE"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
  </script>
  <!-- End Google Tag Manager -->
  <title>Page title</title>
</head>

Always copy the code from your own container’s install dialog; the example here only shows where it goes. In older setups you will also see the classic two-part code: a script in the head and a noscript iframe right after the opening body tag. Google’s help page still lists the previous code snippet separately; you do not need to tear down a working older setup just because the code changed.[2]

If the site runs on a ready-made platform, the method changes. On platforms such as WordPress, Shopify or Wix, the platform option in Google’s install dialog connects the container without adding code to each page by hand.[2] On a site you built yourself, adding the code once to the shared layout or template file is enough. In single-page applications (SPA), page transitions do not create a new page load; in that case you use the History Change trigger or a page view event pushed to the dataLayer.

How do you set up GA4 with GTM?

You set up GA4 with GTM by entering the measurement ID of the GA4 web data stream (the Tag ID that starts with G-) into a Google tag in GTM. According to Google’s help page, the Google tag loads the GA4 property on the page, sets the GA4 cookies, and sends automatically collected and enhanced measurement events.[3]

Google’s current help page presents a newer method called the Google Analytics Destination as the recommended path for this. With this method, settings are managed at the container level and less JavaScript is loaded on the page.[3] In the classic method, you create a Google tag and attach it to the “Initialization - All Pages” or “All Pages” trigger. Interface names change from time to time, so compare the option names in GTM with the help page as you go.

Set two rules for GA4 from the start. First, use a separate Google tag for each website; Google recommends this too.[3] Second, use Google’s recommended event names for events, so GA4 fills dimensions and metrics automatically. I explain which events should count as conversions in detail in GA4 conversion tracking.

How do you set up tags, triggers and variables?

The right order for setting up tags, triggers and variables is to define the variable first, then the trigger, and the tag last. This order stops you from hitting a missing value or condition when you save the tag. Some variables come built in with GTM; you need to enable variables such as Click URL, Click Text and Form ID from the Variables menu.

The choice of trigger decides how robust the measurement is. Here is the difference between two approaches that do the same job:

Click or form trigger

  • Quick to set up without touching code
  • Can break when button text or a CSS class changes
  • May also count failed form submissions
  • Suitable for simple sites and quick tests

Custom dataLayer event

  • Needs one line added by the developer
  • Not affected by design changes
  • Fires only on a successful submission
  • Suitable for conversion tracking and ad optimization
For events used as conversions, the dataLayer approach holds up better against interface changes.

The dataLayer is a JavaScript array that passes information from the page to GTM in a structured way. After a form is submitted successfully, the developer runs this line:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'generate_lead',
  form_id: 'contact',
  form_name: 'Contact form'
});

Three things are defined on the GTM side. First, a dataLayer variable is created for form_id. Next, a Custom Event trigger is created with the event name generate_lead. Finally, the GA4 event tag is attached to this trigger and form_id is sent as a parameter. Google’s dataLayer documentation covers the details of this structure.

The same event also acts as a trigger for Google Ads and Meta. I explain the Google Ads settings in Google Ads conversion tracking and the Meta side in Meta Pixel setup. Sending one event to several platforms makes the numbers comparable across platforms.

How do you preview and publish?

Preview is a test mode that runs the container draft as if it were published, only in your browser. According to Google, preview mode connects the site to Tag Assistant and shows which tag fired in which order; the debug interface is not visible to regular visitors.[4]

To open preview, you click the Preview button at the top right of the workspace. In the Tag Assistant tab that opens, you enter the site address and click Connect. As you browse the site, you see which tags ran for each event and which did not. Some sites can break because of the debug parameter added to the address; in that case you can untick the “Include debug signal in the URL” option.[4]

Once testing is done, you publish with the Submit button. Every publish creates a version record; a version is a snapshot of the container configuration at a given moment.[5] After a bad publish, going back to the previous version and publishing it again takes a few clicks. That is why you should not leave the version name and description empty; a description such as “Added GA4 generate_lead event” lets you find what changed and why months later.

GTM pre-publish checklist0/8

What are the most common setup mistakes?

The most common mistake in a Google Tag Manager setup is adding the same tag both to the site code and to GTM. This mistake creates double counting and inflates sessions in GA4 and conversions in Google Ads. Other common mistakes are these:

  • Adding the code only to the home page: The container code must be on every page. When thank-you and order confirmation pages are skipped in particular, conversions are not measured at all.
  • Measuring conversions with clicks: Clicking the “Submit” button does not mean the form was submitted successfully. Use the dataLayer or a thank-you page for the conversion event.
  • Publishing without testing: When the preview step is skipped, a faulty trigger can collect wrong data on every page of the site.
  • Piling up tags without limit: Unused tags slow the page down. I cover the speed side in page speed optimization.
  • Giving everyone admin rights: If access for a person or agency leaving the team is not removed, you lose control of the container.

Conclusion: the setup is done, what comes next?

A Google Tag Manager setup consists of creating the account and container, adding the code in the right place, setting up the first tag, and testing in preview before publishing. For a lasting measurement foundation, a measurement plan, dataLayer events, consent management and version discipline should be added to these steps.

Once the setup is complete, the logical next step is to connect conversion events to ad platforms and make sure the data is used in ad optimization. You can see how I plan measurement together with ad strategy on the performance marketing page, and my background on the about page.

Key terms

Google Tag Manager
Google Tag Manager is a free tag management system that lets you manage measurement and marketing tags on websites and apps from a single interface without changing code. Tags, triggers and variables are grouped inside a container.
Container
A container is the structure in Google Tag Manager that holds the tags, triggers and variables of one website or app together. Every container has a unique ID that starts with GTM- and is installed on the site once.
Trigger
A trigger is the rule in Google Tag Manager that decides under which condition a tag runs. A page view, a click, a form submission or a custom event pushed to the dataLayer can all act as triggers.
Workspace
A workspace is the draft environment in Google Tag Manager that holds unpublished changes. It lets several people work in the same container without affecting each other, and its changes become a version once published.
Tag Assistant
Tag Assistant is a debugging tool that shows whether Google tags fire correctly on a page. GTM's preview mode connects to Tag Assistant, where you can see which tag ran, in what order and with what data.

Frequently asked questions

Is Google Tag Manager free?

The standard version of Google Tag Manager is free and is enough for most websites. A paid version is also available for enterprises as part of Google Marketing Platform. The paid version adds management features such as approval workflows and more workspaces.

Where do you add the GTM code on a site?

According to Google's help page, the GTM code snippet goes as high in the page's head tag as possible. The code must be present on every page of the site. If you use a platform such as WordPress, Shopify or Wix, you can use the platform integration instead of adding code to each page by hand.

Does Google Tag Manager slow down a site?

GTM itself loads asynchronously and does not cause a serious slowdown on its own. The real source of slowdown is the number and weight of the tags added to the container. Removing unused tags and firing each tag only on the pages that need it keeps the performance impact low.

Why use Google Tag Manager if I already have GA4?

GA4 is an analytics tool, while GTM is a tag management system that manages all measurement tags, including GA4, from one place. With GTM you can add, test and roll back Google Ads, Meta Pixel and other tags through version history without touching the code.

How do I know the GTM setup works?

The most reliable way is to open Preview mode in GTM and connect to the site with Tag Assistant. Tag Assistant shows which tag fired and in what order. You then check in GA4's DebugView or the realtime report that the data arrives.

Sources

  1. Tag Manager Help: Create an account and container
  2. Tag Manager Help: Install a web container
  3. Tag Manager Help: Set up Google Analytics in Tag Manager
  4. Tag Manager Help: Preview and debug containers
  5. Tag Manager Help: Publishing, versions, and approvals