tunapanda / h5p-standalone

Display H5P content without the need for an H5P server
MIT License
272 stars 117 forks source link

Activity id does not seem to be passed to xAPI events #78

Closed mrik974 closed 3 years ago

mrik974 commented 3 years ago

Hi there ! I'm using your lib to display multiple H5P activities in a single page. Each activity has an id set. I'm also using H5P.externalDispatcher to track on xAPI events. It works, every activity displayed sends events that are caught and forwarded by the dispatcher. But every event I receive looks like this (note the object.id field ) :

Screenshot 2021-04-25 at 21 06 22

I've tried multiple kinds of id, even an URI (which, by the way, is a xAPI requirement).

I don't know what to do, I need this id to correctly handle the events. Do you have a solution, or a workaround ?

Edit : Here's the iframe code for the first activity, the content-id field is set to undefined.

<iframe id="h5p-iframe-undefined" class="h5p-iframe h5p-initialized" scrolling="no" data-content-id="undefined" style="width: 100%; height: 205px; border: medium none; display: block;" src="about:blank" frameborder="0"></iframe>

Have a good day,

Emeric

mrik974 commented 3 years ago

Hi there. I tried a few things and I've found out that the minified version (or even the js file) of the lib does not contain any reference to the options.id field. I mean in your "h5p-standalone.class.ts" there's this line : this.id = options.id || Math.random().toString(36).substr(2, 9); But I can't find any reference of it in the js file nor in the minified file. When I manually add this to the main.bundle.js (I know it's bad practice, I just want to try a few things out without having to rebuild the lib), it works and the H5P activity has an id :
n.id ? (this.id = p(n.id)) : (n.id = Math.random().toString(36).substr(2, 9)), Here's the result in the DOM after I added this :

Screenshot 2021-04-26 at 14 50 28

But, it doesn't end here. Even though the ID is now set, the xAPI events do not use it at all and I still have an undefined field.

kileha3 commented 3 years ago

Hi @mrik974, I think this issue was addressed on pull request #54 commit https://github.com/tunapanda/h5p-standalone/pull/54/commits/da064164d8ba1d71bce9c32be0b97ed360b1b9d0 but unfortunately, it wasn't merged into master. I will try merging the latest master so that later can be merged into master.

kileha3 commented 3 years ago

Activity ID was being passed as one of query params to the URL, something like this:- http://localhost:8080/index.html?actor={"account":{"homePage":"http://localhost:8080/","name":"John Doe"}}&endpoint=http://localhost:8080/xapi/13112/&auth=OjFjMGY4NTYxNzUwOGI4YWY0NjFkNzU5MWUxMzE1ZGQ1&registration=a1045a8f-474b-4e58-aae3-fad297dd3632&activity_id=http://localhost:8080/177892100433350656/3196e3e6-6f56-457c-95ef-882b734ac96d

mrik974 commented 3 years ago

Hi @kileha3 thank you for your answer, but I don't think I have the same issue. The present commit shows an object called registration being modified, but I believe my matter is more about the activityId object. Also I am not trying to send the xAPI event through the H5P lib, I'm only trying to catch them. And finally the activityId in the file vendor/h5p/js/h5p.js seems to be stored within the global H5P variable, which doesn't seem good in my use case where I have multiple activities displayed in the same screen. It showed me a lead to follow though, I'll try to see where the event is generated in the H5P vendor lib.

mrik974 commented 3 years ago

I haven't found out what's going on but what I've found out is the h5p event has an object.definition.extensions field that contains the id. I think it's really more a matter of vendor lib then, so I won't bother you with it. Also, the missing line in h5p-standalone.class.js was repaired in version 3.0.1 (I don't know why npm didn't install the latest version, as I'm working on a very recent project...) I'll close the issue, sorry for bothering you :)