The code below sends the 30s
event do Google Analytics after 30 seconds a user enters a page.
setTimeout(function(){
gtag('event', '30s');
}, 30000);
But when the user minimizes the window, the event still fires.
What I really want is a way to "pause" the setTimeout
when the user minimizes the page and, when he maximizes the page, the setTimeout
continues counting from the moment it has stopped.
I tried to put setTimeout
inside the hasFocus
statement but it didn't work as expected.
Any way to do that?