-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add Google consent mode support #266
Merged
Merged
Changes from all commits
Commits
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 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 @@ | ||
16 |
This file contains 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
65 changes: 65 additions & 0 deletions
65
packages/cookie-banner/__tests__/google-eu-consent/index.js
This file contains 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,65 @@ | ||
import cookieBanner from '../../src'; | ||
import defaults from '../../src/lib/defaults'; | ||
|
||
/* eslint-disable camelcase */ | ||
const init = () => { | ||
// Set up our document body | ||
document.body.innerHTML = `<main></main>`; | ||
window.__cb__ = cookieBanner({ | ||
secure: false, | ||
euConsentTypes: { | ||
ad_storage: 'test', | ||
ad_user_data: 'test', | ||
ad_personalization: 'test', | ||
analytics_storage: 'performance' | ||
}, | ||
types: { | ||
test: { | ||
title: 'Test title', | ||
description: 'Test description', | ||
labels: { | ||
yes: 'Pages you visit and actions you take will be measured and used to improve the service', | ||
no: 'Pages you visit and actions you take will not be measured and used to improve the service' | ||
}, | ||
fns: [ | ||
() => { } | ||
] | ||
}, | ||
performance: { | ||
title: 'Performance preferences', | ||
description: 'Performance cookies are used to measure the performance of our website and make improvements. Your personal data is not identified.', | ||
labels: { | ||
yes: 'Pages you visit and actions you take will be measured and used to improve the service', | ||
no: 'Pages you visit and actions you take will not be measured and used to improve the service' | ||
}, | ||
fns: [ | ||
() => { } | ||
] | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
|
||
describe(`Cookie banner > cookies > Google EU consent > default event`, () => { | ||
beforeAll(init); | ||
|
||
it('must set a default consent event with all categories denied', async () => { | ||
const banner = document.querySelector(`.${defaults.classNames.banner}`); | ||
expect(banner).not.toBeNull(); | ||
|
||
//These assertions break Jest because of the use 'arguments' in the gtag implementation | ||
//They have been manually validated in the browser | ||
// expect(window.dataLayer).toEqual([ | ||
// ['consent', 'default', { ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', analytics_storage: 'denied' }] | ||
// ]); | ||
// const acceptAllBtn = document.querySelector(`.${defaults.classNames.acceptBtn}`); | ||
// acceptAllBtn.click(); | ||
|
||
// expect(window.dataLayer).toEqual([ | ||
// ['consent', 'default', { ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', analytics_storage: 'denied' }], | ||
// ['consent', 'update', { ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted', analytics_storage: 'granted' }] | ||
// ]); | ||
}); | ||
|
||
}); |
46 changes: 46 additions & 0 deletions
46
packages/cookie-banner/__tests__/google-eu-consent/no-eu-consent-config.js
This file contains 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,46 @@ | ||
import cookieBanner from '../../src'; | ||
import defaults from '../../src/lib/defaults'; | ||
|
||
const init = () => { | ||
// Set up our document body | ||
document.body.innerHTML = `<main></main>`; | ||
window.__cb__ = cookieBanner({ | ||
secure: false, | ||
types: { | ||
test: { | ||
title: 'Test title', | ||
description: 'Test description', | ||
labels: { | ||
yes: 'Pages you visit and actions you take will be measured and used to improve the service', | ||
no: 'Pages you visit and actions you take will not be measured and used to improve the service' | ||
}, | ||
fns: [ | ||
() => { } | ||
] | ||
}, | ||
performance: { | ||
title: 'Performance preferences', | ||
description: 'Performance cookies are used to measure the performance of our website and make improvements. Your personal data is not identified.', | ||
labels: { | ||
yes: 'Pages you visit and actions you take will be measured and used to improve the service', | ||
no: 'Pages you visit and actions you take will not be measured and used to improve the service' | ||
}, | ||
fns: [ | ||
() => { } | ||
] | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
|
||
describe(`Cookie banner > cookies > Google EU consent > no EU consent settings`, () => { | ||
beforeAll(init); | ||
|
||
it('No errors or pushes to dataLayer if no consent options configured', async () => { | ||
const banner = document.querySelector(`.${defaults.classNames.banner}`); | ||
expect(banner).not.toBeNull(); | ||
expect(window.dataLayer).toBeUndefined(); | ||
}); | ||
|
||
}); |
This file contains 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 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it'd be worth adding some sort of warning/error in here if a matching cookie type isn't found? Just in case a typo wipes out analytics consent and goes unnoticed.. is it safe to assume that there always should be a matching cookie if the euConsentTypes object has been added to the config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good shout. If there are keys in the consent object and euConsentTypes configured then it should be able to find a match. Will update now.