Last active
April 4, 2023 18:54
-
-
Save dcvogi/e6555a7aa724cecc87e49d329394de29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function pageVisibility(){ | |
function initializeTracking(){ | |
//... | |
} | |
function handleVisibilityChange(event){ | |
if(document.hidden){ | |
return; | |
} | |
event.target.removeEventListener(event.type, handleVisibilityChange); | |
initializeTracking(); | |
} | |
function initWhenVisible(){ | |
if (typeof document.addEventListener === "undefined" || typeof document.hidden === "undefined") { | |
ga('send', 'event', 'browser support features', 'visibility', 'unable to handle visibility API'); | |
initializeTracking(); | |
} else { | |
document.addEventListener(visibilityChange, handleVisibilityChange, false); | |
} | |
}; | |
var hidden, visibilityChange; | |
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support | |
hidden = "hidden"; | |
visibilityChange = "visibilitychange"; | |
} else if (typeof document.msHidden !== "undefined") { | |
hidden = "msHidden"; | |
visibilityChange = "msvisibilitychange"; | |
} else if (typeof document.webkitHidden !== "undefined") { | |
hidden = "webkitHidden"; | |
visibilityChange = "webkitvisibilitychange"; | |
} | |
if(document.hidden){ | |
initWhenVisible(); | |
} else { | |
initializeTracking(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment