Skip to main content

Trigger Surveys via the JavaScript SDK

How developers can trigger, target, and tag surveys programmatically instead of relying on the built-in triggers.

Written by Jon

On this page

When to use the SDK instead of built-in triggers

The Survey Target tab's built-in triggers (page load, element click, rage click) cover most cases for triggering a survey on your site.

Use the SDK when the moment you want to survey isn't tied to a page or a click at all, such as after a background job finishes, a set amount of usage, or a business event like a cancellation.

To use the SDK path, set the survey's trigger to "Trigger the survey using JavaScript SDK" in the Target tab, then call it from your own code.

For full documentation on triggering surveys using the Javascript SDK see: Javascript SDK Seference Surveys

Trigger a survey with openSurvey()

Call Userback.openSurvey(survey_id) at the moment you want the survey to appear, using the survey's ID from its share or install settings.

Userback.openSurvey('YOUR_SURVEY_ID');

Fire a survey off your own event

Call Userback.addCustomEvent(event_name) to register your own named event as a trigger condition, then select that custom event as the trigger in the Target tab instead of calling openSurvey() directly.

Tag responses with context

You can attach extra metadata to a session with Userback.setData() before a survey opens, so the response comes through with context like the feature the user was on or their plan tier. For the full method list and exact signatures, see JavaScript SDK Method Reference.

What's next

Related articles

Did this answer your question?