@viezel opened this Issue on October 10th 2018

Matomo: 3.6.0
Browser: Chrome 69.0.3497.100

<script type="text/javascript">
    function onExit() {
        window.removeEventListener("beforeunload", onExit);
        window._paq.push(['trackEvent', "MyExitCategory", "MyExitAction", "web", 1]);
    }
    window.addEventListener('beforeunload', onExit)
</script>

Results in:
grafik
(works in Firefox and Safari - but not in Chrome)
The MyExitCategory tracking event should only appear once.

Is this a known bug?

@sgiehl commented on October 10th 2018 Member

Are you sure the event is triggered twice and the user for example didn't have the site open in two tabs and closed both?

@viezel commented on October 10th 2018

yes.

@viezel commented on October 10th 2018

this is a small hotfix - creating a state varialble - but not really ideal.

<script type="text/javascript">
    var beforeunloadFired = false;
    function onExit() {
        if (beforeunloadFired === false) {
            window._paq.push(['trackEvent', "MyExitCategory", "MyExitAction", "web", 1]);
        }
        window.removeEventListener("beforeunload", onExit);
        beforeunloadFired = true;
    }
    window.addEventListener('beforeunload', onExit)
</script>
@fdellwing commented on October 10th 2018 Contributor

Are you sure the event is not fired twice?

@viezel commented on October 10th 2018

I think chrome might be firing it twice, but only one request is shown in the Network tab of Chrome Dev Tools.

@viezel commented on October 10th 2018

try it yourselves:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Track debug</title>
</head>
<body>
<script type="text/javascript">
    var _paq = _paq || [];
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u = 'https://demo.matomo.org';
        u = u[u.length-1] === '/' ? u : u+'/';
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', 44]);
        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>
<script type="text/javascript">
    function onExit() {
        window._paq.push(['trackEvent', "MyExitCategory", "MyExitAction", "web", 1]);
        window.removeEventListener("beforeunload", onExit);
    }
    window.addEventListener('beforeunload', onExit)
</script>
</body>
</html>
@tsteur commented on October 10th 2018 Member

It might be sendBeacon. The request that you see in the network tab, is that request failing?

@viezel commented on October 10th 2018

nope it works fine.

Request URL: https://demo.matomo.org/piwik.php?e_c=MyExitCategory&e_a=MyExitAction&e_n=web&e_v=1&idsite=44&rec=1&r=141047&h=21&m=47&s=56&url=http%3A%2F%2Flocalhost%3A8000%2Ftrack-debug.html&_id=8c3935eb9df1b675&_idts=1539200863&_idvc=1&_idn=0&_refts=0&_viewts=1539200863&send_image=1&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1680x1050&gt_ms=8&pv_id=4wahMw
Request Method: GET
Status Code: 200 OK

http://prntscr.com/l4l1yi
https://demo.matomo.org/index.php?module=CoreHome&action=index&idSite=44&period=day&date=yesterday&updated=2#?idSite=44&period=day&date=2018-10-10&category=General_Visitors&subcategory=Live_VisitorLog

@fdellwing commented on October 11th 2018 Contributor

I'm unable to reproduce the behaviour you noticed with:

Chrome 69.0.3497.100 64 Bit on Ubuntu 14.04

@viezel commented on October 11th 2018

interesting.. I have it on two different MacOS now.

@fdellwing commented on October 11th 2018 Contributor

I just tried it with Chrome 70.0.3538.45 (Beta) 64 Bit on Ubuntu 14.04 and everything works as excepted.

matomo4

Powered by GitHub Issue Mirror