1. Home
  2. Docs
  3. JavaScript API
  4. Gorilla tutorial

Gorilla tutorial

This tutorial will teach you to setup Mind-Trace in a Gorilla code editor experiment.

Note: It is not possible to use Mind-Trace with a Task Builder experiment at this moment. We will update this tutorial once that feature becomes available.

Step 1: Create a new project, we named it “Mind-Trace Example”

Step 2: Open the new project, and create a new experiment. We named it “Mind-Trace Experiment”.
Step 3: Add two new tasks: “Mind-Trace Setup” and “Mind-Trace Teardown”.

Step 4: Open the “Mind-Trace Setup” task and click “Edit”.

Step 5: Open the “Toolbox” and select “Use Metrics” as well as “Use Head”.

Step 6: Then, open the “Head” section, and add:
<script src=”https://static.mind-trace.com/js-api/v1.0/mindtrace.js”></script>

Step 7: Open “Metrics” and add a new metric called “event”.

Step 8: Create a new script called “main”, then add the following script:

import gorilla = require("gorilla/gorilla");

declare var exports: any;
const mindtrace = exports.mindtrace;

// The experimentId uniquely identifies your experiment within the Mind-Trace system.
const experimentId = 85;

// The experimentPassword makes sure only people with the password can access your
// experiment. There are two types of password:
//  - Single use passwords, that are unique to a specific participant
//  - Global passwords, that can be used by any participant
// Within Gorilla we only support global passwords.
const experimentPassword = '602439d5-6f7b-4e71-bd23-1e64d6e34709';

// The identifier you use for this session, it must be unique
const yourSessionId = 'unique-identifier-' + mindtrace.getUuid();

// Connect to MindTrace and enable Gorilla support
// This might take a few seconds, so you might want to display
// a spinner to indicate things are moving forward.
mindtrace.connectWithGorilla(gorilla, experimentId, yourSessionId, experimentPassword)
         .ready(function(session) {
             if(session === undefined) {
                 // Connection to Mind-Trace failed.
             } else {
                 // Mind-Trace is working fine.
             }
             
             // Do your experiment here
             console.log('Your experiment comes here...');
             
             // We keep the Mind-Trace experiment open such that
             // we can use it in future tasks. Not that
             // Mind-Trace needs to be initialized in EVERY task!
             //
             // See the "Mind-Trace Teardown" script for an example
             // on how to continue an existing session.
             gorilla.finish();
         }, function(error) {
             // Handle Mind-Trace run-time errors here...
             gorilla.finish();
         });

Step 9: Now click the “Commit Version 1” button to save your changes.

Step 10: Do the same for the “Mind-Trace Teardown” task, except use the following code for the “main” script:

import gorilla = require("gorilla/gorilla");

declare var exports: any;
const mindtrace = exports.mindtrace;

// To continue an existing Mind-Trace session, omit ids and password:
mindtrace.connectWithGorilla(gorilla)
         .ready(function(session) {
             if(session === undefined) {
                 // Connection to Mind-Trace failed.
                 gorilla.finish();
                 return;
             }
             
             // We currently do not support dynamic calibration
             // within Gorilla. To run the calibration routine
             // again, you can run:
             session.calibration.reset();
             mindtrace.runCalibration(session.calibration).then(() => {
                 gorilla.finish();
    
                 // After you are done with Mind-Trace in your experiment,
                 // you should close the session. Once the session is closed,
                 // you can no longer use Mind-Trace in the experiment.
                 mindtrace.close();
             });
             
         }, function(error) {
             // Handle Mind-Trace run-time errors here...
             gorilla.finish();
         });

Step 11: Go back to the project overview and open “Mind-Trace Experiment”.

Step 12: Click edit to edit your experiment.

Step 13: Click “add new node”, then select “Task” and click “ok”. Now select the “Mind-Trace Setup” task.

Step 14: Also add the “Mind-Trace Teardown” task.

Step 15: Click the circle below the “Start” node and drag it to the “Mind-Trace Setup” task to connect them. Then connect the setup task with the “Mind-Trace Teardown” task and finally connect the teardown task with the “Finish” node.

Step 16: Now click “Commit version ..” to save your experiment.

Step 17: Click “Preview experiment” to test it.