Running 2 Piwik Pro Tag Managers on the same website

Case:
A Site has an existing PP Site (TM + Consent Mgr + Analytics) running, let’s call it “OLD”.
The TM setup is so messed up that it needs to be replaced by a better setup, let’s call it “NEW”.

For some weeks, we also want to compare numbers between OLD and NEW, so both need to run in parallel.

I cannot change the code on the website for now.

Can I load NEW via Custom Code in OLD if I deactivate the Consent Management in NEW (so the users won’t need to consent twice)?

I read Can I use Piwik PRO and Matomo at the same time? | Piwik PRO help center, but it does not seem to be exactly what I need.

Hi @loldenburg,

Can I load NEW via Custom Code in OLD if I deactivate the Consent Management in NEW (so the users won’t need to consent twice)?

No, it’s not possible. You will see this error in your browser’s console:
Uncaught Error: Attempting to initialize a second container. Multiple PPAS async containers on one page are not supported. Make sure container code is added to the site only once.

  1. Do you want to setup a separate tag manager instance because the old one is cluttered? Maybe using the meta setup on top of the existing (old) container would be a good idea?

  2. Do you want to setup a separate tag manager instance because you want to add an additional tracker to the website? Perhaps adding a second tracker (that points to a different site UUID) in the existing container would be a solution for this?

The second solution is usually a bit more tricky to set up, so let me know in case additional details are needed.

1 Like

@anthonybartczak thanks

“1. Do you want to setup a separate tag manager instance because the old one is cluttered?”

=> yes, partially, but the new TM Setup should also be for more than just this one site. Basically this one site is the pilot for an overarching setup where multiple PP Containers on very similar sites with completely redundant setups will be replaced by one central setup.

“Maybe using the meta setup on top of the existing (old) container would be a good idea?”

=> I looked at the “Meta Sites” and I was initially very inclined to try that, but there are plenty of downsides (most importantly, roll-up properties with separate visitor namespaces, see Use meta sites & apps to merge data and create a meta setup in Tag Manager | Piwik PRO help center : “A meta site/app combines data from connected entities but doesn’t track visitors across domains or subdomains. A visitor who moves from one site to another is counted separately for each site.”).

Just to understand it fully:

a) When using a Meta Site, if I can configure a central PP Analytics Tag in the Meta Site Container and all sites would be tracked with this PP Analytics Tag IN ADDITION to the existing PP Tag on the sub-sites belonging to the Meta Site?

b) Would the Meta Site-based PP Analytics tag also have separate visitor namespaces from site to site, or would setting it up in the Meta Site avoid that?

“2. Do you want to setup a separate tag manager instance because you want to add an additional tracker to the website?”
=> It’s more than that, as pointed out in 1.

Hmm I tried this but it seems Meta Sites do not allow for setting up a Piwik Pro Analytics tag at all…
Which means we would need to have redundant PP Analytics tags in all sub-sites…
So this is not an option for us, if the multiple namespaces problem cannot be resolved.

Yeah, you are correct - there is no way of using the Piwik PRO tracking tag template inside a meta setup. There are some technical limitations when it comes to pulling the site configuration from the Administration module to the meta setup. Maybe it will change in the future.

I think you should be able to add the tracking code in a “less user friendly” way tho. You can pretty much copy and paste the tracking code (Piwik PRO tracking template) from your website’s source code (or the tag manager debugger) and add it to a custom HTML tag in the meta setup. It’s not a perfect solution as some of the settings (e.g. setting the domains, disabling cookies) have to be done in this piece of code by using the _paq API.

It would be also beneficial to change the site UUID based on the current URL or hostname ({{ Site UUID lookup table }} in this example).

<script type="text/javascript">
    var _paq = _paq || [];
    (function () {
        var trackAnonymously = {{ Piwik PRO Anonymization }}('analytics');
        if (trackAnonymously) {
            _paq.push(['setUserIsAnonymous', 1]);
            _paq.push(['disableCookies']);
        }
    }());
</script>
<script type="text/javascript">
    var _paq = _paq || [];
    _paq.push(['setTrackingSource', 'jstc_tm']);
    _paq.push(['setSessionIdStrictPrivacyMode', true]);
    _paq.push(['enableLinkTracking']);
    _paq.push(['setIpTracking', true]);
    _paq.push(['setDomains', ['example.com']]);
    _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://abartczak.piwik.pro/ppms.php','https://abartczak.containers.piwik.pro/ppms.js',{{ Site UUID lookup table }},document)
</script>

You should be able to add a second tracker if needed by calling addTracker.

And this would probably also require having a deanonymization tag which can also be yoinked from the tag manager debugger. That’s because if you turn off the Piwik PRO tracking tag it will also disable the deanonymization one as well.

<script type="text/javascript">
    var _paq = window._paq || [];
    (function () {
        var consents = {{ Consents }};
        var consentType = 'analytics';
        _paq.push(['setVisitorCookieTimeout', 33955200]);
        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']);
        }
    }());
</script>

Some disadvantages of this would be:

  • No access to the tag priority feature
  • Code is less user friendly than UI (imo)
  • Goals added through the meta setup have to be triggered per site (e.g. hostname condition) as a single goal UUID is unique to the Piwik PRO site it was created on.

Thanks, but I don’t think this is a viable option for me, because I would have to set up everything in Custom Code, and then later when the 1 month of parallel runs is over, I would have to move it all to the native PP TM UI again. It’s a huge setup with 80 tags and triggers per site (never seen so much redundancy, the agency which did this setup should be paying me as a penalty, not the client), so I can’t redo everything twice (once in CUstom COde and then back to the “normal way”).