• Resolved cwhlin

    (@cwhlin)


    I followed one of the previous posts and added the following code to my theme’s functions.php file.

    function h5pmods_alter_scripts(&$scripts, $libraries, $embed_type) {
    if (isset($libraries[‘H5P.DragQuestion’])) {
    $scripts[] = (object) array(
    // Path can be relative to wp-content/uploads/h5p or absolute.
    ‘path’ => ‘score-tracking.js’,
    ‘version’ => ‘?ver=1.2.3’ // Cache buster
    );
    }
    }
    add_action(‘h5p_alter_library_scripts’, ‘h5pmods_alter_scripts’, 10, 3);

    I then added a score-tracking.js with the following code:

    H5P.externalDispatcher.on(‘xAPI’, function(event){
    if (event.result.score.raw() === event.result.score.max()){
    console.log(‘The user has exceeded our expectations!’);
    }
    });

    However, when I go back to my page with the drag and drop and gets a maximum score, nothing shows up in the console log.

    https://www.littlechinesereaders.com/staging/?sfwd-topic=drag-and-drop-h5p

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author icc0rz

    (@icc0rz)

    The PHP parts looks fine, but there’s some minor issues with the score-tracking.js.
    Try copying and pasting this into the file:

    
    H5P.externalDispatcher.on('xAPI', function (event) {
      var statement = event.data.statement;
      if (statement.result.completion && statement.result.score.scaled === 1){
        alert('You exceeded our expectations!');
      }
    });
    

    Note that the code is sensitive about which ' symbols are used.
    If you want to see what’s happening you could add a debugger; line inside the function.

    Thread Starter cwhlin

    (@cwhlin)

    I modified the js file as follows:

    H5P.externalDispatcher.on(‘xAPI’, function (event) {
    console.log(event.data.statement);
    var statement = event.data.statement;
    if (statement.result.completion && statement.result.score.scaled === 1){
    alert(‘You exceeded our expectations!’);
    }
    });

    However, the h5p doesn’t load in this case. If I remove the condition, then it will load.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘API Score Reporting’ is closed to new replies.