javascriptanalyticsmatomo

Matomo - Multiple Containers / Tag Managers on Single Site


Setup

Questions:


Solution

  • Can you maybe do e.g.:

    <!-- Matomo Tag Manager -->
    <script type="text/javascript">
        var _mtm1 = window._mtm1 = window._mtm1 || [];
        _mtm1.push({'mtm1.startTime': (new Date().getTime()), 'event': 'mtm1.Start'});
    
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.src='https://{$MATOMO_URL}/js/container_{$CONTAINER}.js'; s.parentNode.insertBefore(g,s);
    
        var d1=document, g1=d1.createElement('script'), s1=d1.getElementsByTagName('script')[1];
        g1.type='text/javascript'; g.async=true; g1.src='https://{$MATOMO_URL}/js/container_{$CONTAINER}.js'; s1.parentNode.insertBefore(g1,s1);
    </script>
    <!-- End Matomo Tag Manager -->
    

    I think you only need one _mtm in the whole window, since it only contains the startTime anyways. The only thing you need to do is to load the second container to the page, and they both will use the same "startTime" variable - I see no reason why those two containers should use different "startTime" variable.

    What I'm not really sure is whether you should get the first or second element of the array during the getElementsByTagName.

    Hope it works!