Has anyone been able to figure out a way to track the length of time a person spends on a “scene” via Google Analytics or some other analytics system?
I just thought of something… one approach could be setting timers in each scene that fire off events at select intervals: 1 minute, 2 minutes, 3 minutes, etc. Each scene is set to timeout after a couple minutes anyways and restart at the opening scene so it wouldn’t be too hard to implement (even though I do have around 70 scenes to add it to).
e.g. on load
window.startTime = Math.floor((new Date()).getTime()/ 1000);
on triggering a button
window.finishTIme = Math.floor((new Date()).getTime()/ 1000);
var difference = window.finishTIme - window.startTime;
(this will return the difference in whole seconds)
That’ll get you the difference, i wouldn’t advice using set intervals, if you wanna use the constant ticker approach you should use requestAnimationFrame as that will pause when the user switches tabs so it will be more accurate. Also performance is way better than setInterval or timeout
Although having the hype doc be on stage doesnt mean people are interacting with it so you could check for a focus with document.activeElement before triggering the action… but that’s a bit more complicated and I’m not sure the best approach for that.
Anyway hope that helps