Skip to main content

Class SessionInfoFetcher

Retrieves the participant's server-assigned subject ID from the backend and populates a SessionInfo instance with the result.

public class SessionInfoFetcher

Inheritance​

Remarks​

In the WebGL deployment, a participant arrives at the study URL with their Prolific or MTurk worker ID embedded as a query parameter (e.g., ?search=ABC123). This class reads that parameter, posts it to the backend, and receives back a numeric subject ID that the backend assigns for data linkage. The subject ID is what links WebGL telemetry to the participant's survey responses.

In Editor and Standalone Windows builds, the worker ID and subject ID can be overridden via command-line arguments so developers can test specific participant configurations without running through the web form flow.

Constructors​

SessionInfoFetcher()​

Initialises the fetcher with a sentinel response code indicating no fetch has occurred yet.

public SessionInfoFetcher()

Properties​

HasError​

true when the server returned a code other than 200 or 201, indicating that the subject ID lookup failed or the request was rejected.

public bool HasError { get; }

Property Value​

bool

Remarks​

The guard ResponseCode > 0 excludes the initial -1 sentinel so that callers can check HasError before Fetch has completed without getting a false positive.

ResponseCode​

The HTTP status code returned by the server, or -1 if the request has not yet run.

public int ResponseCode { get; }

Property Value​

int

Result​

The populated SessionInfo object after Fetch completes.

public SessionInfo Result { get; }

Property Value​

SessionInfo

Remarks​

null before Fetch has been called. Callers should check HasError before reading fields from this result.

Methods​

Fetch()​

Posts the participant's worker ID to the backend and retrieves the assigned subject ID.

public IEnumerator Fetch()

Returns​

IEnumerator — An IEnumerator that must be driven by a MonoBehaviour coroutine.

Remarks​

The coroutine first resolves a fallback subject ID from AuthSettings. In Editor and Standalone Windows builds, a command-line override (--subjectID N) takes precedence over the fallback so QA testers can run as specific participants without going through the web form flow.

When server connectivity is enabled and a server address is configured, the participant's worker ID is either read from the URL (?search=…) or taken from the fallback. That ID is then posted to the server and the server's JSON response is deserialised into PhpResponse to extract the numeric subject ID.

QueryParamsFromURL(string, string)​

Parses the value of queryKey from a URL's query string.

public string QueryParamsFromURL(string url, string queryKey)

Parameters​

NameTypeDescription
urlstringThe full URL, e.g. https://example.com/study?search=ABC123.
queryKeystringThe query parameter name to look up.

Returns​

string — The decoded parameter value, or an empty string if the parameter is absent from the URL.