"Imagine you install analytics on a traditional content site. A few months later you update that site to be a single page application (SPA) without changing your analytics code. Then, a few months after that, you update your site to be a progressive web app (PWA) "<p>Who on earth would ever do this? The worst boss of all time?
You'll also want to track the pageshow and pagehide events (because of PageCache), and note that prerender is now obsolete. Browsers no longer support it and the spec is dead.<p>boomerang has been using PageVisibility for as long as the API has existed, and also handles the prerender case for when browsers did support it. The source is open if you'd like to see how we do it: <a href="https://github.com/soasta/boomerang" rel="nofollow">https://github.com/soasta/boomerang</a>