Skip to content

JavaScript tracker: change Piwik.addTracker() to allow not setting an idSite #14781

@mattab

Description

@mattab

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: matomo-org/tag-manager@f0e368d 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 -->

​    <!-- Matomo Tag Manager -->
        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);
    </script>
    <!-- End Matomo Tag Manager -->

  • 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.<anonymous> (container_uAZDfecL.js:384)
at t.push (container_uAZDfecL.js:21)

Metadata

Metadata

Assignees

Labels

BugFor errors / faults / flaws / inconsistencies etc.RegressionIndicates a feature used to work in a certain way but it no longer does even though it should.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions