Google consent mode integration

Consent Manager + Tag Manager

On 13 November, Google made changes to the way Google ads are displayed. The visitor must consent to analytics and advertising cookies, otherwise Google will not show ads to this visitor.

Google relies on two consent mechanisms: IAB TCF 2.0 or Google consent mode (which is currently in beta testing). We’re currently working on integrating Piwik PRO with IAB TCF 2.0, and before this setup is ready, we advise you to use Consent Manager with a custom-made integration with Google consent mode. In this article, we’ll explain how to apply it.

Before you start

Here are some things to know before you set up the integration:

  • This integration works only if you have the Google’s global site tag (aka gtag.js) installed on your website. To add it, follow Google’s instructions.
  • You need to use Consent Manager that collects visitors’ consents. This integration will only pass information received by Consent Manager.
  • We’ll use four tags to communicate with Google: Analytics storage consent granted, Analytics storage consent removed, Ad storage consent granted, Ad storage consent removed.

To integrate with Google consent mode, you will use four codes:

  • Analytics storage consent granted
    <script>
      gtag(
      'consent',
      'update',
      {
    	'analytics_storage': 'granted'
    })
    </script>
  • Analytics storage consent removed
    <script>
      gtag(
      'consent',
      'update',
      {
    	'analytics_storage': 'denied'
    })
    </script>
  • Ad storage consent granted
    <script>
      gtag(
      'consent',
      'update',
      {
    	'ad_storage': 'granted'
    })
    </script>
  • Ad storage consent removed
    <script>
      gtag(
      'consent',
      'update',
      {
    	'ad_storage': 'denied'
    })
    </script>

To set up each code, follow these steps:

  1. Go to Menu > Tag Manager.
  2. Navigate to Tags.
  3. Click Add new tag.
  4. Name the tag and select the following type: Custom asynchronous tag.
  5. Click Next.
  6. In Tag code, type your code.
    Google consent mode integration in Piwik PRO
  7. In Advanced tag settings > Consent type, choose the following type: Analytics. The tag will fire only when selected consent is given by a visitor.
    Google consent mode integration in Piwik PRO

    Note: Add the following consent types:

    • Analytics storage consent granted > Consent type: Analytics 
    • Analytics storage consent removed > Consent type: Analytics
    • Ad storage consent granted > Consent type: Remarketing
    • Ad storage consent removed > Consent type: Remarketing
  8. In Tag triggers, click Add new trigger.
  9. Name the trigger. For example, Consent updated.
  10. In Event type, choose the following type: Data layer event.
    A data layer event trigger in Piwik PRO
  11. Click Next.
  12. In Data layer event settings, set the following condition: Event name contains stg.consentsWereSent.
    Google consent mode integration in Piwik PRO
  13. When you’re done, click OK for the trigger.

    Note: Each code for integrating with Google consent mode will use the same trigger, so after creating it for the first time, you can choose it when creating a tag under Tag triggers > Choose existing trigger.

  14. In Tag triggers, click Choose existing trigger.
  15. Choose the following trigger: All page views and click OK.
    Google consent mode integration in Piwik PRO
  16. Click OK for the tag.
  17. Test your tag in debug mode.
  18. When you’re happy how the tag works, click Publish.
  19. Repeat these steps for remaining codes: Analytics storage consent removed, Ad storage consent granted and Ad storage consent removed.
Was this article helpful?

Be the first to rate this article.

Technical support

If you still have some questions, visit our community.
There’s always someone ready to help!

Related articles

Back to help center