-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the cookie names to match the unified approach.
Add the data layer push for the GA consent mode.
- Loading branch information
Showing
11 changed files
with
79 additions
and
31 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Cookies from 'js-cookie' | ||
|
||
const grantType = { | ||
granted: 'granted', | ||
notGranted: 'not granted' | ||
} | ||
|
||
const getCookiePreferences = () => Cookies.get('cookie_preferences') ?? '{}' | ||
|
||
const getCookiePreferencesSaved = () => Cookies.get('cookie_preferences_saved') ?? '{}' | ||
|
||
const setCookiePreferencesSaved = (cookiePreferences) => { | ||
Cookies.set('cookie_preferences_saved', JSON.stringify(cookiePreferences), { expires: 365 }) | ||
} | ||
|
||
const getGrantedText = (state) => state ? grantType.granted : grantType.notGranted | ||
|
||
const updateDataLayer = (cookiePreferences) => { | ||
window.dataLayer.push({ | ||
event: 'gtm_consent_update', | ||
usage_consent: getGrantedText(cookiePreferences.usage), | ||
glassbox_consent: getGrantedText(cookiePreferences.glassbox), | ||
marketing_consent: grantType.notGranted | ||
}) | ||
|
||
setCookiePreferencesSaved(cookiePreferences) | ||
} | ||
|
||
$(() => { | ||
if (window.dataLayer) { | ||
const cookiePreferences = getCookiePreferences() | ||
const cookiePreferencesSaved = getCookiePreferencesSaved() | ||
|
||
if (cookiePreferences !== cookiePreferencesSaved) { | ||
updateDataLayer(JSON.parse(cookiePreferences)) | ||
} | ||
} | ||
}) |
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
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