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

Bug: Events send on Beforeunload is sent twice in Chrome #13577

Closed
viezel opened this issue Oct 10, 2018 · 13 comments
Closed

Bug: Events send on Beforeunload is sent twice in Chrome #13577

viezel opened this issue Oct 10, 2018 · 13 comments
Labels
answered For when a question was asked and we referred to forum or answered it. Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users.
Milestone

Comments

@viezel
Copy link

viezel commented Oct 10, 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
Copy link
Member

sgiehl commented Oct 10, 2018

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
Copy link
Author

viezel commented Oct 10, 2018

yes.

@viezel
Copy link
Author

viezel commented Oct 10, 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
Copy link
Contributor

Are you sure the event is not fired twice?

@viezel
Copy link
Author

viezel commented Oct 10, 2018

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

@viezel
Copy link
Author

viezel commented Oct 10, 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
Copy link
Member

tsteur commented Oct 10, 2018

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

@viezel
Copy link
Author

viezel commented Oct 10, 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
Copy link
Contributor

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

Chrome 69.0.3497.100 64 Bit on Ubuntu 14.04

@viezel
Copy link
Author

viezel commented Oct 11, 2018

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

@fdellwing
Copy link
Contributor

fdellwing commented Oct 11, 2018

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

matomo4

@mattab
Copy link
Member

mattab commented Jun 18, 2019

Hi @viezel Are you still able to reproduce this issue? if so can you please list again the steps to reproduce and browser you can reproduce this in? We'd really like to fix this issue if it's confirmed. Thanks!

@mattab mattab added this to the 3.12.0 milestone Jun 18, 2019
@mattab mattab added the Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. label Jun 18, 2019
@viezel
Copy link
Author

viezel commented Jun 18, 2019

@mattab Just tested it again, and it seems fixed in newest version 👍

@viezel viezel closed this as completed Jun 18, 2019
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Jun 29, 2019
@mattab mattab modified the milestones: 3.13.0, 3.11.0 Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. 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

5 participants