Skip to content

Commit

Permalink
Added advanced config for google tags
Browse files Browse the repository at this point in the history
  • Loading branch information
spolischook committed Sep 22, 2024
1 parent d5547ec commit 04d14fa
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions layouts/partials/gtag.html
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>

0 comments on commit 04d14fa

Please sign in to comment.