-
Notifications
You must be signed in to change notification settings - Fork 86
fix(google-analytics, google-tag-manager): per-region consent defaults #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harlan-zw
merged 4 commits into
nuxt:main
from
zizzfizzix:feat/regional-consent-defaults
May 3, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
25cd2d6
feat(google-tag-manager): per-region consent defaults
zizzfizzix ef33ab6
feat(google-analytics): per-region consent defaults
zizzfizzix aa9d27b
docs(google-analytics, google-tag-manager): document per-region conseβ¦
zizzfizzix a8bef9a
fix(google-analytics, google-tag-manager): address CodeRabbit review
zizzfizzix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <script lang="ts" setup> | ||
| useScriptGoogleTagManager({ | ||
| id: 'GTM-DEMO123', | ||
| defaultConsent: [ | ||
| { | ||
| // EEA + UK + Switzerland β denied by default, gtag waits 500ms for an update. | ||
| ad_storage: 'denied', | ||
| ad_user_data: 'denied', | ||
| ad_personalization: 'denied', | ||
| analytics_storage: 'denied', | ||
| region: ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'IS', 'LI', 'NO', 'CH'], | ||
| wait_for_update: 500, | ||
| }, | ||
| { | ||
| // Unscoped fallback β everywhere else, granted by default. | ||
| ad_storage: 'granted', | ||
| ad_user_data: 'granted', | ||
| ad_personalization: 'granted', | ||
| analytics_storage: 'granted', | ||
| }, | ||
| ], | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <UApp> | ||
| <div class="min-h-screen bg-gray-50 dark:bg-gray-900"> | ||
| <div class="max-w-2xl mx-auto p-8"> | ||
| <h1 class="text-3xl font-bold mb-4"> | ||
| Region-specific Consent Mode example | ||
| </h1> | ||
| <p class="text-gray-600 dark:text-gray-400 mb-8"> | ||
| Pass an array to <code>defaultConsent</code> to fire multiple | ||
| <code>['consent','default', state]</code> pushes β one per region group. | ||
| gtag picks the most specific region match at runtime. | ||
| </p> | ||
|
|
||
| <UCard> | ||
| <template #header> | ||
| <h2 class="font-semibold"> | ||
| How it works | ||
| </h2> | ||
| </template> | ||
| <ul class="list-disc list-inside space-y-2 text-sm"> | ||
| <li>The first entry targets the EEA + UK + Switzerland via <code>region</code> and starts denied</li> | ||
| <li>The second entry has no <code>region</code> and is the unscoped global fallback (granted)</li> | ||
| <li>Order in the array does not matter β Google's "more specific region wins" rule is enforced by gtag at runtime</li> | ||
| <li>Open DevTools β Network & <code>window.dataLayer</code> to see two consent-default pushes before <code>gtm.js</code></li> | ||
| </ul> | ||
| </UCard> | ||
| </div> | ||
| </div> | ||
| </UApp> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| @import "tailwindcss"; | ||
| @import "@nuxt/ui"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export default defineNuxtConfig({ | ||
| modules: ['@nuxt/scripts', '@nuxt/ui'], | ||
|
|
||
| devtools: { enabled: true }, | ||
| css: ['~/assets/css/main.css'], | ||
| compatibilityDate: '2025-01-01', | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "nuxt-scripts-regional-consent-example", | ||
| "type": "module", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "nuxt dev", | ||
| "build": "nuxt build", | ||
| "preview": "nuxt preview" | ||
| }, | ||
| "dependencies": { | ||
| "@nuxt/scripts": "latest", | ||
| "@nuxt/ui": "^4.7.1", | ||
| "nuxt": "^4.4.4", | ||
| "tailwindcss": "^4.2.4", | ||
| "vue": "^3.5.33" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "./.nuxt/tsconfig.json" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.