Visibility.js is a wrapper for the Page Visibility API. It hides vendor prefixes and adds high-level functions.
Moreover, you can detect if the browser is just prerendering the page while the user has still not opened the link, and don’t count this as a visit in your analytics module, or do not run heavy calculations or other actions which will disable the prerendering.
Page Visibility API is natively supported by all browsers. For old browsers, you can use
lib/visibility.fallback.js with focus/blur hack (note that this hack has an issue: when the browser has just lost focus, but is still visible for the user, its state will change to [hidden]).