-
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.
Added advanced config for google tags
- Loading branch information
1 parent
d5547ec
commit 04d14fa
Showing
1 changed file
with
33 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,36 @@ | ||
<script defer> | ||
document.addEventListener('DOMContentLoaded', () => { | ||
if (getCookieValue('cookieConsentMarketing') === 'true') { | ||
// Create the script element for Google Tag Manager | ||
const gtmScript = document.createElement('script'); | ||
gtmScript.async = true; | ||
gtmScript.src = 'https://www.googletagmanager.com/gtag/js?id=G-21CQLLSNPS'; | ||
<script> | ||
// Define dataLayer and the gtag function. | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { dataLayer.push(arguments); } | ||
|
||
// Insert the script element into the DOM | ||
document.head.appendChild(gtmScript); | ||
|
||
// Initialize Google Tag Manager | ||
gtmScript.onload = function() { | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { | ||
dataLayer.push(arguments); | ||
} | ||
gtag('js', new Date()); | ||
gtag('config', 'G-21CQLLSNPS'); | ||
}; | ||
} | ||
// Set default consent to 'denied' as a placeholder | ||
// Determine actual values based on your own requirements | ||
gtag('consent', 'default', { | ||
'ad_storage': 'denied', | ||
'ad_user_data': 'denied', | ||
'ad_personalization': 'denied', | ||
'analytics_storage': 'denied' | ||
}); | ||
</script> | ||
<!-- Google tag (gtag.js) --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-21CQLLSNPS"> | ||
</script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { dataLayer.push(arguments); } | ||
|
||
gtag('js', new Date()); | ||
gtag('config', 'G-21CQLLSNPS'); | ||
</script> | ||
|
||
<!-- Create one update function for each consent parameter --> | ||
<script> | ||
if (getCookieValue('cookieConsentMarketing') === 'true') { | ||
gtag('consent', 'update', { | ||
'ad_storage': 'granted', | ||
'ad_user_data': 'granted', | ||
'ad_personalization': 'granted', | ||
'analytics_storage': 'granted' | ||
}); | ||
} | ||
</script> |