Hunor.digital
← All writing
Tracking · Strategy

GTM vs hardcoded tracking: when to use which

Tag manager or code? The honest decision rules: what belongs in GTM, what belongs in the codebase, and the hybrid split that most mature setups land on.

Lázár HunorDigital Fixer
The short answer

Use Google Tag Manager for marketing and analytics tags that change often, and hardcode tracking that is core to the product or must never depend on a marketing container. GTM buys speed and non-developer control at the cost of governance risk; hardcoding buys stability at the cost of developer time for every change.

This question usually arrives disguised. What the client asks is "should we use Google Tag Manager or put the code in the site?" What they mean is "who should be able to change what our site sends to third parties, and how fast?" Answer that second question and the first one mostly answers itself.

What GTM actually is

Google Tag Manager is a container of JavaScript that your site loads once, after which marketers can inject, modify, and remove tags through a web interface without a developer or a deploy. That is its entire value and its entire risk in one sentence.

The value: a new ad platform pixel goes live in an hour instead of waiting three weeks for a release window. The risk: your container is production code that ships outside your code review, your testing, and usually your awareness. Every person with publish rights can change what runs on your checkout page this afternoon.

When GTM is the right call

When hardcoding is the right call

The hybrid most mature setups converge on

In practice the good setups I see are not either-or. They split by change frequency and blast radius:

  1. The dataLayer contract lives in code. Developers own event pushes, reviewed and tested like any feature, because they are one.
  2. Tool wiring lives in GTM. Which platforms consume which events is marketing configuration, and it changes too often to deserve a deploy each time.
  3. Consent gating lives in one place, in GTM, applied to every marketing tag with no exceptions.
  4. Publish rights are scarce. Two or three people, versioned workspaces, and a habit of naming versions so the container has a history someone can read.

This gets you developer-grade stability where stability matters and marketing-grade speed where speed matters.

The failure mode of each, so you recognize yours

GTM's failure mode is entropy: unreviewed changes pile up until nobody can say what the container does, and the answer to "why did conversions double-count in March" is a shrug. Hardcoding's failure mode is starvation: every measurement request enters the engineering backlog behind features, so marketing quietly installs plugins and pixels around the process, and you end up with GTM anyway, just unofficially and worse.

If either of those paragraphs described your setup, the fix is rarely switching architectures. It is assigning an owner and writing down the contract. The architecture question is downstream of the governance question, which is why an audit of what actually fires today, mapped against who can change it, is where I start every tracking engagement. Verify first, then decide; the procedure is in how to check if your GA4 tracking actually works.