Google global site tag (gtag.js) Integration

The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Ads, Campaign Manager, Display & Video 360, Search Ads 360, and Google Analytics.

Example of gtag.js and UniConsent Integration

Put the following tag just below UniConsent CMP tag and before your Google tags or any other advertising tags:

Copied
<script>
window.dataLayer = window.dataLayer || []
function gtag() {
dataLayer.push(arguments)
}
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
})
__tcfapi('addEventListener', 2, function (tcData, success) {
if (success && tcData.unicLoad === true) {
if (!window._unic_i) {
window._unic_i = true
gtag('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted',
})
}
}
})
</script>

The above codes delay all the Google tag cookies until the user grants consent.