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 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.
- 01
Create the container
One web container for the site, with publish rights limited to named people.
- 02
Put the ID in an environment variable
Store the container ID on your host, for production and preview builds.
- 03
Add the consent default
An inline Consent Mode v2 default script runs before the container loads.
- 04
Load GoogleTagManager in the root layout
The component from @next/third-parties loads the container in the root layout.
- 05
Push events with sendGTMEvent
Form submissions, bookings and sign-ups go to the data layer from client components.
- 06
Preview before publishing
Check each tag and its consent behavior in GTM’s preview mode, then publish a named version.
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.
Webflow Google Tag Manager, Framer and Astro
The method depends on where your site is built. Here is what we use for Google Tag Manager on each platform.
Framer
Framer’s own guide places the two GTM snippets in Site Settings custom code: one at the start of the head, one at the start of the body, on all pages. We set the consent default before the container loads and push form events to the data layer from Framer’s form handling.
Framer development Custom codeWebflow
We paste the container snippet into Webflow’s head custom code and the noscript part into the body section, then publish. Webflow form submissions and CMS template data are pushed to the data layer with a small script, so tags trigger on real conversions.
Webflow development Layout snippetAstro
The container goes in the shared Astro layout, after an inline consent-default script. Because Astro ships little JavaScript, GTM is often the heaviest script on the page, so we keep the container lean and test Partytown only when it actually helps.
Astro development Official componentNext.js
The GoogleTagManager component from @next/third-parties loads the container in the root layout, and sendGTMEvent pushes conversions from client components. Server-side tagging can be added later by pointing the component at your own tagging server.
Next.js developmentWhat teams use it for
Consent in one place
Every tag respects the visitor’s cookie choice through Consent Mode v2 and per-tag consent settings.
Marketing without deploys
New pixels and events go live through a reviewed GTM version, not a site release.
Clean conversion events
Forms, bookings and sign-ups pushed to the data layer once, used by GA4 and ad platforms alike.
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.
Anyone who can publish in GTM can run JavaScript on your site. Limit publish rights and use approvals.
Containers grow quietly. Old pixels and duplicate tags slow every page; we audit and remove them.
A tag set to fire on all pages ignores consent unless configured otherwise. We check consent settings on every tag.
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
Questions about Google Tag Manager
What is Consent Mode v2?
How do I add Google Tag Manager to Webflow?
Should GA4 run inside GTM or separately in Next.js?
Can we keep our existing GTM container?
Which cookie banner works with GTM?
Thomas OldenburgerFounder, design and build leadStill deciding? A 30-minute call answers most of it.
Related integrations and services
Google Analytics
Google’s free web analytics (GA4) for traffic, events, conversions and acquisition reports.
OpenHotjar
Heatmaps, session recordings and on-page surveys that show how visitors use your pages.
OpenSegment
Customer data platform from Twilio that collects events once and sends them to many tools.
OpenSEO & AEO
A clean tag setup is part of the technical baseline we deliver.
OpenTechnical SEO
Glossary definition.
Open