Title: API Score Reporting
Last modified: February 1, 2018

---

# API Score Reporting

 *  Resolved [cwhlin](https://wordpress.org/support/users/cwhlin/)
 * (@cwhlin)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/api-score-reporting/)
 * 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](https://www.littlechinesereaders.com/staging/?sfwd-topic=drag-and-drop-h5p)
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fapi-score-reporting%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [icc0rz](https://wordpress.org/support/users/icc0rz/)
 * (@icc0rz)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/api-score-reporting/#post-9927072)
 * 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](https://wordpress.org/support/users/cwhlin/)
 * (@cwhlin)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/api-score-reporting/#post-9929224)
 * 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.

 * ![](https://ps.w.org/h5p/assets/icon.svg?rev=986118)
 * [Interactive Content – H5P](https://wordpress.org/plugins/h5p/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/h5p/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/h5p/)
 * [Active Topics](https://wordpress.org/support/plugin/h5p/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/h5p/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/h5p/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [drag-and-drop](https://wordpress.org/support/topic-tag/drag-and-drop/)

 * 2 replies
 * 2 participants
 * Last reply from: [cwhlin](https://wordpress.org/support/users/cwhlin/)
 * Last activity: [8 years, 3 months ago](https://wordpress.org/support/topic/api-score-reporting/#post-9929224)
 * Status: resolved