Skip to content

double-execution of trackLink callback #10152

@er314

Description

@er314

in function sendXmlHttpRequest, call to xhr.onreadystatechange,
callback is executed twice, and actually not when it should.
this is due to this.readyState taking status 2 (the send method has been called), then status 4 (data received complete)
the code is :

            if (this.readyState === 4 && !(this.status >= 200 && this.status < 300) && fallbackToGet) {
                [...]
            } else {
                if (typeof callback === 'function') { callback(); }
            }

should be, I think :

            } else if (this.readyState === 4) {
                if (typeof callback === 'function') { callback(); }
            }

my js tracking code :

  var tracking_callback = function() { console.log('hello callback'); };
  var _paq = _paq || [];
 _paq.push(['setRequestMethod', 'POST']);
 _paq.push(['trackLink', 'http://127.0.0.1:81/tools/contact/', 'link', null, tracking_callback]);
 (function() {
    var u='//127.0.0.1:81/analytics/';
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 1]);
    _paq.push(['setLinkTrackingTimer', 300]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
 })();

Metadata

Metadata

Assignees

Labels

BugFor errors / faults / flaws / inconsistencies etc.not-in-changelogFor issues or pull requests that should not be included in our release changelog on matomo.org.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions