Overview
The basic integration sends only your survey number and the respondent’s session ID. The advanced integration also loads the Research Defender JavaScript library in the respondent’s browser. The library collects additional datasets, and the search API processes them to produce a more complete result. Because the library needs a moment to collect its data, your integration waits for a short interval before calling the search endpoint.How it works
1
Load the library
Import
rd_sys_util.min.js from your Research Defender environment.2
Initialize it
Call
init() with your publishable key and environment so the library starts collecting data.3
Wait for the datasets
Pause for a short interval (1 second by default) so the datasets are ready.
4
Get the pass-through value
Call
pass_params(). It returns a string that you send with the search request.5
Call the search endpoint
Send a
POST or GET request that includes your survey number, the session ID, and the pass_params() value.Prerequisites
- A Research Defender publishable key
- Your survey number (
sy_nr) - The respondent’s session ID (
sn_ud) - A page served over HTTP(S). Opening the file directly from disk (
file://) will not work.
Configuration
Endpoints
string
https://{environment}.rtymgt.com/static/js/rd_sys_util.min.js?v={version}string
https://{environment}.rtymgt.com/api/v4/respondents/search/{publishable_key}Request parameters
string
required
The survey number.
string
required
The respondent’s session ID.
string
Set to
"1" to enable.string
Set to
"1" to enable.string
required
The string returned by
pass_params(). Send it as the name of a parameter with an empty string as its value.Requests must be sent with credentials (
credentials: "include") so Research Defender cookies are included.Examples
- POST
- GET
advanced-post.js
Full HTML pages
If you want a complete page you can open in a browser, use one of the samples below. Replace the placeholder values at the top of the script, then serve the file over HTTP, for example withpython3 -m http.server.
Advanced POST integration (HTML)
Advanced POST integration (HTML)
advanced-post-integration.html
Advanced GET integration (HTML)
Advanced GET integration (HTML)
advanced-get-integration.html
Tuning the wait interval
The default 1-second wait gives the library time to collect its datasets. If results look incomplete on slower devices, increaseDATASET_READY_DELAY_MS. Avoid setting it higher than your survey flow can tolerate, since respondents wait for it before the search call is made.
Handling errors
The samples throw an error if the library fails to load or if the search returns a non-200 status. Decide in advance how your survey should respond, for example letting the respondent continue and logging the failure.
