Event Tracking in TagManager failed for published website when using lookup table

Hi everyone,

I’m experiencing some interesting behaviour when using Matomo’s tag manager for event tracking. For easy development of all variables, tags and triggers, I am using a three stage development system each of which having its own domain or subdomain (live, development and staging).

The primary website (live environment) is using siteID 1, development siteID 5 and staging siteID 6. The numbers in detail are not important. Matomo tag manager uses the same container for all three stages and with this, the event tracking works perfectly fine when having preview mode enabled but also when deploying to the development or staging environment. For the live version, this only happens when reviewing event tracking from tag manager in preview mode. Once the settings have been published, no more events are tracked on the live page anymore.

Reviewing the code implementation, everything is looking fine - the lookup table inserts the correct siteID numbers into the code and the basic tracking works. Also event tracking coming directly from html.

It took me a while to find out, why click events of all tag manger tags and triggers are not recorded. If a visitor interacts with an element which is being connected to a trigger and tag of the tag manager, this invokes a call to the matomo.php file sending all data for tracking as POST process. Reviewing this for both development and staging environments, the variable idsite there holds the corresponding number of that environment. For the live environment however, the domain name (e.g. www.mydomain.com) is being used and not the number of the live environment itself. With this, the call has been rejected from being sent to matomo instance from the primary website. CORS elements are also in place and identical for all three domains.

Beginning of the header (simplified) of this working tracking call looked like this:
https://matomo.mydomain.com/matomo.php?e_c=Test&e_a=Clicked&e_n=Pagetitle&e_v=&ca=1&idsite=1&rec=1&r=

versus (not working):
https://matomo.mydomain.com/matomo.php?e_c=Test&e_a=Clicked&e_n=Pagetitle&e_v=&ca=1&idsite=www.mydomain.com&rec=1&r=

Only solution so far I could make things work is to completely remove the custom lookup table variable from the main container and add the initial siteID number back (which then of course breaks the smooth development and deployment process).

Configuration of the custom variable for the lookup table looks like this:

For the container, Matomo site id was set to variable {{SiteID}}

Not sure what is causing this behavior and why the domain name is being added as sideid variable for the live environment instead of the default id value.

I hope this information helps to check if this may be a bug somewhere when building the url for the event tracking call.