@crnm21 opened this Issue on December 6th 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 commented on December 6th 2019 Member

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 commented on December 7th 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 commented on December 8th 2019 Member

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 commented on January 21st 2020 Member

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

@crnm21 commented on January 21st 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.

Powered by GitHub Issue Mirror