Author: | Jaap Murre |
---|---|
Version: | 1.0b |
Date: | May, 2011 |
This is a JavaScript library for tracking activity. It extracts ‘periods of activity’ from large numbers of events. For example, suppose you want to know how much time users spend reading materials on a certain web page. With the activity tracker you can get an idea of the total time based on the evidence such as mouse moves, key presses, etc. When the user does not interact with the page at all, the activity tracker assumes that the period of activity is over and (only then) sends a ‘activity’ event to the server. As soon as the user starts interacting, another period starts. The ‘micro events’ that form the evidence of inferred activities such attending or reading are not stored permanently, only the global ‘activity’ event with the length in milliseconds.
You setup an activity tracker like this:
dojo.registerModulePath("nm","../../nm"); // path to 'nm' is relative to dojo.js file
dojo.require("nm.logger.activity_tracker");
nm.logger.activity_tracker.register("reading",{
url:"process_data.php",
password:"pietje",
maxInactivity: 10000, // in ms
});
Legal arguments of the details argument of logger.register() can be used here too. In addition you can still access nm.logger as usual, .e.g., to set the namespace.
Now, you send events that are evidence of activity, e.g., that the user is still attending to the page or section, presumably reading or studying the materials. Evicience of activity could be mouse movements or clicks, hover on elements, key presses, etc.. You must send this ‘evidence’ to the activity tracker yourself, like this:
dojo.publish('reading',[{name:'Lesson 1'}]);
The activity tracker than logs these and keeps track of idle time. If nothing happens for a while (set with maxInactivity), a ‘activity period’ is logged and eventually sent to the server.
The activity tracker does not save the possibly very large volume of events to the server but keeps these in memory and local storage. Only when a lapse in activity is detected (set by maxInactivity), is an event sent to the server using the original name of the event plus a suffix ("-activity" by default).
The activity tracker, thus, registers two event types with nm.logger: (1) the one mentioned in the registration (i.e., named “reading” above), which has saveToServer set to false; (2) one with the suffixed type (i.e., “reading-activity” above), which is sent to the server with an estimate of the period of activity in the data attribute in milliseconds, and name as the attribute sent with the dojo.publish (i.e., “Lesson 1” above, or “default” if no event name was provided).
The following methods are available (for event_type it is best to always use a string):
Send data to server, via local storage. See nm.logger.register() for legal values of details. In addition, one may specify the idle time in ms that is used to mark the end of a period of activity, maxInactivity, which is 5000 by default (5 seconds). This, if no events are received for 5000 ms, the period of activity is sent to the server and a new one is started. The maxInactivity time itself is not added to the total activity period.
Arguments: |
|
---|
The details parameter includes those of logger.register() and adds:
(integer) If nothing happens for maxInactivity ms, an ‘activity period’ is logged and eventually sent to the server.
Set the suffix attached to the global activity event. The suffix is called "_activity" by default.
Arguments: |
|
---|
Returns: | the current suffix |
---|
Check whether there are any old events that form periods of activity. This function can be called when the page was for example clicked away and reloaded. Old events are not lost, but kept in local storage. This function is called in register() and can also be called elsewhere.
Arguments: |
|
---|
Note
This function does not duplicate logger.register() which is called as well in activity_tracker.register(). The function in the activity tracker only tracks those events that are not directly sent to the server.