Multiple Containers / Tag Managers on Single Site

Setup

  • My team is building a web component, which is integrated on many host sites
  • Each of these host sites is managed by a different team and has its own Matomo Tag Manager with its own id e.g. <script src="https://.../container_ugas78d7sg.js">
  • We want to only visualise our own events in our Dashboard. We don’t care about the analytics of the host sites and the host sites do not care about ours.
  • My idea was to load a second tag manager script e.g. <script src="https://.../container_asd3s99ssd.js"> and send events using this 2nd container. However both scripts want to load the tag manager in window._mtm .
  • Multiple containers on the same site should to be possible, but there is no example in the documentation

Questions:

  • How to load a second container and sent events to it without overwriting _mtm ?
  • Is there a better alternative without loading a second container?

Hi,

Just update the end of the matomo script:

<!-- Matomo Tag Manager -->
<script type="text/javascript">
var _mtm = window._mtm = window._mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
_mtm.push({'userId': userId}); // example of user ID

var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src='https://lmatoni1.cm-cic.fr/js/container_xxxxxxxx.js'; s.parentNode.insertBefore(g,s); // Container 1
g=d.createElement('script')
g.type='text/javascript'; g.async=true; g.src='https://lmatoni1.cm-cic.fr/js/container_yyyyyyyy.js'; s.parentNode.insertBefore(g,s); // Container 2
</script>
<!-- End Matomo Tag Manager -->

Maybe @diosmosis can add this tip in the documentation https://developer.matomo.org/guides/tagmanager/embedding ?