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

setCustomRequestProcessing blocks enableHeartBeatTimer #15243

Open
crnm21 opened this issue Dec 6, 2019 · 5 comments
Open

setCustomRequestProcessing blocks enableHeartBeatTimer #15243

crnm21 opened this issue Dec 6, 2019 · 5 comments
Labels
Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users.

Comments

@crnm21
Copy link

crnm21 commented Dec 6, 2019

If you use a setCustomRequestProcessing, an enableHeartBeatTimer does not fire in the JS tracker.

How to reproduce:

Add a

_paq.push(['setCustomRequestProcessing', function(params){
        .... send the request individually ....
      }]);

and
_paq.push(['enableHeartBeatTimer', 20]);

Result: HeartBeatTimer is not executed.

Desired result: HeartBeatTimer gets executed through the CustomRequestProcessing.

@tsteur
Copy link
Member

tsteur commented Dec 6, 2019

Looking at the code I'm not seeing why this shouldn't work. Is it actually sending the heartBeatTimer request? You might need to leave the page and focus again a few times etc or navigate to another page for the request to fire.

@crnm21
Copy link
Author

crnm21 commented Dec 7, 2019

It's not sending the heartBeatTimer if a setCustomRequestProcessing is set, that is the problem. Without the setCustomRequestProcessing, the heartBeatTimer is send.

In my example case, the setCustomRequestProcessing is the following function:

function sendAjax(data){ httpRequest = new XMLHttpRequest(); httpRequest.open('GET', '[MATOMOHOST+PATHtoPiwik.php]?ac='+data); httpRequest.send();

This function gets a btoa(params) as data. It does work for the pageload, but then not for the heartBeatTimer. Without the setCustomRequestProcessing, the heartBeatTimer works.

@tsteur
Copy link
Member

tsteur commented Dec 8, 2019

Sorry I can't reproduce this. Make sure you are on the latest version of Matomo in case you are not. This works here without any issue for me and looking that the code I can't even think how this wouldn't work. To make sure the heart beat timer is sent, stay on the page for say 1 minute before you navigate to some other window like the developer tools.

@mattab
Copy link
Member

mattab commented Jan 21, 2020

Could you send us a short JavaScript code that will reproduce this issue? @crnm21

@mattab mattab added the Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. label Jan 21, 2020
@crnm21
Copy link
Author

crnm21 commented Jan 21, 2020

Sorry for getting back to this so late.
I'm using this code on Matomo 3.11.0:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq || [];
function sendAjax(data){
httpRequest = new XMLHttpRequest();
httpRequest.open('GET', '{$MATOMO_URL}?d='+data+'&ts='+new Date().getTime());
httpRequest.send();
}
  _paq.push(['setCustomRequestProcessing', function(params){
        sendAjax(btoa(params));
    }]);
  _paq.push(['disableCookies']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  _paq.push(['enableHeartBeatTimer', 10]);
  (function() {
    var u="//{$MATOMO_URL}/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    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);
  })();
</script>
<!-- End Matomo Code -->

Matomo does fire once, but the HeartBeatTimer does not fire. (On Matomos side, the d query param is decoded and Motomo registers the pageload). I stayed on the site (focused), scrolling up and down for a minute or more but the HeartBeatTimer does not fire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users.
Projects
None yet
Development

No branches or pull requests

4 participants