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 anddataLayer
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:
- Log in to Piwik PRO.
- Go to Menu > Tag Manager.
- Navigate to Tags.
- Click Add a tag.
- Name the tag and select the following type: Custom code (async) (custom asynchronous tag).
- Click Next.
- In Tag code, type the code.
- 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.
Note: This step is the most important in the 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 OK. In this way, a data layer event will be sent every time the visitor refreshes the page.
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.
- When you’re done, click Save for the tag.
- Repeat the process for 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.
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:
- Log in to Google Tag Manager.
- Open your container.
- On the left, click Variables.
- In User-defined variables, click New.
- Name the variable.
- Pick Data Layer Variable.
- Paste the variable name that you used in the code in Piwik PRO Tag Manager. In our case, it’ll be
analytics_consent
.
- Click Save.
- 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:
- 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. For example,
analytics_consent contains on
.
- Repeat the process for other triggers that you want to modify.
- After the triggers are ready, add them to the tags.