Andreas Cederblad Δ
All articles
kpi3 minMarch 24, 2025

Building GTM Containers and Measurement Plans with Claude Code

Google Tag Manager setup becomes faster, more structured, and less error-prone with Claude Code. Here's how it works in practice.

Most GTM containers grow organically. Tag by tag. Trigger by trigger. Until nobody knows what's actually being measured.

Claude Code changes that.

The problem with GTM today

GTM is powerful. But it's also:

  • manual
  • repetitive
  • hard to document
  • easy to get wrong

The most common problems I see:

  • Tags that never fire
  • Duplicated events
  • No connection to a measurement plan
  • "Someone set it up two years ago"

What Claude Code actually does

Claude Code isn't a GTM plugin. It's an AI-driven development environment that understands code, structure, and logic.

In the GTM context, that means:

1. Generate tag configurations from the measurement plan

You have a measurement plan with events: purchase, add_to_cart, begin_checkout, view_item.

Claude Code can generate the entire GTM configuration — tags, triggers, and variables — as a JSON import. Not one at a time. The entire structure at once.

2. Validate existing containers

Export your GTM container as JSON. Claude Code can:

  • identify tags without triggers
  • find duplicated events
  • flag inconsistent naming conventions
  • compare against your measurement plan

3. Custom HTML tags

Need a custom JavaScript tag? Claude Code writes it. With error handling, consent checks, and documentation built in.

Examples:

  • Scroll depth tracking with custom thresholds
  • Dynamic remarketing tags for Shopify
  • Consent-aware event forwarding

4. The data layer

Most underrated part of GTM. Claude Code can:

  • design dataLayer schemas based on your KPIs
  • generate push events for every funnel step
  • validate that the frontend sends the right data

The measurement plan as foundation

Everything starts with the measurement plan. Not with GTM.

A measurement plan defines:

  1. What to measure (events)
  2. Why it's measured (connection to KPI)
  3. Where data is collected (GA4, CRM, ad platforms)
  4. Who is responsible

Claude Code takes that plan and turns it into:

  • GTM configuration
  • GA4 event setup
  • Documentation

Practical workflow

Here's how I work:

  1. Workshop — define KPIs and events with the client
  2. Measurement plan — document everything in a structured framework
  3. Claude Code — generate GTM container, dataLayer schema, custom tags
  4. Validation — test in GTM preview mode
  5. Deploy — publish with version notes

Step 3 takes minutes instead of hours. And the result is consistent, documented, and reproducible.

What changes

With Claude Code in the workflow:

  • Faster setup — an entire container in an afternoon instead of a week
  • Fewer errors — AI doesn't forget edge cases
  • Better documentation — generated automatically
  • Easier maintenance — structure is consistent from the start

Limitations

Claude Code doesn't replace:

  • GTM knowledge (you need to know what to measure)
  • Strategic thinking (the measurement plan requires business understanding)
  • QA (always validate in preview mode)

It's a tool for iteration, not an autopilot.

Connection to experimentation

A well-structured GTM container is the foundation for all experimentation. If you don't measure correctly, you can't test correctly.

Claude Code makes it possible to:

  • quickly set up event tracking for new experiments
  • generate custom dimensions for segmentation
  • validate that data flows correctly before the test starts

Conclusion

GTM doesn't have to be chaos. Measurement plans don't have to be PDFs that nobody looks at.

With Claude Code, both become living, structured, and connected.

It's not AI replacing measurement. It's AI making measurement possible to maintain.

Andreas Cederblad Δ