A jsPsych Extension enabling integration with the Gorilla online behavioral experiment platform, designed to extend your jsPsych experiment with new features and capabilities.
🚨 Neurocog.js is now a jsPsych Extension! This means that Neurocog.js v0.4.0+ is only compatible with jsPsych v7.0+. For earlier jsPsych versions, please use Neurocog.js v0.3.9 or earlier. 🚨
Gorilla integration
Facilitates interaction with parts of the Gorilla API. Load and access stimuli, access manipulations, and update stored data while maintaining the same codebase online and offline. The wrapper library detects what context the experiment is running in and makes API calls accordingly.
A global state is maintained outside of the jsPsych instance. While not an advisable for experiment-wide data storage, a state system can be used to direct task logic and add an element of dynamic behavior. Additionally, it could function as temporary data storage.
By listening for errors in the browser, this library provides graceful error handling and alerts participants before ending the experiment. This prevents online experiments from hanging or resulting in the complete loss of participant data.
A seeded RNG is provided using the D3.js library.
npm install neurocogyarn add neurocogOnce installed, refer to the jsPsych guide on Extension usage for instructions to enable the Neurocog.js extension within your existing experiment using jsPsych v7.0+. Refer to Configuration below for further information regaring the expected parameters (params).
npm install neurocog@0.3.9yarn add neurocog@0.3.9Neurocog.js expects a number of parameters (params) when being initialized. There are also optional parameters (parameters in bold are required):
| Name | Type | Description |
|---|---|---|
| name | string |
A human-readable name for the experiment such as "Brain Game" |
| studyName | string |
A machine-readable name for the experiment plugin such as "brain-game". No whitespace is permitted. |
| allowParticipantContact | boolean |
Whether or not to show an email address for participants to contact in the case of an error. |
| contact | string |
The contact email address for the experiment. |
| seed | number |
A float to act as the seed for the RNG. |
| state | key : value |
State initialisation parameters. This object is digested as the initial state and is accessible during the experiment using the same keys. While not required, it must be at least defined if state functionality is to be used. |
| logging | LogLevel |
Set the logging level of the consola logging utility. |
| Name | Type | Description |
|---|---|---|
key : value |
A collection of key-value pairs that represent the manipulations configured in Gorilla. The key must be a string, and the value can be a string, boolean, or number. While required, it can be empty. | |
key : value |
A collection of key-value pairs that represent resources used in the experiment. The key can be used as a unique identifier for accessing the resource in the source code. The value is the relative path to the actual resource. While required, it can be empty. | |
key : value |
A collection of key-value pairs that represent the stimuli used in the experiment. The key can be used as a unique identifier for accessing the stimulus in the source code. The value is the relative path to the actual stimulus. While required, it can be empty. |
To utilize the Neurocog.js functionality in timeline trials, ensure that the trial object contains the extensions parameter containing the type NeurocogExtension, shown below:
var timelineNode = {
...
extensions: [
{
type: NeurocogExtension,
}
],
...
}Check out the experiment in the example/ directory for a simple example.
Gorilla: Manipulations
getManipulation function takes two arguments, the name, and a default value. If running locally, the default value will always be returned. If running on Gorilla, the Manipulation value specified on Gorilla will be returned.
Accessing Manipulations:
const variableA = jsPsych.extensions.Neurocog.getManipulation("variableA", 2);
console.log(variableA); // The value of the manipulation if specified on Gorilla, otherwise 2Gorilla: Stimuli
The key for a Stimulus must be the exact file name.
Accessing Stimuli:
const imageSrc = jsPsych.extensions.Neurocog.getStimulus('stimulus.jpg');
console.log(imageA); // 'stimuli/stimulus.jpg' locally or the path to a Gorilla StimulusGorilla: Resources
The key for a Resource must be the exact file name.
Accessing Resources:
const resourceSrc = jsPsych.extensions.Neurocog.getResource('resource.jpg');
console.log(resourceSrc); // 'resource/resource.jpg' or the path to a Gorilla ResourceConfiguring State:
const jsPsych = initJsPsych({
// ...
extensions: [
{
type: NeurocogExtension,
params: {
// ...
state: {
counter: 0,
// ...
},
// ...
}
}
],
// ...
});The following methods can be used for interacting with the experiment state throughout the experiment:
| Method | Parameters | Description |
|---|---|---|
getState(key) |
key: string |
Get the value of a global state variable |
setState(key, value) |
key: string, value: any |
Set the value of a global state variable |
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
