otacke / h5pxapikatchu

WordPress plugin to store xAPI statements emitted by H5P
MIT License
10 stars 6 forks source link

Record a timestamp with each xAPI event #17

Closed phgrosjean closed 4 years ago

phgrosjean commented 4 years ago

There seems to be no timestamp associated with xAPI events. It would be great to have one, so the exact chronology of the events could be recorded (would be nice to know if or where a user spends more time in the H5P apps).

otacke commented 4 years ago

@phgrosjean I am a little confused, whether this is some suggestion for H5PxAPIkatchu or for H5P.

H5PxAPIkatchu stores the time of each that the statement was received https://github.com/otacke/h5pxapikatchu/blob/master/class-database.php#L464.

If you want a timestamp to be included in every xAPI statement emitted by H5P, you should address the H5P core team. It's possible to implement, but it is an optional property in the xAPI specification, and Learning Record Stores (or whatever stores the events) should set it if not provided (https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#details-1) like H5PxAPIkatchu or the H5P plugins do for reporting.

otacke commented 4 years ago

@phgrosjean Ah, I think now I get it. You were referencing the xAPI data that you can retrieve from the filter, and those don't contain the timestamp. Shouldn't be an issue for you to set it yourself. I might do that in the future if I find some time.

phgrosjean commented 4 years ago

@otacke Yes, that's it. But as soon as it is recorded in the database, it is fine. I can recover it and I don't need more. But it would be fine to retrieve the timestamp from the filter too.

otacke commented 4 years ago

Hi @phgrosjean !

I have given this some thought, and I think I won't add this to H5PxAPIkatchu. It might be convenient, but it feels weird to have an extra function just for getting the time or to modify the original statement that I want to preserve. As I mentioned, it's up to the LRS (or whatever stores the data) anyway to set the timestamp if it's not included in the xAPI statement. So if you require it, I suggest you set it yourself. You can use the _h5pxapikatchu_insert_dataxapi filter and add the time like:


function handle_xapi_data( $xapi ) {
  // Change from JavaScript
  $xapi = str_replace( '\"', '"', $xapi );
  $xapi = str_replace( "\'", "'", $xapi );
  $xapi = str_replace( '\\\\"', '"', $xapi );

  $xapi_decoded = json_decode( $xapi, true );

  // xAPI Timestamp following RFC 3339
  $xapi_decoded['timestamp'] = current_time( 'Y-m-d\TH:i:s.vP' );

  /*
   * Process $xapi_decoded as required here
   * ...
   */

  return $xapi;
}
add_filter( 'h5pxapikatchu_insert_data_xapi', 'handle_xapi_data' );```
phgrosjean commented 4 years ago

Hello @otacke OK, I understand. I already did this, but I was considering it as a basic feature useful for everyone because xAPI events without time indication represent really only partial information. So now, I close the issue.

otacke commented 4 years ago

@phgrosjean Feel free to add a feature request addressing the H5P core team. They could add the timestamp to every single xAPI statement.