Tracking length of time spent on Hype scene

(Casey) #1

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?

(Casey) #2

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).

Another theoretical approach makes me think of some kind of javascript action being applied at scene unload. Perhaps starts on scene load. When the scene unloads do to a user navigating to another scene, the counter number gets rounded up to the nearest minute and added to some kind of variable string and passed as a Google event. I’m just not savy with Javascript to know how to do this approach.

(Lucky) #3

you could just use javascript’s getTime() to get the time on load and then on exiting the stage you can do the same get time and get the difference

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