# Multiple site IDs on the same page

**URL:** <https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532>\
**Category:** Data collection and tags\
**Created:** [January 25, 2024, 9:20am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532 "2024-01-25T09:20:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 25, 2024, 9:20am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/1 "2024-01-25T09:20:00Z")

</div>

Hi all,

I am trying to implement cross domain tracking and send data to one site ID in PP as well as sending data to a different site ID as per the structure here.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/0/009d447acf02ae6ca1458f023913fbd6106af5ec.png)

I have trouble using the Tag manager debug where the panel looks like this.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/4/4830f12cc2db25af2935a4a7bf420402e20f0fdc.png)

In Analytics debug events come in but I get javascript errors. Is it a problem to run two containers on the same website. GA has no trouble with multiple scripts. I assume I just don’t understand how PP does multiple scripts and how to debug. Single scripts work just fine. I humbly ask for advice.

Anders:)

---

<div class="post-metadata">

**Author:** ![asinior](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/asinior/32/1905_2.png) [@asinior](https://community.piwik.pro/u/asinior)\
**Post date:** [January 25, 2024, 9:52am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/2 "2024-01-25T09:52:50Z")

</div>

Hi,  
We have a great article on how to set up such an environment: [How can I set up Piwik PRO for multiple environments? | Piwik PRO help center](https://help.piwik.pro/support/questions/how-can-i-set-up-piwik-pro-for-multiple-environments/)

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 25, 2024, 11:23am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/3 "2024-01-25T11:23:51Z")

</div>

As far as I can tell, the solution in the article evaluates the hostname and chooses a PP ID based on which hostname is present. Maybe I don’t get the support article, but I don’t think this covers my case.

I want PP on the exact same hostname to send data to two different PP IDs. One ID is for the roll-up, and the other one is for the individual site (hostname, if you will). I.e. all domains will have ID1. So, for instance, [example-a.com](http://example-a.com) will have ID1 and ID2, [example-b.com](http://example-b.com) will have ID1 and ID3, [example-c.com](http://example-c.com) will have ID1 and ID4, and so on.

I am running two different PP container scripts on the same domain, as described above. I do get data into the PP roll-up, but I get javascript errors and I don’t see the tag manager debug working.

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 26, 2024, 2:33am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/4 "2024-01-26T02:33:40Z")

</div>

@mbaersch You have helped before:)

The idea is to fire two different containers and send the same data to each. The two requests for containers work, the first two in the list. It appears that only one ppms.php request is triggered. Why don’t two ppms.php calls get sent? One for each container? Doesn’t PP support multiple containers like GA does? If PP does, is there a config that I haven’t used?

Here are two clips, where the two containers fire as expected. There is only one ppms.php request, and it seems to arbitrarily fire based on one or the other container.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/8/8f093c6344a2864a66f72076e8428842fdfba15e.png)  
 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/3/3feacb91fad82cdca0b82f6b937ad96a6ff6dd6b.jpeg)

---

<div class="post-metadata">

