-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
51 lines (48 loc) · 1.37 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function () {
var visible = true;
function focused() {
if (!visible) {
window.dataLayer.push({
'event' : 'windowStatus',
'eventCategory' : 'Activity',
'eventAction' : 'window-status',
'eventLabel' 'focused'
});
}
}
function unfocused() {
if (visible) {
window.dataLayer.push({
'event' : 'windowStatus',
'eventCategory' : 'Activity',
'eventAction' : 'window-status',
'eventLabel' 'unfocused'
});
}
}
// Standards:
if ('hidden' in document) {
document.addEventListener('visibilitychange',
function() {(document.hidden ? unfocused : focused)()});
}
if ('mozHidden' in document) {
document.addEventListener('mozvisibilitychange',
function() {(document.mozHidden ? unfocused : focused)()});
}
if ('webkitHidden' in document) {
document.addEventListener('webkitvisibilitychange',
function() {(document.webkitHidden ? unfocused : focused)()});
}
if ('msHidden' in document) {
document.addEventListener('msvisibilitychange',
function() {(document.msHidden ? unfocused : focused)()});
}
// IE 9 and lower:
if ('onfocusin' in document) {
document.onfocusin = focused;
document.onfocusout = unfocused;
}
// All others:
window.onpageshow = window.onfocus = focused;
window.onpagehide = window.onblur = unfocused;
}