It seems this question and similar ones have a tendency to pop up every once in a while. Tracking time spent in a course or activity seems like a sensible means of measuring engagement, but you tend to run into really practical obstacles.
Time/date accessed is logged in Moodle for each user/participant/student for all courses and activities, be it through the Moodle app or from a browser window. You could use this time stamp as a starting point for measuring time spent, if:
- You are certain the user only has this one app / browser window open;
- You are certain his/her eyes and attention are where they should be: in the activity;
- You are certain the time/date logged for storing the activity's result (grade, completion state, ...) is accurate and matches the time/date the user/participant/ student concluded the activity.
You could also try the following:
You could calculate the time between a user first accessed the course and the conclusion of the final activity or assessment and use that number for an indication of average time needed to finish the course.