Digital Marketing

How to Set Up Google Tag Manager for Website Tracking

Why I start every Google Tag Manager setup with a measurement plan

The easiest part of a Google Tag Manager setup is pasting the container snippet into a website. The difficult part comes later, when you are trying to explain why one order became two purchases, or why a form button click appears as a lead even though the form failed.

I see this regularly in support tickets: a WordPress site has a GA4 plugin, an old Analytics snippet in the theme, and another GA4 tag inside Google Tag Manager. Page views are counted twice, sometimes three times. The traffic graph looks wonderful until somebody checks the underlying requests.

Let me put it this way: GTM does not measure anything by itself. It detects events and controls when tags send data to other systems. GA4 stores and reports the data; GTM manages the conditions that make those tags run.

Before I create a container, I write down a small measurement plan:

  • Will I track page views and campaign sources?
  • Which event represents a successful form submission?
  • Will WooCommerce orders and revenue go to GA4?
  • Which advertising platforms should receive conversions?
  • Which tags must remain inactive until cookie consent is granted?

If you want to clarify how campaign tracking fits together, see What Are UTM Parameters? A Practical Campaign Tracking Guide. UTM parameters carry campaign information; GTM can read that information when it fires a tag. They solve different problems.

Create the account and container

Keep the structure predictable

Google Tag Manager has an account at the top and one or more containers underneath it. An account usually represents a company. A container represents a website, Android application, or iOS application.

I normally give each website its own web container. Two domains may share a company account, but keeping unrelated measurement logic together makes testing and permissions harder than necessary.

  1. Open Google Tag Manager and sign in.
  2. Select Create Account.
  3. Enter the company name and country.
  4. Name the container after the domain.
  5. Select Web as the target platform.

GTM displays a two-part installation snippet. The first part belongs inside <head>. The second belongs immediately after the opening <body> tag. A container ID usually looks like GTM-ABC1234.

Install GTM on WordPress

I first check whether the installation will survive a theme or plugin update. Editing a parent theme is quick, but it is also a good way to lose tracking during the next update.

Use a theme or custom-code field

A reliable theme may provide fields for head and body code. Some plugins provide similar fields. Put the first snippet in the <head> field and the second immediately after the opening <body> tag.

Do not put both snippets into one field. The noscript section belongs inside <body>.

Use a child theme or custom plugin

If you need file-level control, use a child theme or a small custom plugin rather than modifying the parent theme. The exact hook depends on how the site is built, so I test the rendered HTML instead of assuming the hook placed the code correctly.

The standard placement looks like this:

<!-- inside <head> -->
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABC1234');
</script>

<!-- immediately after the opening <body> tag -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-ABC1234"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

Replace GTM-ABC1234 with your container ID. Seeing &l= in the script is normal. It tells GTM the name of the data layer when that name is not dataLayer.

When I choose a third-party plugin, I check its update history, consent support, generated output, and extra JavaScript. I once trusted a plugin description that said it added GTM, then found that it also inserted another tracking script. The page source was more useful than the description.

Verify the installation before building tags

Do not start with the GA4 report. Reports can be delayed, and a wrong container ID will not stop the page from loading. Use the Preview button in GTM first.

  1. Open the correct container.
  2. Select Preview.
  3. Enter the website address and start the connection.
  4. Confirm the connection in Tag Assistant.
  5. Check the event timeline for page views, clicks, and form events.

The tag merely appearing in Preview is not enough. A tag under Tags Fired ran during the session; one under Tags Not Fired did not meet its conditions. Check the event as well as the tag.

In browser developer tools, open Network and search for collect, gtag, or the request used by your measurement platform. From a terminal, I use this to check the basic server response:

curl -sI https://your-example-domain.com/ | sed -n '1,12p'

This only proves that the page returned an HTTP response. It does not prove that GTM works. The useful test combines page source, Tag Assistant, and network requests.

Connect GA4 as the first tag

If the GA4 property does not exist yet, create a web data stream first. In GA4, open Data streams, select the web stream, and copy its measurement ID, which looks like G-XXXXXXXXXX.

In GTM, create a tag with these settings:

  • Tag type: Google tag, or the current GA4 tag type shown in your account
  • Google tag ID: your GA4 measurement ID
  • Trigger: Initialization – All Pages, or another suitable all-pages trigger

I use a name such as GA4 - Google Tag - All Pages. “Tag 1” tells me nothing six months later. Good names make broken tracking much easier to trace.

Do not load the same measurement ID through a separate Analytics plugin as well. In one case, I found a form conversion firing from a button click before the form had succeeded. I traced the form’s AJAX response and changed the trigger to the success event. Failed submissions stopped becoming conversions.

For GA4 installation and report checks, see GA4 Setup Guide: Track Your Website Data Step by Step. GTM installation and GA4 property configuration are related, but I verify them separately.

Track clicks, forms, and custom events

Telephone links

For phone links, create a custom event tag and a trigger whose Click URL starts with tel:. I might name the event phone_click and send parameters such as link_text and page_location.

