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 anddataLayer
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:
- Log in to Piwik PRO.
- Go to Menu > Tag Manager.
- Navigate to Tags.
- Click Add a tag.
- Name your tag and select the following type: Custom code (async).
- Click Next.
- In Tag code, type your code.
- In Advanced tag settings, set the same tag type as you use in your code. For example, if you use
analytics_consent
, set Analytics.Note: This step is the most important in the entire setup because it links Piwik PRO consents with Google Tag Manager.
- In Tag triggers, click Choose existing trigger to set up a trigger for your tag.
- 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.
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.
- When you’re done, click Save.
- Repeat steps 3–11 for the other consent types you want to have in Google Tag Manager.
- Test your tags in debug mode.
- When you’re happy with how the tags work, click Publish.
- 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:
- Log in to Google Tag Manager.
- Open your container.
- On the left, click Variables.
- In User-defined variables, click New.
- Name your variable.
- Pick Data Layer Variable.
- Paste the variable name you used in your code in Piwik PRO Tag Manager. In our example, it is
analytics_consent
. - Click Save.
- Repeat steps 4–8 for the other data layer events you’ve set in Piwik PRO Tag Manager.
- 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:
- Log in to Google Tag Manager.
- Open your container.
- On the left, click Triggers
- Add a new trigger or edit an existing trigger.
- In This trigger fires on, set the condition based on your variable. Example:
analytics_consent contains on
. - Repeat steps 3–5 for the other triggers you want to modify.
- When your triggers are ready, add them to your tags.
- All done!