Pushkin
  • Welcome!
  • Getting Started
    • Installing Pushkin and dependencies
      • macOS
      • Windows 10
        • Windows Subsystem for Linux
        • AWS EC2 Instance
      • Ubuntu Linux
    • Quickstart
      • Quickstart: Example Outputs
    • Deploying to AWS
      • Install required software.
      • Configure the AWS and ECS CLIs.
      • Register a domain.
      • Set up DockerHub.
      • Initialize AWS Deploy.
    • Tutorial: Simple Experiment
  • FAQ
    • FAQ
  • Advanced
    • Pushkin CLI
    • Using Experiment Templates
      • Lexical decision template
      • Grammaticality judgment template
      • Self-paced reading template
    • Experiment Component Structure
      • Experiment Config.yaml Files
      • Experiment Web Page Component
      • Worker Component, Migration, and Seed
    • Modifying Site Template
      • React Bootstrap
      • Header and Footer
      • Home Page
      • Findings Page
      • About Page
      • Feedback Page
    • Troubleshooting Pushkin
    • Pushkin Client
    • pushkin-api
      • API Controller Builder
      • Core API
    • Users & Authentication
    • Deployment
      • Deleting AWS
  • Developers
    • Developing with Pushkin
    • Getting Started on Development
    • Overview of Technologies
    • Testing Pushkin with Jest
    • Working with Templates
Powered by GitBook
On this page
  • Skip to section
  • connect
  • loadScript
  • loadScripts
  • prepExperimentRun
  • getAllStimuli
  • saveStimulusResponse
  • insertMetaResponse
  • endExperiment
  • customApiCall

Was this helpful?

  1. Advanced

Pushkin Client

PreviousTroubleshooting PushkinNextpushkin-api

Last updated 1 year ago

Was this helpful?

Skip to section

The Pushkin client is available on NPM under pushkin-client. It should be instantiated once imported into a web page:

import pushkinClient from "pushkin-client";
const pushkin = new pushkinClient();

The module has the following methods:

connect

Arguments:

  • API URL : string

    Location of this experiment’s API endpoint.

Returns: Promise. Resolves on successful connection.

loadScript

Arguments:

  • URL : string

    URL of a script to load

Returns: Promise. Resolves upon successfully loading the script.

Useful for loading external jsPsych plugins from a CDN. Scripts are reloaded if already present in the DOM, making sure they run again if a page changes.

loadScripts

Arguments:

  • URLs : string array

    URLs to load.

Returns: Promise. Resolves upon successfully loading all scripts.

A convenience function. Uses loadScript and Promise.all in the backend.

prepExperimentRun

Arguments: None

Returns: Promise. Resolves upon affirmation.

Sends a POST request to [expapi]/startExperiment to allow the backend to prepare stimuli for the experiment, if need be. Depends on defaults being enabled in the experiment’s API and worker.

getAllStimuli

Arguments: None

Returns: Promise. Resolves to an array of jsPsych stimuli.

Obtains the stimuli for this experiment in one request. Depends on defaults being enabled in the experiment’s API and worker.

saveStimulusResponse

Arguments:

  • jsPych data object : { user_id : int, … }

    Data to be saved in the database under user_id. Posted to [expapi]/stimulusResponse.

Returns: Promise. Resolves upon successful database save.

The function setSaveAfterEachStimulus is now deprecated, so saveStimulusResponse is called at the on_data_update event which happens at the end of every jsPsych trial after the on_finish (trial) and on_trial_finish events. The function is added as a parameter when initializing jsPsych in experiments/[experiment]/web page/src/index.js like so:

const jsPsych = initJsPsych({
  ...,
  on_data_update: (data) => pushkin.saveStimulusResponse(data),
});

insertMetaResponse

Arguments:

  • jsPych onfinish data : { user_id : int, … }

Returns: Promise. Resolves on successful connection.

endExperiment

Arguments: None

Returns: Promise. Resolves upon successfully notifying the worker.

Notify the worker that the experiment has ended and that it can stop preparing for future stimuli. This should probably be called whenever the user leaves a page in the middle of an experiment as well.

customApiCall

Arguments:

  • path : string

    URL of API endpoint to send this call to.

  • data : object

    Data to send to the API endpoint.

  • httpMethod : string (optional)

    A lowercase string of an HTTP method to call the endpoint, such as “get” or “put”.

Returns: Promise. Resolves with response data.

Simplifies calls to custom API endpoints.

connect
loadScript
loadScripts
prepExperimentRun
getAllStimuli
saveStimulusResponse
insertMetaResponse
endExperiment
customApiCall