Open crnm21 opened 4 years ago
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.
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.
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.
Could you send us a short JavaScript code that will reproduce this issue? @crnm21
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.
If you use a setCustomRequestProcessing, an enableHeartBeatTimer does not fire in the JS tracker.
How to reproduce:
Add a
and
_paq.push(['enableHeartBeatTimer', 20]);
Result: HeartBeatTimer is not executed.
Desired result: HeartBeatTimer gets executed through the CustomRequestProcessing.