Google Tag Manager Event Tracking (Part 1): Design the Measurement Before the Tags
Build a reliable GTM event-tracking foundation with a measurement plan, event taxonomy, dataLayer contract, GA4 recommended events, consent-aware collection and practical QA.
Google Tag Manager makes it easy to create a tag. That is not the difficult part.
The difficult part is deciding what an event actually means, making sure the website emits that event consistently, and keeping the resulting analytics trustworthy six months after three developers, two agencies and a marketing team have touched the container.
A good GTM implementation therefore starts before GTM.
It starts with a measurement contract.
The architecture in one sentence
For most modern websites, a clean event flow looks like this:
user action → application state confirms the action → dataLayer event → GTM trigger → destination tag → analytics validation
That distinction matters. GTM should usually consume meaningful application events rather than reverse-engineering business behaviour from whatever HTML happens to be on screen today.
A button click is not necessarily a conversion. A form submit event is not necessarily a successful lead. A checkout button is definitely not the same thing as a completed purchase.
Start with questions, not tags
Before opening GTM, write down what the business needs to learn.
For a SaaS product that might be:
- Which acquisition sources produce registrations?
- How many registrations become activated accounts?
- Which product actions correlate with retention?
- Where do users abandon onboarding?
- Which pricing CTA or plan was selected?
For ecommerce:
- Which products are viewed?
- Which lists generate product selections?
- Where does checkout abandonment happen?
- What is purchased, for how much and under which transaction ID?
The tracking plan should then map those questions to events and parameters.
| Business action | Event | Useful parameters |
|---|---|---|
| User creates an account | sign_up |
method |
| User signs in | login |
method |
| User searches | search |
search_term |
| User begins checkout | begin_checkout |
currency, value, items |
| Order succeeds | purchase |
transaction_id, currency, value, items |
| User completes a product-specific action | custom event | stable business context only |
Where Google Analytics already defines a recommended event for the action, prefer that vocabulary rather than inventing a near-duplicate. GA4 understands recommended events such as login, sign_up, search, purchase and the ecommerce sequence, with defined parameters that make reports and integrations more useful.
Treat the data layer as an API
The most maintainable way to use GTM is to treat dataLayer as an interface between the application and analytics.
The application owns the truth about what happened. GTM owns routing that information to approved destinations.
For example:
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
event: 'account_created',
account_plan: 'starter',
signup_method: 'email'
});
</script>
GTM can listen for the custom event account_created, read the two accompanying values through Data Layer Variables and translate the application event into the analytics event required by a destination.
This is much more resilient than a trigger such as:
fire when somebody clicks an element with CSS class
.btn-green.signup-final-step
The CSS selector describes presentation. account_created describes reality.
Track outcomes, not hopeful clicks
One of the most common analytics errors is firing an event too early.
Imagine this flow:
- user completes a lead form;
- user presses Submit;
- client validation passes;
- request reaches the API;
- API rejects it because the email already exists;
- UI shows an error.
A generic click trigger at step 2 records a lead that never existed.
If the metric is successful lead creation, emit the event only after the application knows the lead was accepted.
const result = await createLead(payload);
if (result.ok) {
window.dataLayer.push({
event: 'lead_created',
lead_type: 'demo_request'
});
}
This small architectural choice can be the difference between analytics that informs decisions and analytics that merely produces numbers.
Event names should describe things that happened
A durable taxonomy is boring in the best possible way.
Prefer names such as:
sign_up
login
search
generate_lead
pricing_plan_selected
report_exported
subscription_started
Avoid names such as:
button_click_2
new_event_final
homepage_blue_cta
conversion_test_june
Presentation changes. Business actions survive redesigns.
Use lower-case, predictable naming and document the convention before the event catalogue becomes large.
Parameters provide the context
Do not create a separate event for every variation if one event plus parameters describes the model better.
Instead of:
pricing_starter_clicked
pricing_pro_clicked
pricing_business_clicked
consider:
dataLayer.push({
event: 'pricing_plan_selected',
plan_name: 'business',
billing_period: 'annual',
placement: 'pricing_page'
});
Now the event remains stable while the dimensions describe what varied.
There is a limit to useful context, however. Analytics is not an application log and the data layer is visible to client-side code and browser tooling. Do not casually push passwords, authentication tokens, payment-card details, private free-text fields or other sensitive information into it.
A useful data-layer contract
For important events, document at least:
| Field | Meaning |
|---|---|
| event name | stable machine-readable action |
| trigger condition | exact point at which the event is considered true |
| parameters | names, types and meaning |
| source | application/component responsible for emitting it |
| destinations | GA4, Ads, another approved vendor, etc. |
| consent requirement | whether collection/firing depends on consent state |
| test case | how QA proves it fires once with correct values |
| owner | who approves changes to the definition |
This turns tracking from scattered snippets into an interface that can be reviewed and tested.
GTM’s three building blocks
Once the event contract exists, GTM becomes easier to reason about.
Tags
A tag performs an action, normally sending data to a destination.
Triggers
A trigger decides when a tag is eligible to fire.
Variables
Variables provide values used by tags and triggers.
For our earlier example the mapping might be:
Application:
dataLayer.push({ event: 'account_created', account_plan: 'starter' })
GTM:
Custom Event trigger: account_created
Data Layer Variable: account_plan
GA4 event tag: sign_up
parameter: plan_name = {{DLV - account_plan}}
The exact tag UI evolves over time. The architecture is more important than memorising where a field happens to sit in the current interface.
dataLayer.push() is an event queue, not a magic global object
Initialise the array before using it:
window.dataLayer = window.dataLayer || [];
Then push objects onto it.
Do not repeatedly replace window.dataLayer with a new array after GTM has started. Doing so can break the queue and lose information GTM relies on.
Also remember that the state GTM can read may persist across pushes. This becomes particularly important with ecommerce objects, where stale values can accidentally bleed into later events. Google’s current ecommerce examples explicitly clear the previous ecommerce object before pushing a new ecommerce event:
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: 'GBP',
value: 49.00,
items: [
{
item_id: 'SKU-42',
item_name: 'Example Product',
price: 49.00,
quantity: 1
}
]
}
});
That is a practical detail worth getting right rather than discovering it after revenue reports look strange.
Purchases need special discipline
Purchase tracking is where small implementation mistakes become expensive reporting mistakes.
A robust purchase event should be emitted only after the order is genuinely accepted and should carry a stable unique transaction identifier.
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'ORD-84721',
currency: 'GBP',
value: 79.98,
tax: 13.33,
shipping: 0,
items: [
{
item_id: 'SKU-101',
item_name: 'Example Item',
price: 39.99,
quantity: 2
}
]
}
});
Google’s event specification uses transaction_id to identify the transaction and help avoid duplicate purchase events. That does not mean you should deliberately fire duplicates and hope downstream deduplication fixes the architecture. Prevent duplicate emission as well.
Common causes include:
- firing once on API success and again on the confirmation page;
- firing whenever the thank-you page is refreshed;
- client-side route transitions replaying initialization logic;
- a tag existing in both hard-coded site code and GTM;
- two GTM triggers matching the same action.
Test reloads, back/forward navigation and SPA route transitions, not just the happy path once.
Consent belongs in the architecture from day one
Consent is not a final checkbox to bolt onto a finished container.
Your implementation must distinguish:
- what the application is legally and operationally allowed to collect;
- what consent state has been established;
- which tags may run under that state;
- how Google’s consent signals are configured where Google products are used.
Google’s current consent model includes signals such as analytics_storage, ad_storage, ad_user_data and ad_personalization. The exact legal requirements depend on jurisdiction and your processing, so GTM configuration is not a substitute for privacy/legal analysis.
A useful engineering rule is simpler: do not allow a marketing tag to become the thing that decides whether it was allowed to run. Establish consent deliberately and make tag behaviour depend on that state.
Basic and advanced consent mode are not the same thing
Google documents basic and advanced consent-mode implementations. They have different collection behaviour before consent is granted.
Do not copy a random consent-mode snippet without understanding which model your organisation has chosen and how it fits the consent-management platform.
Test at least:
- first visit before a choice;
- accept all;
- reject optional categories;
- granular preferences if offered;
- returning visitor with stored choice;
- withdrawal/change of consent;
- regions where your CMP behaves differently.
Do not send PII because a parameter is convenient
A common anti-pattern is to use analytics as an easy debugging pipe:
// Don't do this casually.
dataLayer.push({
event: 'form_error',
email: form.email.value,
message: form.message.value
});
Free-text fields are especially dangerous because users can enter almost anything.
Prefer controlled categorical values:
dataLayer.push({
event: 'form_error',
form_name: 'demo_request',
error_code: 'duplicate_email'
});
That is more useful analytically and dramatically reduces accidental data exposure.
SPAs need application events, not page-load assumptions
Single-page applications make DOM-driven analytics particularly fragile.
A user can navigate from /pricing to /checkout without a traditional document load. Components can mount multiple times. History changes can happen before route data is ready. A modal can represent a meaningful funnel step without changing the URL at all.
The cleanest approach is usually to let the router/application tell the data layer when a meaningful navigation or state transition has completed.
If you manually implement page_view events, define exactly what counts as a view and ensure you are not also collecting the same view automatically. Duplicate pageviews are one of those problems that can sit unnoticed because the dashboard still looks plausible.
QA the whole chain
A GTM Preview window saying that a tag fired proves only part of the implementation.
For each important event verify:
- the application emitted it at the correct moment;
- it emitted once;
- the data-layer values are correct;
- the intended GTM trigger matched;
- unintended tags did not match;
- the outgoing network request contains the intended event and parameters;
- the destination receives it;
- consent state behaves correctly;
- refresh/navigation/retry paths do not duplicate it.
For GA4, use the appropriate debugging and real-time tooling as part of QA, but remember that a report appearing later does not tell you whether your business definition was correct.
Version the measurement plan with the product
Analytics breaks when the product changes but the tracking assumptions do not.
If checkout changes from three steps to one, a funnel based on the old steps is now misleading even if every tag technically fires.
Tracking changes should therefore be reviewed alongside feature changes. For important applications, the event contract can live in source control and be included in acceptance criteria.
Example:
Feature: annual plan checkout
Analytics acceptance criteria:
- pricing_plan_selected fires after a plan is selected
- begin_checkout fires once when a checkout session is created
- purchase fires only after confirmed payment/order creation
- transaction_id is stable and unique
- no email address is included in analytics parameters
- consent-denied test path passes
That is a far stronger standard than “marketing will add the GTM tags later”.
Audit what users actually receive
SiteTidy can inspect the public page around your analytics implementation — performance, markup, headers and other delivery issues — while GTM's Preview and destination debugging tools validate the event pipeline itself.
A practical Part 1 checklist
Before calling an event implementation complete, ask:
- Does the event represent a business fact rather than a convenient DOM interaction?
- Is there already a suitable GA4 recommended event?
- Is the firing condition unambiguous?
- Are parameter names and types documented?
- Is sensitive data excluded?
- Does consent behaviour match the chosen architecture?
- Does the event fire exactly once on success?
- Have failure, retry, refresh and SPA navigation paths been tested?
- Can another developer understand the contract without opening GTM?
If those answers are solid, GTM becomes what it should be: a manageable delivery layer for measurement rather than an invisible second application held together by CSS selectors.
In Part 2, we will build on this foundation and look closely at the dataLayer, variables, triggers and event-state problems that cause real-world GTM implementations to produce incorrect data.
