@mattab opened this Issue on August 17th 2019 Member

Could we change Piwik.addTracker() to allow not setting an idSite there, and only have the first parameter URL instead?

This is needed to fix a big regression in Tag Manager.

Why needed now?

This started being an issue a few weeks since we changed: https://github.com/matomo-org/tag-manager/commit/f0e368d4e58ba9af86551fad4b7b578a5bb9761c as we are no longer setting the idsite.

Reproduce

Steps sent by a customer (haven't reproduced it myself, but can see the error live on their site):

  • Use tag manager and Matomo separately for example:
    
    <!-- Matomo -->
    <script type="text/javascript">
        var _paq = window._paq || [];
        /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
        _paq.push(['trackPageView']);
        _paq.push(['enableLinkTracking']);
        (function() {
            var u="https://URL_HERE/";
            _paq.push(['setTrackerUrl', u+'matomo.php']);
            _paq.push(['setSiteId', '1']);
            var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
            g.type='text/javascript'; g.async=true; g.defer=true; g.src='URL_HERE/matomo.js'; s.parentNode.insertBefore(g,s);
        })();
    <!-- End Matomo Code -->


window._mtm = window._mtm || [];
window._mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src='https://URL_HERE/js/container_uAZDfecL.js'; s.parentNode.insertBefore(g,s);

* Create a container
* Create custom html Tag with the following code:
    try {
        window._mtm = window._mtm || [];
        window._mtm.push(data);
        console.log('mtm', data);
    }
    catch (e) {
        console.log('matomo error', e);
    }

(`data` could be eg. `{ category: "clic-réseaux-sociaux", event: "clic-réseaux-sociaux", label: "nom-réseaux-facebook" } `

## JS Error when using tag manager:

matomo error Error: A siteId must be given to add a new tracker
at Q.addTracker (matomo.js:63)
at Object.addTracker (matomo.js:74)
at container_uAZDfecL.js:357
at Object.push (container_uAZDfecL.js:43)
at Object.fire (container_uAZDfecL.js:356)
at g._doFire (container_uAZDfecL.js:36)
at g.fire (container_uAZDfecL.js:36)
at container_uAZDfecL.js:33
at Array. (container_uAZDfecL.js:384)
at t.push (container_uAZDfecL.js:21)

This Issue was closed on August 26th 2019
Powered by GitHub Issue Mirror