WordPress: Could user see their results without being logged in?


this is a quite general question: we would like to use H5P for self assessment quizzes and tests on a wordpress site. The users should not be forced to log in, but they need to view the results of their own tests. As we will use quite different H5P content types we would need the possibility to show the results on different pages and a summary result.

We "as admins" are not interested in analyzing the results, so it's not necessary to store these in the database.

I thought to use javascript variables, as local browser storage or session storage would be sufficient for our needs. But as I can't find anywhere a "how to" or documentation of such an approach with h5p, I am afraid that this could not be possible at all?

Any help would be highly appreciated, thank you!




otacke's picture

Hi osa19!

Should not be difficult. You can catch the xAPI result statements that H5P emits and store them in the browser's local storage. They can then be retrieved and displayed as needed on other posts/pages.

It's nothing that H5P provides, but creating a WordPress plugin for this job isn't difficult. Feel free to rip H5PxAPIkatchu apart and reuse the code if you need to: https://github.com/otacke/h5pxapikatchu



Hi Oliver,

thank you very much for your quick reply and encouraging me to reuse your commented code. Good to know that "creating a WP plugin isn't difficult" - but I am afraid not possible for me with limited programming knowledge. I'll keep looking around, maybe I'll find a similar solution somewhere which I could further adapt for our needs.

Thanks again!

otacke's picture

Hi osa!

I don't think you'll find a solution where you just need to change a couple of lines.

That's why I mentioned H5PxAPIkatchu that already listens for xAPI statements within a plugin - instead of writing them to a database, you can filter them for results and put those into local storage.

The other half is adding a shortcode that you can put into pages or posts, cmp. https://codex.wordpress.org/Shortcode_API



Hi Oliver,

although this is quite a big effort for me - as being new both to xAPI and WordPress - I am still willing to do the next steps. Thanks to you preventing me turning into the wrong direction ... So I digged a little bit further into your code and as far as I understand this is my to do list:

  1. eliminate all the database stuff out of h5pxapikachu plugin. For exapmle in the h5pxapikachu.js in the "var sendAJAX" there is no "action: 'insert_data'" any more but "action: 'get_data'". This will be my new function to retrieve the result data out of the xAPI statement object. I managed already quite simple things in the console such as "event.getScore();", so this would be the "filter for results" part - my first feeling of success. ;)
  2. "put those into local storage" - I managed to "localStorage" the xAPI statement object or certain values as the score and to retrieve the object from storage and log the values into the console - second feeling of success. ;)
    I am not sure yet (but will see) how to resolve this with several H5P content types - for the beginning I just tried with true / false answer.
  3. the function with the shortcode is still the difficult task for me - so that I could transfer the console.log things into my pages where I need them, right? I will have a deeper look in it on Friday (I don't work every day on this project).

I have the feeling that you are a German programming freelancer, is that right? If so, would you generally be interested in being hired for this job from a German university? Although it is really fun for me to develop my programming skills I am sure that I will never be capable to code the WP plugin in the right clean way as it should. In addition my testing was only with two or three H5P content types but we will use far more of them in our project. I would need a clean code base which I could alter then for our needs by myself.

Just a side note: The "track the results of anonymous user" is already on the H5P "features requests" since two years, but obviously hasn't been realised so far. https://h5p.org/node/82264

Anyway, a big thank you for helping me so far - I really appreciate this kind of support very very much. Cheers. :)

otacke's picture

Hi osa!

  1. Yes, you can get rid of all the database stuff, and you also don't need DataTables unless you want to use it to present the results - would be cracking a nut with a sledgehammer though. My function was called insert_data because it does just that - insert data into the database. Feel free to use the name that works best for you :-) But I don't think you really need the AJAX stuff at all, because you don't neet to bring anything to the backend. You can write to localStorage from JavaScript right after filtering for the events that you need.
  2. Good job! I suggest you use the contentID to identify the content types. It can be extracted from object.definition.extensions. It's the same that's used in the plugin on the PHP side.
  3. Shortcodes are part of the WordPress API, and there are lots of tutorials. Basically, you just define a, well, shortcode that you can include into WordPress posts just like adding H5P content. There are probably several ways to retrieve the results later on, but a straight forward approach would be: If there's your shortcode in the page (and the document has loaded), fire up your JavaScript to retrieve the results from the localStorage (for the content ID of the content - either defined as a shortcode parameter or by checking the H5PIntegration object or ...; could also be all results, etc.) and put some HTML element (your results table, whatever) at the position where the shortcode was placed.

I am a German IT freelancer, that's right. If there's a university that would fund this, sure. Just let them reach out to me (still need to set up a proper site for stuff like this, I guess :-D). However, don't give up just yet!!! If you finish your code, I'll gladly give it a review and suggest some improvements if I see anything "suspicious".

I think many people mistake filing in a feature request for putting something onto a "to do" pile. There's no guarantee that a feature request will ever be picked up by the H5P core team, a) because they focus on picking those requests that seem to benefit as many people as possible and, more importantly b) the feature requests are directed to the H5P community (as are questions in this forum). Anyone is welcome to pick them up, contribute to the main code base, develop complementary scripts and plugins, etc. That's what some people including myself do, but the more the merrier.


Hi again, Oliver,

wow, I am really impressed and grateful for your helpful support and efforts, thank you VERY much once again!

I considered your hints and developed my code a little bit further - kind of feeling two steps forward, one step back (better than vice versa ;).
I am not giving up yet but I will need some more time to understand your coding and all the xAPI and plugin stuff - or possibly aks you more questions. Thanks for the review offer. BUT I am feeling that you gave me already far more than I had expected and I will send you a pm to get in touch - and speak about the money for possible further support (and speak German :). 

As for your final remark about the "feature request not being solved" - you are absolutely right. I didn't want to complain or to push someone to solve my problems. ;) I just felt a little confirmed with my wishes for that Wordpress H5P plugin because I am not the only one who missed that special feature. Thank you for explaining the "community thing". If one day we will have developed such a plugin I would be more than happy to publish it so that everyone who is interested can use it for his / her own needs.

To be continued via pm ...! :)