Credit to Daniel Buckmaster off of Stack Overflow questionIs there a way to detect if a browser window is not currently active? .
I created this script for use in Google Tag Manager for tracking user's focus on the window, and as a way to ultimately remove those who are tabbed or unfocused from metrics.