Skip to content

feat: load GTM via @next/third-parties gated by NEXT_PUBLIC_GTM_ID#501

Merged
drankou merged 1 commit into
mainfrom
improve-google-analytics
Jul 9, 2026
Merged

feat: load GTM via @next/third-parties gated by NEXT_PUBLIC_GTM_ID#501
drankou merged 1 commit into
mainfrom
improve-google-analytics

Conversation

@drankou

@drankou drankou commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Replaces the hand-rolled GTM snippet (hardcoded container ID, NODE_ENV gate, next/head usage unsupported in the App Router) with the GoogleTagManager component. The container ID now comes from NEXT_PUBLIC_GTM_ID, so GTM loads only where the var is set — production, not preview deploys.

part of DASH-159

@cla-bot cla-bot Bot added the cla-signed label Jul 9, 2026
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jul 9, 2026 8:00am

Request Review

@linear-code

linear-code Bot commented Jul 9, 2026

Copy link
Copy Markdown

DASH-159

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean switch to @next/third-parties, properly gated on NEXT_PUBLIC_GTM_ID.

Extended reasoning...

Overview

Swaps the hand-rolled GTM next/head + Script snippet (with a hardcoded container ID and a NODE_ENV gate) for the official GoogleTagManager component from @next/third-parties/google, conditionally rendered only when NEXT_PUBLIC_GTM_ID is set. Also adds the env var to the client zod schema and .env.example, drops the now-unused GTMHead/GTMBody module, and removes the stray next/head import (which is a no-op in the App Router anyway).

Security risks

None material. GTM loading behavior is unchanged in intent (still injects the same third-party tag manager); the container ID moves from a hardcoded literal to a client env var, which is fine since GTM container IDs are public. Gating on presence of the env var means preview deploys will no longer load GTM, which is the stated intent.

Level of scrutiny

Low. Small, mechanical migration to the framework-supported component, no logic in critical code paths (auth, billing, permissions). The zod schema addition is standard (z.string().min(1).optional()), matching the surrounding NEXT_PUBLIC_POSTHOG_KEY pattern.

Other factors

Bug hunting system found nothing. Vercel preview build is running. No prior reviewer comments to address.

@drankou drankou merged commit 743cfe4 into main Jul 9, 2026
14 checks passed
@drankou drankou deleted the improve-google-analytics branch July 9, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants