Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double-execution of trackLink callback #10152

Closed
er314 opened this issue May 15, 2016 · 1 comment
Closed

double-execution of trackLink callback #10152

er314 opened this issue May 15, 2016 · 1 comment
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Milestone

Comments

@er314
Copy link
Contributor

er314 commented May 15, 2016

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);
 })();

@tsteur tsteur added the Bug For errors / faults / flaws / inconsistencies etc. label May 16, 2016
@tsteur
Copy link
Member

tsteur commented May 16, 2016

Thanks for that. We callback should be called only once and looking at the code there could be a big indeed. Thank you for reporting 👍

@tsteur tsteur closed this as completed May 22, 2016
@tsteur tsteur added this to the 2.16.2 milestone May 22, 2016
@tsteur tsteur self-assigned this May 22, 2016
@mattab mattab added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

No branches or pull requests

3 participants