-
-
Save leonkorteweg/03765d311af843e8c59f8344f45e3cea to your computer and use it in GitHub Desktop.
Piwik Pro: Consent Mode Update Script
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
<script> | |
window.gtag = window.gtag || function(){dataLayer.push(arguments)}; | |
function googleConsentModeMapping(consents) { | |
if ({{ Consents }}) { | |
var consObj = {}; | |
Object.keys(consents).forEach(function(consent) { | |
consObj[consent] = ({{ Consents }}.current_state[consents[consent]] === 1) ? 'granted' : 'denied'; | |
}); | |
gtag('consent', 'update', consObj); | |
} | |
dataLayer.push({ 'event': 'consent_mode_update' }); | |
// gtag('consent', 'update', { | |
// 'analytics_storage': 'granted' | |
// }); | |
} | |
// Call the function with specific consent mappings; these mappings can be adjusted as needed | |
googleConsentModeMapping({ | |
"ad_storage": "remarketing", | |
"ad_user_data": "remarketing", | |
"ad_personalization": "remarketing", | |
"analytics_storage": "analytics" | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment