xAPI Completion event
Submitted by arosboro on Tue, 06/21/2016 - 23:41
Forums:
Hi,
I'm trying to assess completion on all h5p question types supported by tin can api. Currently I'm looking at memory game.
Is event.data.statement.result.completion used in each question type? Is there a consistent way to asses when a question is answered with the externalDispatcher?
Thanks,
Andrew
falcon
Thu, 06/23/2016 - 11:41
Permalink
Hi,event.data.statement
Hi,
event.data.statement.result.completion should be consistent for all question types that has xAPI support. Do note that in a question set for instance each question also might send statements where completion is set to true. Look in context.contextActivities.parent, if no parent it is the root activity and when the root activity sets result.completion to true it is complete
arosboro
Thu, 06/23/2016 - 14:36
Permalink
I'm not even able to test
I'm not even able to test whether these values are set.
My code does not write to the console:
H5P.externalDispatcher.on('xAPI', function (event) {
var complete = event.data.statement.result.completion;
console.log(event);
console.log('hi');
console.log(event.data.statement);
if (complete == true) {
$("#edit-submit").fadeIn();
}
});
falcon
Mon, 06/27/2016 - 10:54
Permalink
Does your code crash? event
Does your code crash? event.data.statement.result.completion isn't always set,... If you move that line further down and/or replace it with event. getVerifiedStatementValue you should be good.
arosboro
Mon, 06/27/2016 - 20:20
Permalink
There is no indication that
There is no indication that the dispatcher is registering my listener or that the memory game calls xAPI events at all. My testing consists of logging the EventDispatcher which has the on callback and is not undefined. And then attempting to log to the console when completing a memory game in the listener.
When I paste
H5P.externalDispatcher.on('xAPI', function (event) {
console.log(event);
});
in the console, i get undefined and no further messages while working through the memory game.
falcon
Mon, 06/27/2016 - 21:32
Permalink
Are you perhaps embedding H5P
Are you perhaps embedding H5P from another site into your website?
arosboro
Mon, 06/27/2016 - 21:43
Permalink
thanks for continuing to work
thanks for continuing to work with me on this. It's a drupal site, there are no iframes... infact when we do this with h5p video which uses iframes it works.
the full behavior looks something like this now (the console log 'registered' displays in console):
Drupal.behaviors.forceh5p = {
attach: function (context, settings) {
if ($('.quiz-question-node--h5p_content').length) {
Drupal.behaviors.forceh5p.checkH5P();
console.log('I checked h5P');
if ($('.h5p-content').contents().find('.h5p-container')) {
$("#edit-submit").hide();
}
var id = $('.h5p-iframe').attr('data-content-id');
$("#h5p-iframe-" + id).load(function () {
if ($("#h5p-iframe-" + id).contents().find('.h5p-content')) {
$("#edit-submit").hide();
}
});
}
},
checkH5P: function () {
if (typeof H5P.externalDispatcher.on !== 'undefined') {
console.log(H5P.externalDispatcher);
Drupal.behaviors.forceh5p.registerH5P();
}
else {
window.setTimeout('Drupal.behaviors.forceh5p.checkH5P();', 100);
}
},
registerH5P: function () {
console.log('registered');
H5P.externalDispatcher.on('xAPI', function (event) {
//var complete = event.data.statement.result.completion;
console.log(event);
console.log('hi');
console.log(event.data.statement);
var complete = event.getVerifiedStatementValue;
if (complete === true) {
$("#edit-submit").fadeIn();
}
});
}
};
arosboro
Mon, 06/27/2016 - 21:45
Permalink
The submit button gets hidden
The submit button gets hidden but does not log console events while interacting with the question to indicate a means for showing the submit button when the question has been answered.
falcon
Tue, 06/28/2016 - 10:51
Permalink
If you just add H5P
If you just add H5P.externalDispatcher.on('xAPI', function (event) {
console.log(event);
}
in you console on a page without iframe, does it work? Are you using the newest Drupal 7 H5P module?