xAPI Completion event

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's picture

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

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's picture

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.

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's picture

Are you perhaps embedding H5P from another site into your website?

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();

              }

          });

        }

    };

 

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's picture

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?