Skip to content

Conversation

@shrink
Copy link
Contributor

@shrink shrink commented Jun 27, 2023

Note: new PR description written by @timneutkens

What?

Improves the detection of Google Tag Manager vs Google Analytics.
As indicated by the author of this PR it was confusing that when you have Google Tag Manager set up it gives you an error message saying you're adding Google Analytics even though it's Tag Manager.

I've updated the PR to have a separate message for Google Tag Manager and expanded the error message docs too.

It also mentioned next/script in a bunch of places even though the error doc recommends @next/third-parties. I've updated all cases to refer to @next/third-parties instead.

Previous PR description Google has multiple products with similar names: the "Google Tag" and "Google Tag Manager". Google Tag Manager uses `gtm.js` whereas the "Google Tag" uses `gtag`. Google Analytics previously used `analytics.js` (<2017) and is now delivered via the "Google Tag".

Google Tag: www.googletagmanager.com/gtag/js
Google Tag Manager: www.googletagmanager.com/gtm.js

The next-script-for-ga.ts rule's matching list (SUPPORTED_HTML_CONTENT_URLS) includes gtm.js which means when a developer adds Google Tag Manager to their NextJS website, they'll receive the warning and be encouraged to swap from gtm.js to gtag. A developer asleep at the wheel (...me) may think...

I'm using Google Analytics via Google Tag Manager, and NextJS is suggesting I swap gtm.js for gtag because it will improve performance. gtag sounds like it is part of "Google Tag Manager" so I am going to follow the instructions so that my website is faster.

However, gtag is not compatible with gtm.js (they're different products with similar names and similar purposes) and so making this change will cause very confusing Google Tag Manager behaviour. I am suggesting that gtm.js is removed completely from the rule, because anyone using gtm.js should not be following these instructions. A separate rule could be added specifically for Google Tag Manager, that does not refer to gtag.

Google has multiple products with similar names: the "Google Tag" and "Google Tag Manager". Google Tag Manager uses `gtm.js` whereas the "Google Tag" uses `gtag`. Google Analytics previously used `analytics.js` (<2017) and is now delivered via the "Google Tag".

The `SUPPORTED_HTML_CONTENT_URLS` includes `gtm.js` which means when a developer adds Google Tag Manager to their NextJS website, they'll receive the warning and be encouraged to swap from `gtm.js` to `gtag`. However, `gtag` is not compatible with `gtm.js` and making this change will cause very confusing Google Tag Manager behaviour.
@ijjk ijjk added Documentation Related to Next.js' official documentation. tests labels Nov 24, 2025
@timneutkens timneutkens changed the title fix: Remove gtm.js from Google Analytics linting rule Eslint: Improve Google Tag manager third parties message Nov 24, 2025
@timneutkens
Copy link
Member

I've updated the PR to instead clarify Tag Manager vs Google Analytics for this detection.

@timneutkens timneutkens merged commit 7e093af into vercel:canary Nov 24, 2025
402 of 406 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Related to Next.js' official documentation. tests type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants