H5P Guides

H5P and xAPI

xAPI (Tin Can) enable H5P to communicate with the publishing platform about what the user does and achieves.

You can't embed H5P from an external site and use JavaScript on your own site to track what the learner does within the H5P content. The example code here only works if the content and the code is hosted on the same site.

H5P's approach is to generate xAPI statements and make them available through events in JavaScript.

To listen for xAPIevents a developer adds:

H5P.externalDispatcher.on('xAPI', eventHandler);

Where the xAPI statement is to be found in event.data.statement. The event will be an XAPIEvent with many functions that makes working with it easier - see the API reference.

Example

To try this out type the following in your browser's console when using an H5P object on a website:

H5P.externalDispatcher.on('xAPI', function (event) {
  console.log(event.data.statement);
});

You should now see xAPI statements in your console.

If you, for instance, need to do something if the user gets full score you may do something like this:

H5P.externalDispatcher.on('xAPI', function(event){
  if (event.getScore() === event.getMaxScore() && event.getMaxScore() > 0){
    console.log('do something useful here');
  }
});

LRS integrations

Since H5P is a plugin for publishing tools H5P does not include its own LRS integration. Instead, H5P generates the statements and makes them available for the publishing platform so that the publishing platform may use its own LRS integration to send H5P's statements to an LRS.

Coverage

The vast majority of H5P content types send answered or completed statements with score and the user's answers when the user completes a task. They do the same for sub tasks and also send statements in the beginning (attempted). 

We unfortunately don´t maintain a detailed overview of the xAPI statements we send anymore. Many content types send more statements than described above. Statements when changing pages ("progressed") is common in many content types for instance.