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

Simple Mode

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

<script>
  window.dataLayer = window.dataLayer || []
  function gtag() {
    dataLayer.push(arguments)
  }
  gtag('consent', 'default', {
    ad_storage: 'denied',
    analytics_storage: 'denied',
    ad_user_data: 'denied',
    ad_personalization: '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',
          ad_user_data: 'granted',
          ad_personalization: 'granted',
        })
      }
    }
  })
</script>

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

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

<script>
  window.dataLayer = window.dataLayer || []
  function gtag() {
    dataLayer.push(arguments)
  }
  gtag('consent', 'default', {
    ad_storage: 'denied',
    analytics_storage: 'denied',
    ad_user_data: 'denied',
    ad_personalization: 'denied',
  })
</script>

The above codes communicate with Google services via Consent Mode V2 api. Find more about Google Consent Mode V2