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.


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) {

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.

Content types

The following H5P content types are currently supporting xAPI: