I am trying to track an event when a user leaves the page using Google Analytics (analytics.js). Although it is not known how the user will leave, this may be due to an external link or just closing a tab. So I thought I needed to catch the beforeunload or unload event, and then:
window.addEventListener("beforeunload", function() { ga('send', 'event', 'some', 'other', 'data'); });
Now my question is: will the request to the GA server be synchronous or can I somehow force this behavior to use the hitCallback property? If this is not possible, how else can I achieve this? Preferably without having to set a timeout or a fixed timeout for the user!
javascript javascript-events synchronous google-analytics
Joseph Adams
source share