Consent Manager integration with Google Tag Manager

Tag Manager

Consent 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:

  • You need to set up your Consent Manager first and decide which consent types you want to use.
  • When you use a 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

To begin, we’ll create a tag and trigger in Piwik PRO Tag Manager to send a data layer event when a visitor consents.

We’ll use the following code:

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

Parameters

‘event’: ‘stg.consentDecision’
The name of the event.

‘analytics_consent’: ‘on’
The type of the consent. Possible values: 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 your tag and select the following type: Custom code (async).
  6. Click Next.
  7. In Tag code, type your code.
    Tag Manager in Piwik PRO
  8. In Advanced tag settings, set the same tag type as you use in your code. For example, if you use analytics_consent, set Analytics.
    Tag Manager in Piwik PRO

    Note: This step is the most important in the entire 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 Save. We use All page views because it makes sure that a data layer event is sent every time a user refreshes a page.
    Tag Manager in Piwik PRO

    Note: If you’re using page view triggers in Google Tag Manager, you’ll need to change them to window-loaded to fire when consent details are received.

  11. When you’re done, click Save.
  12. Repeat steps 3–11 for the other consent types you want to have in Google Tag Manager.
  13. Test your tags in debug mode.
  14. When you’re happy with how the tags work, click Publish.
  15. Done!

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 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 your variable.
  6. Pick Data Layer Variable.
  7. Paste the variable name you used in your code in Piwik PRO Tag Manager. In our example, it is analytics_consent.
    Google Tag Manager
  8. Click Save.
  9. Repeat steps 4–8 for the other data layer events you’ve set in Piwik PRO Tag Manager.
  10. Done!

Add a trigger in Google Tag Manager

After creating variables, you can use them to create 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. Example: analytics_consent contains on.
    Google Tag Manager
  6. Repeat steps 3–5 for the other triggers you want to modify.
  7. When your triggers are ready, add them to your tags.
    Google Tag Manager
  8. All done!

Was this article helpful?

Technical support

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

Related articles

Back to help center