Since November 2020, Google ads require visitor consent to be 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). To be compliant with Google’s regulations, you can use Consent Manager and 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.
- This integration doesn’t work with Google Tag Manager. To integrate with Google Tag Manager, use these 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.
Integrate with Google consent mode
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:
- Go to Menu > Tag Manager.
- Navigate to Tags.
- Click Add a tag.
- Name the tag and select the following type: Custom code (async).
- Click Next.
- In Tag code, type your code.
- In Advanced tag settings > Consent type, choose the following type: Analytics. This tag will fire only for visitors who accept the selected consent type.
Note: Add the following consent types:
- Analytics storage consent granted > Consent type: Analytics
- Analytics storage consent removed > Consent type: Doesn’t require consent
- Ad storage consent granted > Consent type: Remarketing
- Ad storage consent removed > Consent type: Doesn’t require consent
- In Tag triggers, click Add a trigger.
- Name the trigger. For example,
Consent updated
. - In Event type, choose the following type: Data layer event.
- Click Next.
- In Data layer event settings, set the following condition:
Event name contains stg.consentsWereSent
.
- 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.
- In Tag triggers, click Choose existing trigger.
- Choose the following trigger: All page views and click OK.
- Click OK for the tag.
- Test your tag in debug mode.
- When you’re happy how the tag works, click Publish.
- Repeat these steps for remaining codes: Analytics storage consent removed, Ad storage consent granted and Ad storage consent removed.