- Add a new "External script" for the default "consent to track" behavior:
- Name it e.g. "Google Analytics (default)"
- Set State to Enabled
- Script target set to Every page - Every user
- Set Script position to In Head Section
- Script Cookie Tags
- Performance should be unchecked
- Analytics should be unchecked
- Marketing should be unchecked
- Click on the diskette icon to copy the script below and then paste it into the Code text box
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'default', {
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'ad_storage': 'denied',
'analytics_storage': 'denied',
'wait_for_update': 500,
});
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
Externí script #1 – Google Analytics (default)
- Add a new "External script" for advanced "consent to track" behavior:
- Name it e.g. "Google Analytics (advanced)"
- Set State to Enabled
- Script target set to Every page - Every user
- Set Script position to Before Body End
- Script Cookie Tags
- Performance should be unchecked
- Analytics should be checked
- Marketing should be checked
- Click on the diskette icon to copy the script below and then paste it into the Code text box
<script>
let consent= window.getCookie('.AspNet.Consent');
if (consent == 'yes') {
localStorage.setItem("consentGranted", "true");
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'update', {
ad_user_data: 'granted',
ad_personalization: 'granted',
ad_storage: 'granted',
analytics_storage: 'granted'
});
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=TAG_ID';
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(gtagScript,firstScript);
} else if (document.getElementById('accept-all-btn')) {
document.getElementById('accept-all-btn').addEventListener("click", function() {
localStorage.setItem("consentGranted", "true");
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'update', {
ad_user_data: 'granted',
ad_personalization: 'granted',
ad_storage: 'granted',
analytics_storage: 'granted'
});
});
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=TAG_ID';
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(gtagScript,firstScript);
}
</script>
Externí script #2 – Google Analytics (advanced)
In Google Analytics, these changes can take up to 48 hours to take effect.
In order for Google Analytics to verify that everything is set up correctly after this time, it is necessary for the website to record at least 1 visit during this time to reconcile with the use of cookies.
Example of GA Consent v2 in unapproved form
Example of GA Consent v2 in approved form
Comments
0 comments
Please sign in to leave a comment.