Consent Manager integration with Google Tag Manager

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 Add a tag.
  5. Name the tag and select the following type: Custom code (async) (custom asynchronous tag).
  6. Click Next.
  7. In Tag code, type the code.
    Tag Manager in Piwik PRO
  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.
    Tag Manager in Piwik PRO

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

  9. In Tag triggers, click Choose existing trigger to set up a trigger for your tag.
  10. Pick All page views and click OK. In this way, a data layer event will be sent every time the visitor refreshes the page.
    Tag Manager 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.

  11. When you’re done, click Save for the tag.
  12. Repeat the process for other consent types you want to have in Google Tag Manager.
  13. Test your tags in debug mode.
  14. 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.
    Google Tag Manager
  8. Click Save.
  9. 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.
    Google Tag Manager
  6. Repeat the process for other triggers that you want to modify.
  7. After the triggers are ready, add them to the tags.
    Google Tag Manager

Was this article helpful?

Technical support

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

Related articles

Back to help center