How to integrate Consent Manager with Google Tag Manager

Necessary tools: Consent Manager + Tag Manager

When you want to fire tags in Google Tag Manager in accordance with the consent given in Piwik PRO Consent Manager, you need to set up a manual integration. To do this, you need to create data layer events in Piwik PRO Tag Manager that will store the consent information and pass it to Google Tag Manager.

In this article, we’ll explain how to set up such an integration.

Before you start

Here are some things to know before you start the setup:

  • First, set up your Consent Manager and decide which consent types you’ll need to use.
  • When you use the data layer in other tools, we recommend using a custom data layer name in Piwik PRO. In this integration, you can use pptmDataLayer for Piwik PRO Tag Manager and dataLayer for Google Tag Manager.

Create a tag and trigger in Piwik PRO Tag Manager

We’ll start with creating a tag and trigger in Piwik PRO Tag Manager that will send a data layer event when a visitor gives consent.

We’ll use the following code:

<script>
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({
'event': 'stg.consentDecision',
'analytics_consent': ‘on’
  });
</script>

In this code, you can change:

  • 'event': 'stg.consentDecision',: this is the name of the event.
  • 'analytics_consent': ‘on’: this is the consent type. You can use the following consent types: analytics_consent, marketing_consent, abtesting_consent, conversion_tracking_consent, marketing_automation_consent, remarketing_consent, user_feedback_consent and custom_type_consent.

To create a tag, follow these steps:

  1. Log in to Piwik PRO.
  2. Go to Menu > Tag Manager.
  3. Navigate to Tags.
  4. Click + Create new tag.
  5. Name the tag and select the Custom asynchronous tag template.
  6. In Tag HTML code, type the code.
  7. Code for integrating Google Tag Manager with Piwik PRO Consent Manager.
  8. In Advanced tag settings, set the same tag type as you’re using in the code. For example, when you use analytics_consent set Analytics.
  9. Tag settings in Piwik PRO.

    Note: This step is the most important in the setup because it links Piwik PRO consents with Google Tag Manager.

  10. In Tag triggers, click + Existing trigger to set up a trigger for your tag.
  11. Pick All page views and click OK. In this way, a data layer event will be sent every time the visitor refreshes the page.
  12. Tag triggers in Piwik PRO.

    Note: If you are using page view triggers in Google Tag Manager, you need to change them to window loaded so that they fire after the information about consent is received.

  13. When you’re done, click Save for the tag.
  14. Repeat the process for other consent types you want to have in Google Tag Manager.
  15. Test your tags in debug mode.
  16. When you’re happy how the tags work, click Publish.

Create a variable in Google Tag Manager

Now we need to set up variables in Google Tag Manager that will fetch information about consent types from the data layer events. 

To create a variable, follow these steps:

  1. Log in to Google Tag Manager.
  2. Open your container.
  3. On the left, click Variables.
  4. In User-defined variables, click New.
  5. Name the variable.
  6. Pick Data Layer Variable.
  7. Paste the variable name that you used in the code in Piwik PRO Tag Manager. In our case, it’ll be analytics_consent.
  8. The data layer name in Google Tag Manager.
  9. Click Save.
  10. Repeat the process for other data layer events that you’ve set in Piwik PRO Tag Manager.

Add a trigger in Google Tag Manager

After creating variables, you can use them to build new triggers or set conditions for existing triggers.

To add a trigger, follow these steps:

  1. Log in to Google Tag Manager.
  2. Open your container.
  3. On the left, click Triggers
  4. Add a new trigger or edit an existing trigger.
  5. In This trigger fires on, set the condition based on your variable. For example, analytics_consent contains on.
  6. A trigger in Google Tag Manager.
  7. Repeat the process for other triggers that you want to modify.
  8. After the triggers are ready, add them to the tags.
A trigger in Google Tag Manager.
Was this article helpful?

Technical Support

If you have any questions, drop us a line at support_SPC@piwik_SPC.pro.

We’re happy to help!