**Author:** ![asinior](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/asinior/32/1905_2.png) [@asinior](https://community.piwik.pro/u/asinior)\
**Post date:** [January 26, 2024, 9:32am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/5 "2024-01-26T09:32:31Z")

</div>

Well, what I could also recommend from my side is to try to play around with the [**addTracker** method](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#addTracker) that should deal with your issue.

---

<div class="post-metadata">

**Author:** ![mbaersch](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mbaersch/32/35_2.png) [@mbaersch](https://community.piwik.pro/u/mbaersch)\
**Post date:** [January 26, 2024, 9:37am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/6 "2024-01-26T09:37:58Z")

</div>

I have no idea why two containers should be needed but however: two instances of PP might be the problem because they are using the same command queue and that could be the reason for your troubles. If so, one container would have to switch to the alternative namespace… maybe that helps? If my assumption is correct, you can compare cour problem to using PP and Matomo at the same time anf this the same fix could apply here as well. [Can I use Piwik PRO and Matomo at the same time? | Piwik PRO help center](https://help.piwik.pro/support/questions/can-i-use-piwik-pro-and-matomo-at-the-same-time/)

AFAIK there is no option to use \_ppas instead of \_paq, so you might need to deactivate all PP standard tags in one container and use costom html tags instead. But I am not sure about that.

best,  
Markus

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 28, 2024, 10:19am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/7 "2024-01-28T10:19:25Z")

</div>

Hi, I seem to be a bit closer by using the addTracker method. I now see two ppms.php calls, but they both get 404. The payloads look good. Do you have any idea about why they get 404? The URLs are correct.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/1/108702888089622b04b9b318d9d4c19612a34c2b.png)

This is the part of the script where the trackers get added:

// Add trackers after the Piwik Pro script is loaded  
tags.onload = function() {  
window.\_paq = window.\_paq || ;  
window.\_paq.push([‘setTrackerUrl’, ‘[https://norges.containers.piwik.pro/ppms.php](https://norges.containers.piwik.pro/ppms.php)’]);  
window.\_paq.push([‘setSiteId’, ‘19c287e6-e375-4b6c-b93b-038’]);  
window.\_paq.push([“addTracker”, “[https://norges.containers.piwik.pro/ppms.php](https://norges.containers.piwik.pro/ppms.php)”, “6cde5751-4441-4a1c-aae5-da1cd6”]);  
};  
})(window, document, ‘dataLayer’, ‘19c287e6-e375-4b6c-b93b-038’);

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [January 28, 2024, 10:24am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/8 "2024-01-28T10:24:20Z")

</div>

Remove `containers` from the tracker endpoint URL and I think it should be `norgesgruppen` not `norges`.

`https://norgesgruppen.piwik.pro/ppms.php`

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 29, 2024, 7:59am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/9 "2024-01-29T07:59:04Z")

</div>

Well, it was a clumsy attempt to anonymize the post. You can see the correct URL in the clip below that calls the …a1cd66837a7.js file.  
.  
This is a URL copied from a different installation script in the same account. [https://norgesgruppen.containers.piwik.pro](https://norgesgruppen.containers.piwik.pro) is correctly collecting data today.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/6/6df710f20acb038c03003ea33a53eff7558229bd.png)

When I use the standard manual installation script, I have no problems. It’s when I use the addTracker method the problem occurs.

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [January 29, 2024, 8:50am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/10 "2024-01-29T08:50:27Z")

</div>

> [@Anders](#):
>
> You can see the correct URL in the clip below that calls the …a1cd66837a7.js file.

This file should contain the content of your Piwik PRO Tag Manager container (stuff like tags and so on).

The `https://norgesgruppen.piwik.pro/ppms.php` endpoint is responsible for data collection and this is what we want to use in the `addTracker` method.

So something like `_paq.push([“addTracker”, “https://norgesgruppen.piwik.pro/ppms.php”, “6cde5751-4441-4a1c-aae5-da1cd6”]);` should do the trick when it comes to adding a second tracker.

By the way, if you want me to anonymize some stuff from this post - send me a private message.

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 29, 2024, 9:57am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/11 "2024-01-29T09:57:03Z")

</div>

I guess your suggestion is what I am using. ref the thread above.

These are called after the .js file has loaded.

_// Add trackers after the Piwik Pro script is loaded_  
_tags.onload = function() {_  
_window.\_paq = window.\_paq || ;_  
_window.\_paq.push([‘setTrackerUrl’, ‘[https://norges.containers.piwik.pro/ppms.php’](https://norges.containers.piwik.pro/ppms.php%E2%80%99)]);_  
_window.\_paq.push([‘setSiteId’, ‘19c287e6-e375-4b6c-b93b-038’]);_  
_window.\_paq.push([“addTracker”, “[https://norges.containers.piwik.pro/ppms.php”](https://norges.containers.piwik.pro/ppms.php%E2%80%9D), “6cde5751-4441-4a1c-aae5-da1cd6”]);_  
_};_  
_})(window, document, ‘dataLayer’, ‘19c287e6-e375-4b6c-b93b-038’);_

The only difference is that mine are preceded with **windows.** \_paq…

Please see the clip above where two ppms.php calls are made, and they both get 404.

I follow your logic; the .js file will govern both ppms.php requests and use the .js setup. This is fine, but how do you make the requests valid?

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [January 29, 2024, 10:00am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/12 "2024-01-29T10:00:18Z")

</div>

> [@Anders](#):
>
> The only difference is that mine are preceded with **windows.** \_paq…

And they contain `containers` which I pointed out here:

> [@anthonybartczak](#):
>
> Remove `containers` from the tracker endpoint URL

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 29, 2024, 1:46pm UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/13 "2024-01-29T13:46:39Z")

</div>

Sorry, I misread my dev tools info. Thanks for your patience. It’s working now. I get 202 responses. 😃

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 29, 2024, 1:57pm UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/14 "2024-01-29T13:57:49Z")

</div>

So, now I know how to send the same data to two places, which is great learning. However, my need is to have separate sets of tags on the same page, like you can in GTM.

That would mean calling two different containers on the same page. Is that possible?

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [January 29, 2024, 2:27pm UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/15 "2024-01-29T14:27:35Z")

</div>

> [@Anders](#):
>
> However, my need is to have separate sets of tags on the same page, like you can in GTM.
> 
> That would mean calling two different containers on the same page. Is that possible?

No, 2 or more Piwik PRO containers on the same page is not currently possible. Perhaps [a meta setup](https://help.piwik.pro/support/tag-manager/about-meta-setup/) would partially address your needs.

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 29, 2024, 2:31pm UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/16 "2024-01-29T14:31:01Z")

</div>

Thanks for your answer.

My use case is that I need a “roll-up” to do crossdomain tracking for the login sequence. That involves many sites, but there is only need for a couple of tags.

Each site has other needs that should be taken care of for each of them. The only cross domain need is login.

Using GA this would be simple as you can run multiple GTM containers on one site, sending data of your choice to different GA4 properties.

This seems to be very complicated with PP. Or is it something that I am missing?

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 30, 2024, 7:46am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/17 "2024-01-30T07:46:55Z")

</div>

No, this use case is the opposite of what I seek. I.e., separate tags for two different endpoints.

The only way to do this afaik by now, is the Meta Sites&Apps in Analytics, where you can see all included data if you implement the relevant tags on all sites. Still, this does not support cross-domain tracking, which I am looking for. I would have wanted to see the sessionised use of the single-sign-on solution for some 15 different websites, where tags would only be used to collect login data to and from SSO.

It seems to me that the PP strategy of combining Analytics and Tag Manager in one code base at the same time does not support different tracking needs on the same page as GTM and GA do.

I do like PP’s integrated simplicity, but I think this is a drawback.

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [January 30, 2024, 8:28am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/18 "2024-01-30T08:28:12Z")

</div>

> [@Anders](#):
>
> No, this use case is the opposite of what I seek. I.e., separate tags for two different endpoints.

Well, the meta setup allows you to have separate tags on a single site because on the PPTM UI level you kind of have 2 different containers. They are later (when published) joined together in a single tag tree but I’m not sure if that’s a problem.

What I usually do in case there’s a need for both specific views (seperate sites/domain) and a cross-domain tracking view is create a single tracking code containing 2 `addTracker` methods. One for the separate site and one for the cross-domain one.

I have tried both having a single Piwik PRO Tag Manager container for all of the websites and using a meta setup to keep the separate containers and deploy the “double tracker” on each of those websites with ease. The second method allows you to keep all of the tags that need the per site separation and deploy additional tags on top of that. [There’s a short description of this method here](https://community.piwik.pro/t/running-2-piwik-pro-tag-managers-on-the-same-website/3387/5).

I usually stick to running a single tracking code when splitting traffic into 2 different sites but you could try keeping all of the default tracking tags and adding the cross-domain tracker through the meta setup. This is not something I’ve tried but I think it could address the tracking tag separation need.

Using custom code is for sure more complicated than using UI to configure stuff like this but it’s still possible. Maybe I’m missing the point here but the attached image from your opening post looks very similar to what I’m describing above.

> [@Anders](#):
>
> Using GA this would be simple as you can run multiple GTM containers on one site, sending data of your choice to different GA4 properties.

I agree it could be simpler when it comes to the implementation but this approach has some drawbacks ([Simo has a cool article on this topic](https://www.simoahava.com/gtm-tips/multiple-gtm-containers-on-the-page/)).

---

<div class="post-metadata">

**Author:** ![Anders](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anders/32/2506_2.png) [@Anders](https://community.piwik.pro/u/Anders)\
**Post date:** [January 31, 2024, 10:58am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/19 "2024-01-31T10:58:30Z")

</div>

Thanks Anthony.

I think I get it now. If I build my Login tag on the meta-level and specify a standardized dataLayer across sites for login events, can I get login activity from all involved sites while each has a separate set of tags in their respective Sites?

That would solve the absolute number of login events across sites, as I understand it, but without CDT?

You mention this:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/c/cd9958277377837432ffef77dfc7bbdbe58af704.png)

In a way, it sounds like what I am after, but if you look at my intended setup here, the Script with ID 1 is, in effect, the tags in the Meta Sites&Apps. While Scripts ID 2 - 5 would be the actual scripts for each site?

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/d/db50269c58095eed84193802a050110321a90fa0.jpeg)

With two addTracker methods, is there a way to choose which tags should fire? A trigger rule for Site ID?

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [January 31, 2024, 11:43am UTC](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532/20 "2024-01-31T11:43:21Z")

</div>

> [@Anders](#):
>
> That would solve the absolute number of login events across sites, as I understand it, but without CDT?

No, cross-domain tracking still has to be enabled for one of the trackers (looks like `Script w/ ID 1` in your case).

I think we should take a little step back just to make sure that we are on the same page here. We have to split up the Piwik PRO tracking code from the Piwik PRO container code. They are not tied to eachother permamently - you can use the TM without the tracking code and the tracking code without TM (e.g. embedding tracking in the source code, using a different tag manager).

The setup that I was talking about should look like this:

 ![obraz](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/5/51a4702b2c9a895730fefcfec49677a82f12ea35.png)

If we zoom in, and only inspect the tracker (leaving out tag managment stuff):

 ![obraz](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/0/0207a59578a2695390731091bfa199c74b361d7d.png)

What I haven’t tried before, which may be the thing you are looking for, is this kind of setup:

 ![obraz](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/9/92c148eb9de1940692a58f8350eb95c2c3b5de0b.png)

To also address this question:

> [@Anders](#):
>
> With two addTracker methods, is there a way to choose which tags should fire? A trigger rule for Site ID?

By default, if there are 2 trackers on the website and you e.g. use a custom event template in Piwik PRO Tag Manager, both of the trackers will receive the event. You can specify which site you want to send the custom event to using custom HTML tag.

[Next page](https://community.piwik.pro/t/multiple-site-ids-on-the-same-page/3532.md?page=2)
