Event Logging

JSAV supports AVs to log student actions into an event log. It also provides mechanisms for sites using the AVs to access a log of those events.

Logging events with .logEvent(eventData)

AVs can log events on student actions using this function. The eventData can be any data describing the event. If it is an object, properties tstamp and av will be automatically added to it to mark the current time and the ID of the AV.

For example:

jsav.logEvent({type: "jsav-heap-decrement",
               newSize: bh.heapsize()});

Listening to events

JSAV will trigger all events logged with the .logEvent() function as jsav-log-event on the body element of the current document. To attach a listener for those events, one can use the following code.

$("body").on("jsav-log-event", function(event, eventData) {
  // here you would do something sensible with the eventData
  console.log(eventData);
});

JSAV will automatically trigger many events for actions such as student moving forward, backward, etc in the animation.

Custom event handler

Sometimes listening to the events on the body element might not be preferred. To customize the way the events are handler, a function to handle all JSAV events can be passed as an option to JSAV when initializing it. Name of the option is logEvent. The event handler function will be passed the eventData as the first argument. For example:

var jsav = new JSAV("avcontainerid", { logEvent: function(eventData) {
  // here you would do something sensible with the eventData
  console.log(eventData);
}});