Created
October 4, 2021 17:44
-
-
Save merlijnvanlent/feffed500524a482b3b11ea17161c488 to your computer and use it in GitHub Desktop.
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
const userAgent = window.navigator.userAgent; | |
const consentCookie = []; // Set the current consent status if this is a returning visitor. | |
const attRejectedString = 'ATTRejected'; | |
const attAcceptedString = 'ATTAccepted'; | |
// Show the consent bar if the consent cookie is not set or if this is the in-app browser | |
const initConsentBar = () => { | |
if (consentCookie.length > 0) { | |
return; // Tracking consent was already given by the visitor. | |
} | |
if (userAgent.includes(attRejectedString) || userAgent.includes(attAcceptedString)) { | |
return; // In-app browser so don't show the consent bar. | |
} | |
showConsentBar(); | |
} | |
// Load all | |
const loadTrackingSnippets = () => { | |
snippets.foreach((snippet) => { | |
if (snippet.required || userAgent.includes(attAcceptedString) || consentCookie.Includes(snippet.id)) { | |
loadSnippet(snippet); | |
} | |
}); | |
}; | |
initConsentBar(); | |
loadTrackingSnippets(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment