Skip to content
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

fix(ga): setup default consent state #71

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions data/google-analytics.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
"key": "gtag"
},
{
"code": "window[{{l}}]=window[{{l}}]||[];window['gtag-'+{{l}}]=function (){window[{{l}}].push(arguments);};window['gtag-'+{{l}}]('js',new Date());window['gtag-'+{{l}}]('config',{{id}})",
"code": "window[{{l}}]=window[{{l}}]||[];window['gtag-'+{{l}}]=function (){window[{{l}}].push(arguments);};window['gtag-'+{{l}}]('consent', {{consentType}}, {{consentValues}});window['gtag-'+{{l}}]('js',new Date());window['gtag-'+{{l}}]('config',{{id}})",
"params": ["id"],
"optionalParams": {
"l": "dataLayer"
"l": "dataLayer",
"consentType": "default",
"consentValues": {
"ad_user_data": "denied",
"ad_personalization": "denied",
"ad_storage": "denied",
"analytics_storage": "denied",
"wait_for_update": 500
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these all the default settings? We should definitely have the default values here and then Nuxt (or any consumer) can update them as they fit

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like denied is the default consent state per the docs 👍

},
"strategy": "worker",
"location": "head",
Expand Down
10 changes: 10 additions & 0 deletions src/types/type-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export interface GoogleAnalyticsParams {
* The name of the dataLayer object. Defaults to 'dataLayer'.
*/
l?: string;
/**
* Consent type for Google Analytics.
* @default 'default'
*/
consentType?: string;
/**
* Consent values for Google Analytics.
* @default {{"ad_user_data":"denied","ad_personalization":"denied","ad_storage":"denied","analytics_storage":"denied","wait_for_update":500}}
*/
consentValues?: { [key: string]: string };
}

export interface GTag {
Expand Down
10 changes: 9 additions & 1 deletion src/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('Utils', () => {
},
output: `false`,
},
// boolean
// null
{
input: '{{val}}',
params: {
Expand All @@ -335,6 +335,14 @@ describe('Utils', () => {
input: 'window[{{l}}]=window[{{l}}]||[];',
output: `window[undefined]=window[undefined]||[];`,
},
// object
{
input: '{{obj}}',
params: {
obj: { key: 'value' },
},
output: `{"key":"value"}`,
},
];

it.each(inputs)(
Expand Down
Loading