Menu

Post image 1
Post image 2
1 / 2
0

Why we moved from hardcoded gtag snippets to Google Tag Manager in our Next.js app

DEV Community·John Builds·18 days ago
#U1OnKGdA
Reading 0:00
15s threshold

For the first year of building XreplyAI, our tracking setup was the standard mess: gtag scripts in _app.tsx , conversion events scattered across components, and a tacit rule that any tracking change needed a full deploy cycle. It worked, but it had a real cost: we consistently under-instrumented. Adding a conversion event for a new experiment didn't feel worth a PR when you're moving fast solo. The switch to GTM The migration was about 2 hours. The short version: Replace inline gtag calls with window.dataLayer.push() calls Move all tag configs (Google Ads, GA4, any new pixels) into a GTM container Publish the container — done What actually changed No deploys for tracking changes. New pixel, new conversion event, tweaked trigger — all done in GTM in minutes. This sounds minor until you ship 3 new conversion events in a week without opening your codebase once. Preview mode is a real debugger. GTM shows every tag, trigger, and variable state as you click through your app in real time.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More