Vielen Dank, Tim - wir versuchen das aus!
![Smile](https://forum.premium-contao-themes.com/core/images/smilies/smile.png)
<?php
global $objPage;
$objRoot = \Contao\PageModel::findByPk( $objPage->rootId );
/**
* To use this script, please fill in your Google Analytics ID below
*/
$GoogleAnalyticsId = $objRoot->analytics_google;
/**
* DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
*/
if ($GoogleAnalyticsId != 'GTM-XXXXXXXXXX' && !$this->hasAuthenticatedBackendUser()): ?>
<script id="analytics_<?= $GoogleAnalyticsId ?>"></script>
<script>
function initGoogleAnalytics()
{
document.getElementById('analytics_<?= $GoogleAnalyticsId ?>').src = 'https://www.googletagmanager.com/gtag/js?id=<?= $GoogleAnalyticsId ?>';
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?= $GoogleAnalyticsId ?>',{'anonymize_ip': true});
gtag("consent", "default",
{
ad_user_data: "denied",
ad_personalization: "denied",
ad_storage: "denied",
analytics_storage: "denied",
wait_for_update: 2000 // milliseconds to wait for update
});
// Enable ads data redaction by default [optional]
gtag("set", "ads_data_redaction", true);
}
// Optin privacy setting token
var token = localStorage.getItem('user_privacy_settings');
if( token == undefined )
{
token = '';
}
if(token.indexOf(1) >= 0)
{
initGoogleAnalytics();
}
// listen to privacy event
jQuery(document).on('Privacy.changed',function(eve nt,params)
{
if(params.level.indexOf(1) >= 0)
{
initGoogleAnalytics();
}
});
</script>
<?php endif; ?>
<?php
global $objPage;
$objRoot = \Contao\PageModel::findByPk( $objPage->rootId );
/**
* To use this script, please fill in your Google Analytics ID below
*/
$GoogleAnalyticsId = $objRoot->analytics_google;
/**
* DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
*/
if ($GoogleAnalyticsId != 'GTM-XXXXXXXXXX' && !BE_USER_LOGGED_IN && !$this->hasAuthenticatedBackendUser()): ?>
<script id="googletagmanager_<?= $GoogleAnalyticsId; ?>">
// Google Consent Mode
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?= $GoogleAnalyticsId ?>',{'anonymize_ip': true});
gtag("consent", "default",
{
ad_user_data: "denied",
ad_personalization: "denied",
ad_storage: "denied",
analytics_storage: "denied",
personalization_storage: "denied",
security_storage: "denied",
functionality_storage: "denied",
wait_for_update: 2000 // milliseconds to wait for update
});
// Enable ads data redaction by default [optional]
gtag("set", "ads_data_redaction", true);
// Optin privacy setting token
var token = localStorage.getItem('user_privacy_settings');
if( token == undefined )
{
token = '';
}
if(token.indexOf(3) >= 0)
{
gtag("consent", "update",
{
ad_user_data: "granted",
ad_personalization: "granted",
ad_storage: "granted",
analytics_storage: "granted",
personalization_storage: "granted",
security_storage: "granted",
functionality_storage: "granted"
});
}
// listen to privacy event
jQuery(document).on('Privacy.changed',function(eve nt,params)
{
if(params.level.indexOf(3) >= 0)
{
gtag("consent", "update",
{
ad_user_data: "granted",
ad_personalization: "granted",
ad_storage: "granted",
analytics_storage: "granted",
personalization_storage: "granted",
security_storage: "granted",
functionality_storage: "granted"
});
}
});
// Optin privacy setting token
if(token.indexOf(3) >= 0)
{
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:''; j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<?= $GoogleAnalyticsId; ?>');
}
// listen to privacy event
jQuery(document).on('Privacy.changed',function(eve nt,params)
{
if(params.level.indexOf(3) >= 0)
{
//location.reload();
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:''; j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<?= $GoogleAnalyticsId; ?>');
}
});
</script>
<?php endif; ?>
gtag("consent", "default", { ad_user_data: "denied", ad_personalization: "denied", ad_storage: "denied", analytics_storage: "denied", personalization_storage: "denied", security_storage: "denied", functionality_storage: "denied", wait_for_update: 2000 // milliseconds to wait for update });
gtag('config', '<?= $GoogleAnalyticsId ?>',{'anonymize_ip': true});
gtag("consent", "default", { ad_user_data: "denied", ad_personalization: "denied", ad_storage: "denied", analytics_storage: "denied", personalization_storage: "denied", security_storage: "denied", functionality_storage: "denied", wait_for_update: 2000 // milliseconds to wait for update });
gtag('config', '<?= $GoogleAnalyticsId ?>',{'anonymize_ip': true});
gtag("consent", "default", { ad_user_data: "denied", ad_personalization: "denied", ad_storage: "denied", analytics_storage: "denied", personalization_storage: "denied", security_storage: "denied", functionality_storage: "denied", wait_for_update: 2000 // milliseconds to wait for update });
gtag('config', '<?= $GoogleAnalyticsId ?>',{'anonymize_ip': true});
<?php global $objPage; $objRoot = \Contao\PageModel::findByPk( $objPage->rootId ); /** * To use this script, please fill in your Google Analytics ID below */ $GoogleAnalyticsId = $objRoot->analytics_google; /** * DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING! */ if ($GoogleAnalyticsId != 'GTM-XXXXXXXXXX' && !BE_USER_LOGGED_IN && !$this->hasAuthenticatedBackendUser()): ?> <script id="googletagmanager_<?= $GoogleAnalyticsId; ?>"> // Google Consent Mode window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag("consent", "default", { ad_user_data: "denied", ad_personalization: "denied", ad_storage: "denied", analytics_storage: "denied", personalization_storage: "denied", security_storage: "denied", functionality_storage: "denied", wait_for_update: 2000 // milliseconds to wait for update }); gtag('config', '<?= $GoogleAnalyticsId ?>',{'anonymize_ip': true}); // Enable ads data redaction by default [optional] gtag("set", "ads_data_redaction", true); // Optin privacy setting token var token = localStorage.getItem('user_privacy_settings'); if( token == undefined ) { token = ''; } if(token.indexOf(3) >= 0) { gtag("consent", "update", { ad_user_data: "granted", ad_personalization: "granted", ad_storage: "granted", analytics_storage: "granted", personalization_storage: "granted", security_storage: "granted", functionality_storage: "granted" }); } // listen to privacy event jQuery(document).on('Privacy.changed',function(eve nt,params) { if(params.level.indexOf(3) >= 0) { gtag("consent", "update", { ad_user_data: "granted", ad_personalization: "granted", ad_storage: "granted", analytics_storage: "granted", personalization_storage: "granted", security_storage: "granted", functionality_storage: "granted" }); } }); // Optin privacy setting token if(token.indexOf(3) >= 0) { (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:''; j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','<?= $GoogleAnalyticsId; ?>'); } // listen to privacy event jQuery(document).on('Privacy.changed',function(eve nt,params) { if(params.level.indexOf(3) >= 0) { //location.reload(); (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:''; j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','<?= $GoogleAnalyticsId; ?>'); } }); </script> <?php endif; ?>
<?php
global $objPage;
$objRoot = \Contao\PageModel::findByPk($objPage->rootId);
/**
* To use this script, please fill in your Google Analytics ID below
*/
$GoogleAnalyticsId = $objRoot->analytics_google;
/**
* DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
*/
if ($GoogleAnalyticsId != 'GTM-XXXXXXXXXX' && !BE_USER_LOGGED_IN && !$this->hasAuthenticatedBackendUser()): ?>
<script id="googletagmanager_<?= $GoogleAnalyticsId; ?>">
// Google Consent Mode
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag("consent", "default", {
ad_user_data: "denied",
ad_personalization: "denied",
ad_storage: "denied",
analytics_storage: "denied",
personalization_storage: "denied",
security_storage: "denied",
functionality_storage: "denied",
wait_for_update: 2000 // milliseconds to wait for update
});
// Enable ads data redaction by default [optional]
gtag("set", "ads_data_redaction", true);
gtag("js", new Date());
gtag('config', '<?= $GoogleAnalyticsId ?>', {'anonymize_ip': true});
// Optin privacy setting token
var token = localStorage.getItem('user_privacy_settings');
if (token == undefined) {
token = '';
}
if (token.indexOf(3) >= 0) {
gtag("consent", "update", {
ad_user_data: "granted",
ad_personalization: "granted",
ad_storage: "granted",
analytics_storage: "granted",
personalization_storage: "granted",
security_storage: "granted",
functionality_storage: "granted"
});
}
// Listen to privacy event
jQuery(document).on('Privacy.changed', function(event, params) {
if (params.level.indexOf(3) >= 0) {
gtag("consent", "update", {
ad_user_data: "granted",
ad_personalization: "granted",
ad_storage: "granted",
analytics_storage: "granted",
personalization_storage: "granted",
security_storage: "granted",
functionality_storage: "granted"
});
}
});
// Optin privacy setting token
if (token.indexOf(3) >= 0) {
(function(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({'gtm.start': new Date().getTime(), event: 'gtm.js'});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '<?= $GoogleAnalyticsId; ?>');
}
// Listen to privacy event
jQuery(document).on('Privacy.changed', function(event, params) {
if (params.level.indexOf(3) >= 0) {
//location.reload();
(function(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({'gtm.start': new Date().getTime(), event: 'gtm.js'});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '<?= $GoogleAnalyticsId; ?>');
}
});
</script>
<?php endif; ?>
Kommentar