Integrations · Analytics

Google Tag Manager on Next.js, Webflow, Framer and Astro

Google Tag Manager is the switchboard for every tracking script on your site. Our Next.js Google Tag Manager setup, and the same container on Webflow, Framer and Astro, keeps the site fast and consent-compliant while marketing adds tools.

Next.js

Next.js Google Tag Manager, step by step

Put the consent default script before the GTM container, and install GA4 inside the container only, never also on the page.

  1. 01

    Create the container

    One web container for the site, with publish rights limited to named people.

  2. 02

    Put the ID in an environment variable

    Store the container ID on your host, for production and preview builds.

  3. 03

    Add the consent default

    An inline Consent Mode v2 default script runs before the container loads.

  4. 04

    Load GoogleTagManager in the root layout

    The component from @next/third-parties loads the container in the root layout.

  5. 05

    Push events with sendGTMEvent

    Form submissions, bookings and sign-ups go to the data layer from client components.

  6. 06

    Preview before publishing

    Check each tag and its consent behavior in GTM’s preview mode, then publish a named version.

Speed

Loading strategy: when GTM slows the page

Because Astro and Next.js ship little JavaScript, GTM is often the heaviest script on the page. We keep the container lean, remove dead tags, test Partytown only where it actually helps, and add server-side tagging later, when the number of tags justifies it.

Use cases

What teams use it for

01

Consent in one place

Every tag respects the visitor’s cookie choice through Consent Mode v2 and per-tag consent settings.

02

Marketing without deploys

New pixels and events go live through a reviewed GTM version, not a site release.

03

Clean conversion events

Forms, bookings and sign-ups pushed to the data layer once, used by GA4 and ad platforms alike.

Cautions

Common Google Tag Manager pitfalls

GA4 installed twice, once on the page and once in the container, doubles every page view. We run it inside the container only.

Data

Anyone who can publish in GTM can run JavaScript on your site. Limit publish rights and use approvals.

Security

Containers grow quietly. Old pixels and duplicate tags slow every page; we audit and remove them.

Performance

A tag set to fire on all pages ignores consent unless configured otherwise. We check consent settings on every tag.

Privacy
Handover

What we set up and hand over

What we set up
Container install, Consent Mode v2, tag audit, data layer events, documentation
Typical time
1–2 days
Complexity
Medium
FAQ

Questions about Google Tag Manager

What is Consent Mode v2?
It is Google’s way of passing the visitor’s cookie choice to Google tags, using four signals including ad_user_data and ad_personalization. It has been required for advertisers in the EEA since March 2024.
How do I add Google Tag Manager to Webflow?
Paste the head snippet into Webflow’s head custom code and the noscript part into the body section, then publish. Form submissions reach the data layer with a small script.
Should GA4 run inside GTM or separately in Next.js?
One of the two, never both. We run GA4 inside the container, so consent and events are managed in one place.
Can we keep our existing GTM container?
Usually, yes. We audit it first, remove dead tags, fix consent settings and document what is left, rather than starting over and losing history.
Which cookie banner works with GTM?
Any consent platform that supports Google Consent Mode v2, such as Cookiebot or Usercentrics. We pick one with you based on price, languages and how your legal team wants consent stored.
Thomas OldenburgerFounder, design and build lead

Still deciding? A 30-minute call answers most of it.

Got a brief, or half of one?

Book a free 30-minute call. You leave with a straight answer on scope, price and timing, even when we are not the right fit.