jehna / ga-lite

Small, cacheable and open version of Google Analytics JS client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add onunload event tracking

jehna opened this issue · comments

The v1 implemented the onunload event by default to correct the time spent on page (especially on bounces).

The original code:

var pageLoadedTimestamp = new Date().getTime();

/**
 * Note:
 * unload event does not fire on:
 * - Android chrome on tab closing
 */
window.addEventListener(
    'unload',
    eventBuilder(
        'timing',
        {
            'utc': 'JS Dependencies',
            'utv': 'unload',
            'utt': (new Date().getTime() - pageLoadedTimestamp)
        }
    )
);

Probably will just mention this in the README.md's migration section. While this was a great feature in v1, it probably should not be part of version 2.