Keep event names consistent. Avoid spaces and accented characters; plain lowercase names are easier to use across analytics and advertising systems.

A button click is not a successful form

Many WordPress form plugins submit through AJAX. A normal “Form Submission” trigger can therefore fire too early or not at all. A success message, a plugin-provided JavaScript event, or a custom data layer event is usually a better signal.

I measure the successful response, not the visitor’s attempt to press the button. Otherwise, a visitor who leaves a required field empty may be counted as a lead.

Use the data layer for stable event data

Custom data layer events reduce your dependence on CSS classes and changing HTML:

<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'lead_form_success',
  form_name: 'demo_request',
  form_id: 'contact-form'
});
</script>

In GTM, set the custom event trigger name to lead_form_success. Create data layer variables for form_name and form_id, then pass them into the event tag. If a designer changes the button class later, the measurement logic can continue working.

WooCommerce tracking needs order-level checks

WooCommerce sites can send product views, add-to-cart events, checkout starts, and purchases. The event count is not enough. Revenue, currency, product IDs, and order numbers must also be correct.

The transaction_id matters especially for purchases. A refresh, payment return, or reopened thank-you page can send the same order again. Use the order number as a unique value and test the thank-you page twice.

When a plugin creates the data layer, I inspect its actual output in the Data Layer tab in Tag Assistant. Documentation and generated field names do not always match.

Before marking a purchase as an advertising conversion, compare the test order with GA4 DebugView, the real-time report, and the WooCommerce order screen. The amount, currency, and order ID should agree.

Consent and KVKK considerations

GTM is a technical tool. It does not decide whether consent is required, which data may be collected, or which provider may receive it. Your consent management platform and legal assessment should define the categories and conditions for analytics and advertising tags.

Test the default consent state, the update signals, and the tag conditions. A consent banner appearing on screen proves very little. I also inspect network requests for advertising calls that happen before consent.

Tag groupExample nameCheck
AnalyticsGA4 – Google Tag – All PagesConsent state and single load
AdvertisingAds – Lead ConversionCorrect conversion and consent signal
CommerceGA4 – PurchaseOrder ID and revenue
Custom eventGA4 – Lead Form SuccessActual successful submission

Publish carefully and keep rollback available

Changes stay in the GTM workspace until you publish the container. Before publishing, add a description such as “Added form tracking using the demo_request event.” That note will save time later.

  1. Test the tags in Preview.
  2. Verify the destination request in GA4 DebugView or the relevant platform.
  3. Review the workspace changes.
  4. Add a clear description to the published version.
  5. Check the live site again in a private browser window.

If a bad tag reaches production, return to an earlier container version. I treat rollback as part of the setup, not as an admission that testing failed. Measurement code is still production code.

Problems I check first

The tag does not fire

Check the trigger conditions and variables. Previewing the wrong container, using an ad blocker, or missing required consent can look identical at first.

GA4 data arrives twice

Search the page source for another GA4 snippet, inspect GTM for duplicate Google tags, and check whether both a plugin and the theme are loading Analytics. The Network tab usually gives me an answer faster than the report screen.

Preview will not connect

Cache plugins, firewalls, third-party cookie restrictions, and Content Security Policy rules can interfere with Tag Assistant. Try a private window and check server firewall logs if the connection is being blocked.

The published change is missing

You may have changed the workspace without publishing it. A CDN or page cache may also be returning old HTML. Confirm the published version first, then inspect the browser source for the container ID.

A practical setup checklist

  • Does each website have the correct container?
  • Are both GTM snippets in the right locations?
  • Is the container or GA4 tag loading more than once?
  • Does the measurement ID belong to the intended data stream?
  • Do tags fire on the correct events in Preview?
  • Do form and order events represent successful actions?
  • Are consent-dependent tags inactive before consent?
  • Does the published version have a useful description?
  • Have custom events been compared with DebugView and live reports?

Once you start interpreting GA4 data, How to Increase E-Commerce Conversion Rates can help connect measurement with business goals. A conversion that is defined badly can mislead you more effectively than no conversion data at all.

My usual order is simple: define the event and its success condition, design the data layer or trigger, test it, and publish last. I would rather have five reliable events than fifty guesses. Review unused tags and old triggers every month; containers quietly become junk drawers when nobody does.

Frequently asked questions

Should I use a WordPress plugin for GTM?

You can, but check that it survives updates, supports your consent system, and does not add unnecessary scripts. A child theme or custom plugin is usually more durable than editing a parent theme directly.

Are GTM and Google Analytics the same?

No. Google Analytics measures and reports data. Google Tag Manager manages tags and the conditions under which they run. GTM can load GA4, advertising conversion tags, and other third-party tags.

Can GTM slow down a website?

The container normally loads asynchronously, but every tag can add JavaScript and network requests. Remove unused tags, narrow their triggers, and test performance on real mobile devices.

How do I know that a tag actually fired?

Use GTM Preview and Tag Assistant to confirm the event and fired tag. Then compare the browser request with the real-time or debugging view in the destination platform. That extra check has saved me from trusting a green-looking setup more than once.