When you use Server-side Google Tag Manager, you can use our integration to send the collected data to Piwik PRO. The integration uses a dedicated client template and tag in Server-side Google Tag Manager. The tag sends tracked events from Google to Piwik PRO in real time.
To integrate, you’ll have to add a site or app in Piwik PRO, then set up our dedicated client template and tag in Server-side Google Tag Manager and finally set up custom tracking in Piwik PRO.
Before you start
Here are some things to know before you start:
- Needed permissions in Piwik PRO: owner.
- Needed permissions in Server-side Google Tag Manager: administrator.
- Our client template and tag template are also described in this blog post.
- If you want to contribute to the template development, here are the links to our GitHub repositories:
Add a site or app in Piwik PRO
To add a site or app in Piwik PRO, follow these steps:
- Go to Menu > Administration.
- Navigate to Sites & apps.
- Click Add a site or app.
- Type the site or app name and address and click Save.
Note: If you want to track a few domains, add their addresses.
- Set the time zone and currency.
Note: We’ll show data in reports in this time zone. We’ll use this currency for goal revenue.
Install our client template
The Piwik PRO Client template is designed to capture requests from Piwik PRO’s client-side libraries.
To install our client template, follow these steps:
- Download our client template.
- Log in to Google Tag Manager.
- Open your server-side container.
- Go to Templates.
- In Client Templates, click New.
- Click the ⋯ three-dot icon in the upper right corner and select Import.
- Upload the template you’ve downloaded in step 1.
- Click Save.
- Navigate to Clients.
- Click New.
- Select Piwik PRO Client from the list of available templates.
- Click Submit.
- Click Publish.
- That’s done!
Install our tag template
The tag template’s purpose is to compose an HTTP request to your Piwik PRO account.
To install our tag template, follow these steps:
- In Server-side Google Tag Manager, go to Tags.
- Click New.
- Name your tag. Example:
Piwik PRO
. - Click Choose a tag type to begin setup…
- Click Discover more tags in the Community Template Gallery.
- Click on the search icon and type in Piwik PRO. Our tag will appear in the search results. Make sure it is the original one, made by Piwik PRO.
- Click Piwik PRO.
- Click Add to workspace.
- Click Add to confirm your choice.
- In Triggering, click Choose a trigger to make this tag fire…
- Add a new custom trigger with the following condition:
Client Name equals Piwik PRO Client
. - Click Submit.
- Click Publish.
- That’s also done!
Method 1: Set up tracking in Piwik PRO
Once the client template and tag template are added, you need to set up tracking. This method assumes you’re using Piwik PRO to collect data.
To set up tracking, follow these steps:
- Log in to Server-side Google Tag Manager.
- Go to Admin > Container settings.
- Copy Server container URLs.
- Log in to Piwik PRO.
- Go to Menu > Tag Manager > Tags and turn off Piwik PRO tag (tracking code). In the next steps, you’ll set up custom tracking.
- Set up your custom tracking depending on Consent Manager settings:
(Case 1) If Menu > Administration > Sites & apps > Privacy > Ask visitors for consent (on) and Collect anonymous data from non-consenting visitors (on) > Use visitor cookies (on)
In the tracking code below, replace<site-app-ID>
with your site ID (Where to find it?), replacehttps://example.com/ppms.php
with the copied server container URL from GTM and added/ppms.php
, replacehttps://youraccountname.containers.piwik.pro/ppms.js
with your account address and add the code as:
Tag type: Custom code
Consent type: No consent is required
Trigger: All page views<script> var _paq = window._paq || []; (function () { var trackAnonymously = {{ Piwik PRO Anonymization }}('analytics'); if (trackAnonymously) { _paq.push(['setUserIsAnonymous', 1]); _paq.push(['setVisitorCookieTimeout', 1800]); } }()); _paq.push(['setTrackingSource', 'jstc_tm']); _paq.push(['enableLinkTracking']); _paq.push(['setDomains', ['www.example.com', 'shop.example.com']]); // Add this line only if you use this tag on more than one domain _paq.push(['setCookieDomain', '.example.com']); // Add this line only if you have cross-subdomain tracking _paq.push(['setSecureCookie', 1]); _paq.push(['trackPageView']); _paq.push(['enableJSErrorTracking']); (function(p,i,w,ik) { var g=ik.createElement('script'),s=ik.getElementsByTagName('script')[0]; _paq.push(['setTrackerUrl', p]); _paq.push(['setSiteId', w]); g.type='text/javascript';g.async=true;g.defer=true;g.src=i;s.parentNode.insertBefore(g,s); })('https://example.com/ppms.php','https://youraccountname.containers.piwik.pro/ppms.js','<site-app-ID>',document) </script>
Add this deanonymization code as:
Tag type: Custom code
Consent type: Analytics
Trigger: All page views<script> var _paq = window._paq || []; (function () { var consents = {{ Consents }}; var consentType = 'analytics'; if (typeof consents !== 'undefined' && consents.hasOwnProperty('current_state') && consents.current_state.hasOwnProperty(consentType) && consents.current_state[consentType] === 1 && consents.hasOwnProperty('previous_state') && consents.previous_state.hasOwnProperty(consentType) && consents.previous_state[consentType] !== 1 ) { _paq.push(['deanonymizeUser']); _paq.push(['setVisitorCookieTimeout', 33955200]); } }()); </script>
(Case 2) If Menu > Administration > Sites & apps > Privacy > Ask visitors for consent (on) and Collect anonymous data from non-consenting visitors (on) > Use a session hash (on)
In the tracking code below, replace<site-app-ID>
with your site ID (Where to find it?), replacehttps://example.com/ppms.php
with the copied server container URL from GTM and added/ppms.php
, replacehttps://youraccountname.containers.piwik.pro/ppms.js
with your account address and add the code as:
Tag type: Custom code
Consent type: No consent is required
Trigger: All page views<script> var _paq = window._paq || []; (function () { var trackAnonymously = {{ Piwik PRO Anonymization }}('analytics'); if (trackAnonymously) { _paq.push(['setUserIsAnonymous', 1]); _paq.push(['disableCookies']); } }()); _paq.push(['setTrackingSource', 'jstc_tm']); _paq.push(['enableLinkTracking']); _paq.push(['setDomains', ['www.example.com', 'shop.example.com']]); // Add this line only if you use this tag on more than one domain _paq.push(['setCookieDomain', '.example.com']); // Add this line only if you have cross-subdomain tracking _paq.push(['setSecureCookie', 1]); _paq.push(['enableHeartBeatTimer']); _paq.push(['trackPageView']); _paq.push(['enableJSErrorTracking']); (function(p,i,w,ik) { var g=ik.createElement('script'),s=ik.getElementsByTagName('script')[0]; _paq.push(['setTrackerUrl', p]); _paq.push(['setSiteId', w]); g.type='text/javascript';g.async=true;g.defer=true;g.src=i;s.parentNode.insertBefore(g,s); })('https://example.com/ppms.php','https://youraccountname.containers.piwik.pro/ppms.js','<site-app-ID>',document) </script>
Add this deanonymization code as:
Tag type: Custom code
Consent type: Analytics
Trigger: All page views<script> var _paq = window._paq || []; (function () { var consents = {{ Consents }}; var consentType = 'analytics'; if (typeof consents !== 'undefined' && consents.hasOwnProperty('current_state') && consents.current_state.hasOwnProperty(consentType) && consents.current_state[consentType] === 1 && consents.hasOwnProperty('previous_state') && consents.previous_state.hasOwnProperty(consentType) && consents.previous_state[consentType] !== 1 ) { _paq.push(['deanonymizeUser']); _paq.push(['enableCookies']); } }()); </script>
(Case 3) If Menu > Administration > Sites & apps > Privacy > Ask visitors for consent (off)
In the tracking code below, replace<site-app-ID>
with your site ID (Where to find it?), replacehttps://example.com/ppms.php
with the copied server container URL from GTM and added/ppms.php
, replacehttps://youraccountname.containers.piwik.pro/ppms.js
with your account address and add the code as:
Tag type: Custom code
Consent type: No consent is required
Trigger: All page views<script> var _paq = window._paq || []; _paq.push(['setTrackingSource', 'jstc_tm']); _paq.push(['enableLinkTracking']); _paq.push(['setDomains', ['www.example.com', 'shop.example.com']]); // Add this line only if you use this tag on more than one domain _paq.push(['setCookieDomain', '.example.com']); // Add this line only if you have cross-subdomain tracking _paq.push(['setSecureCookie', 1]); _paq.push(['enableHeartBeatTimer']); _paq.push(['trackPageView']); _paq.push(['enableJSErrorTracking']); (function(p,i,w,ik) { var g=ik.createElement('script'),s=ik.getElementsByTagName('script')[0]; _paq.push(['setTrackerUrl', p]); _paq.push(['setSiteId', w]); g.type='text/javascript';g.async=true;g.defer=true;g.src=i;s.parentNode.insertBefore(g,s); })('https://example.com/ppms.php','https://youraccountname.containers.piwik.pro/ppms.js','<site-app-ID>',document) </script>
- Check to see if your tracking works correctly in the tracker debugger. Read more
- All done!
Method 2: Set up tracking in Google Tag Manager
Once the client template and tag template are added, you need to set up tracking. This method assumes you’re using Piwik PRO Analytics tag in Google Tag Manager to collect data.
To set up tracking, follow these steps:
- Log in to Server-side Google Tag Manager.
- Go to Admin > Container settings.
- Copy Server container URLs.
- Go to Google Tag Manager.
- Open your regular container.
- Navigate to Tags > Piwik PRO Analytics.
- In Account setup, select Use a custom tracker URL.
- Enter the copied server container URL from GTM and added
/ppms.php
, for example:https://example.com/ppms.php
. - Click Save.
- Click Publish.
- Check to see if your tracking works correctly in the tracker debugger. Read more
- All done!
Map Piwik PRO to GA4 data stream
If you’re using Server-side GTM to collect GA4 data, you can map it to Piwik PRO by following the guidelines in this blog post. We plan to implement an easier mapping method in the future.