Links

Using Query Params

Query parameters play a pivotal role in making web applications, including online experiments, more versatile and customizable. Let's unpack how Cognition leverages query parameters to enhance the user experience and expand experimental possibilities.

1. What are Query Parameters?

At a basic level, query parameters are specific sets of keys and values appended to a URL. They start after a question mark (?) and are often separated by ampersands (&). For instance, in the URL https://example.com?subject=123&group=A, subject and group are query parameters.

2. Integrating with Third-party Applications

By utilizing query parameters, Cognition can:
  • Seamlessly integrate with third-party applications or platforms.
  • Allow external platforms to pass necessary information to the experiment, enhancing configurability.

3. Customizing Experimental Logic

Query parameters offer a dynamic way to adjust experimental logic:
  • Depending on the query parameters passed, your experiment can adapt its behavior.
  • This adaptability is crucial for tailoring tasks to specific groups or even individual participants.

4. Practical Applications

Query parameters offer numerous practical benefits:
  • Subject Identification: Differentiate participants by assigning unique subject IDs via query parameters.
  • Custom Redirects: Direct participants to different end pages based on specific query parameters.
  • Participant Rewards: By generating unique URLs for each participant using query parameters, you can track and reward those who complete the experiment.

5. Accessing Query Parameters in Code

JsPsych, integrated within Cognition, provides a simple function to access these parameters:
javascriptCopy code// Given the URL: https://abcdfge.cognition.run?subject=1234&condition=test
console.log(jsPsych.data.getURLVariable('subject')) // Outputs: "1234"
console.log(jsPsych.data.getURLVariable('condition')) // Outputs: "test"
By employing the jsPsych.data.getURLVariable function, you can directly tap into the query parameters' values and use them in your experimental logic.

6. Data Collection and Analysis

In addition to enhancing real-time experiment dynamics:
  • Cognition ensures that query parameters are appended to the collected data. This inclusion is immensely beneficial during data analysis, allowing researchers to categorize, filter, or analyze based on specific parameters.

7. Development and Testing

As you develop your experiment using Cognition's online code editor:
  • You can simulate the presence of query parameters by clicking on the "Add url params" option. This feature ensures you can test and refine your task's behavior based on various query parameter configurations.
To wrap up, query parameters are a robust tool in Cognition's toolkit, enabling more dynamic, adaptable, and versatile experiments. Whether you're looking to customize tasks, integrate third-party platforms, or simply enhance data analysis, query parameters stand ready to deliver.