Track time viewing a document

Good evening folks,

I am currently in the process of building a fairly basic learning management system. Users will be able to view a theory document. The idea is that for the user to progress to the next stage they must have viewed the document for x amount of minutes before being able to request a practical session. This, of course, doesn’t seem to be as simple as I would like.

My first though was to run a timer in the page, when the page is closed - stop the timer and then calculate the minutes and upload this to the database, though this doesn’t seem to be an easy option. Given that I can’t run actions on the page when it’s already closed.

I feel that my best chance is to have a “recently accessed” date/time field on the document issue type and then when the page is closed calculate the time between the recently accessed and current time to figure out the minutes viewed, I figure that somehow I could do this by running it as an API workflow and somehow adding actions to every redirection to run this API workflow before moving the user along, though this again seems like a lengthy option and doesn’t account for the user just closing the tab.

Of course neither of these options actually calculate how long the user is on the page, if they tab out to go and watch YouTube my system would have no idea.

Any options, please?

I’d put something on the user called “CurrentlyViewing”
This “type” is your type of thing.

You can use this to keep the user’s state, and know what their current item is, and you can also check the user’s “CurrentlyViewing” modified date. (Which the user can see too for privacy rules)

Check that the modified date is greater than what you want.
Change the “currentlyViewing” when the new item is viewed.

Should work!

As for the below, it’s very hard to track users activity like that. I don’t know how.