immersivecognition / unity-experiment-framework

UXF - Framework for creating human behaviour experiments in Unity
https://immersivecognition.github.io/unity-experiment-framework/
MIT License
221 stars 43 forks source link

Adding URL ID to UXF_UI #66

Closed cofficer closed 3 years ago

cofficer commented 3 years ago

I was wondering if it would be possible to add an additional PPID mode where the ID is grabbed directly from the URL.

I'm using Prolific to recruit participants which then are redirected to Gorilla, and finally to the web page of the WebGL experiment. The addressbar contains their unique participant ID in this form: http://www.your-url-above.com?id=PUBLICID

Gorilla and Prolific have a nice way of integrating their unique participant IDs: https://researcher-help.prolific.co/hc/en-gb/articles/360009223973-Gorilla-Integration-Guide

If the variable PUBLICID could be used directly, it would save the possible user error of entering this manually, and would make for a simple way to match all the data across multiple platforms without the need of several different generated unique IDs per participant.

If I was more comfortable editing the UIController.cs script I would attempt a pull request for this functionality but I think I would just mess it up!

jackbrookes commented 3 years ago

Nice idea, I might get around to adding this - for a quick fix you could call javascript from Unity:

https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

Using this code from here: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript

mergeInto(LibraryManager.library, {

  GetPPID: function () {
    var urlParams = new URLSearchParams(window.location.search);
    var myParam = urlParams.get('ppid');
    return myParam;
  }

)

Call this from Unity, then use this PPID to start the session manually, or set PPID to automatic but then record this new ppid elsewhere.

cofficer commented 3 years ago

Awesome thank you!