Questions about sessions and user activity tracking

I'm trying to figure a way to properly track user activity on a platform, and ideally the goal is to be able to construct a timetable of when and what people usually do online at a given day of the week.

Data is collected in an SQL database, and I'm currently figuring out

1) The data columns required to build such a time table, and

2) Programming implementation to collect said data

Seems easy enough, for 1) I probably will need to know a user's

  • datetime of status change to "online" "offline" "away"
  • datetime of activity change to "using/stop using application X"

and that should be able to construct the timetables for a user/all users in the system.

I am however very lost in the implementation.

  • Do I generate a log of each user?
  • Or do I generate SessionIDs and track each session for when a user goes online?
  • How then do I consolidate the data collected from all the sessions this way?
  • Are there any good references for sessions/log managements?