xAPI development
xAPI is H5P's standard for communitcation about what the users does between libraries and externally. To user the xAPI features within your library you need to add H5P's event system to your library. After that you may have your library trigger xAPI events like this:
[CODE HERE]
Or use the short hand version like this:
[CODE HERE]
If your library has child libraries you might want to listen for xAPI events triggered by your children. For instance if you want to act when the user does an attempt you do it like this:
[CODE HERE]
All features of the xAPI Event are documented in the xAPIEvent reference.
Comments
shazzama
Wed, 07/25/2018 - 23:13
Permalink
Code placeholder not filled in
Hi, I am trying to develop different xAPI statements to be used for a new H5P content type I've been working on. There aren't a lot of documentation on how to do so. I believe this is the closest thing, but it only contains placeholders for the code. Do you think you could finish this thread, so I may get some assistance on how to generate and send my own xAPI statements from my new library?
thomasmars
Thu, 07/26/2018 - 11:04
Permalink
Hi, you're correct, the
Hi, you're correct, the documentation on how to trigger xAPI statements from new content types is very limited. I would start by looking at the code of other libraries that trigger xAPI events. They typically do the following:
There's a list of content types that implement xAPI event triggering at https://h5p.org/documentation/x-api, I would suggest starting with the xAPI generation for the true-false content type, as it is one of the simpler ones.
We'd love to hear your experience with it afterwards, we'd also be thrilled if you'd make some documentation for it from your experience. Good luck, hope you succeed with the implementation.
Best regards, Thomas
shazzama
Fri, 08/03/2018 - 00:41
Permalink
Thanks for replying Thomas. I
Thanks for replying Thomas. I'm quite new at xAPI things so please bear with me. I have a follow up question. Am I getting somewhere with the following code below?
var xAPIEvent = new H5P.XAPIEvent();
xAPIEvent.setActor();
xAPIEvent.setVerb('pressed play');
xAPIEvent.setObject('h5p instance');
var verb = xAPIEvent.getVerb(true);
var eventTemplate = H5P.createXAPIEventTemplate(verb)
eventTemplate.trigger(xAPIEvent);
I have a couple of questions:
1) What is the difference between createXAPIEventTemplate() and using new H5P.XAPIEvent?
2) The function setActor(). Where do you obtain the email and name from?
3) Do we pass the entire H5P library as an object when we use setObject()? Do we handle this object in the xAPI H5P plugin?
4) How do we use the trigger() function?
thomasmars
Mon, 08/06/2018 - 16:11
Permalink
Hi,1) createXAPIEventTemplate
Hi,
1) createXAPIEventTemplate is a convenience function that creates a new H5P.XAPIEvent object, then sets the actor, verb, object and context from the content that is inheriting from EventDispatcher. Unlike H5P.XAPIEvent where you would have to build the XAPIEvent yourself and append the data, like you did in the start of your example. I would recommend that your content type always "inherits" from H5P.EventDispatcher and calls createXAPIEventTemplate when you're building your xAPI events.
2) setActor() grabs the user data from the H5PIntegration.user object, and includes name and email properties. These must be set by the platform integration when exposing the H5PIntegration object to the script/window.
3) Yes the H5P instance is passed to setObject() since the H5P instance has essential information for building the xAPI event, like instance.contentId, instance.subContentId and instance.getTitle(). This is handled in the setObject() function in h5p-x-api-event.js and is typically used to link the xAPI event to the address where the content/object can be found.
4) A content type that "inherits" from H5P.EventDispatcher will have the this.trigger() function. This function is used for triggering events of any type, that others can listen for. To trigger an 'interacted' xAPI event you can typically just call this.triggerXAPI('interacted'); from your content type. triggerXAPI will call trigger(this.createXAPIEventTemplate(verb, extra)), which will build the XAPI event for you with the helper functions in h5p-x-api.js. For more sophisticated events, such as when a score has been achieved you can use the helper function triggerXAPIScored(score, maxScore, score === maxScore) to fire off a 'completed' event that will be built for you.
Hope that makes sense and sheds some light on how the xAPI events are built using our helper functions. Let me know if something was unclear.
Best regards, Thomas