Skip to content

Instantly share code, notes, and snippets.

@merlijnvanlent
Created October 4, 2021 17:44
Show Gist options
  • Save merlijnvanlent/feffed500524a482b3b11ea17161c488 to your computer and use it in GitHub Desktop.
Save merlijnvanlent/feffed500524a482b3b11ea17161c488 to your computer and use it in GitHub Desktop.
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