kalnyc67 / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 0 forks source link

Events sent on windows.(before)unload callback are not sent on some browsers. #484

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Name of affected component: Web Tracking (analytics.js)

Issue summary:
Provide a brief summary of the issue you're experiencing.

URL of the page exhibiting the issue:
www.pwl.philips.com 
It should send an application closed event on closing the tab.
However, on for example, firefox, it does not.

Steps to reproduce issue:
1. open the site
2. close the tab
-> no application close event send through analytics.js  

Expected output:
What do you expect to see after performing the above steps?

I expect to see the event appear in GA

Actual results:
What do you actually see after performing the above steps?

It does not.

Notes:
Provide any additional information which might be useful here. Feel free to
attach screenshots or sample code which demonstrates the issue being
described.

It looks like the measurement request is triggered through an img load.
However, windows.(before)unload does not seem to allow that on some browsers 
such as ff.

Original issue reported on code.google.com by rianwouters on 1 Sep 2014 at 1:08

GoogleCodeExporter commented 9 years ago
This behavior is just how browsers work. It's not really something that 
analytics.js can address. When you close a tab (or click a link to another 
page, etc.) most browsers will stop executing JavaScript.

Some newer browsers implement the function `sendBeacon` to deal with this exact 
issue. Here's an MDN article on the subject:
https://developer.mozilla.org/en-US/docs/Web/API/navigator.sendBeacon

If you want to use `sendBeacon` with analytics.js you can set the `useBeacon` 
parameter to true:
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-r
eference#useBeacon

Original comment by philipwa...@google.com on 3 Sep 2014 at 12:41