sybrew/the-seo-framework

Google Tag Manager connection

Closed this issue · 1 comments

Using the Cord extension of TSF I can connect my WordPress site directly to Google Analytics using the Measurement ID.
I would like to be able to connect my site to Google Tag Manager too.

Using Google Tag Manager we manage

  • our cookie wall
  • Google Consent mode
  • our connection to Google Analytics

Sorry for the delay; I thought this was a feature request, but this appears to be more custom: We can not know how you've set up cookies.

After wp_body_open priority 0 (so 1 or later), function gtag() is available. Thence, you can implement scripts like this (source):

<script>
  gtag('consent', 'default', {
    'ad_storage': 'denied',
    'ad_user_data': 'denied',
    'ad_personalization': 'denied',
    'analytics_storage': 'denied'
  });
</script>

Once a user accepts some cookies, you can update that by calling the consentGrantedAdStorage() function as below:

<script>
  function consentGrantedAdStorage() {
    gtag('consent', 'update', {
      'ad_storage': 'granted'
    });
  }
</script>

There's a lot to tinker with here, and the correct approach depends on how you've set up the cookies.

If you like a more encompassing solution, you could try Google Site Kit. Note that it will slow down your site.