How to use Javascript trigger in survey embedding

How to use Javascript trigger in survey embedding

Here you will learn to use JavaScript trigger in your webpage for embedded survey

Use Javascript trigger if you want to trigger the survey on a specific action taken by the user on your website or web application.

Suppose a user just signed up to your platform and you want to show them the survey regarding the signup experience, in that case, you can just use this trigger to start the survey.

How to use it?

NOTE: Before starting with this section, you must have basic knowledge of the Javascript Language.

Step 1: Select the Javascript trigger from the targeting section.

Step 2: Enter an event name you would like to use as your trigger, only alphanumeric characters (a-z, A-Z, 0-9), underscores (_), and dashes (-) can be used in the trigger name. This field cannot be left blank.

Note: If a Javascript trigger is present on a page, it will cause the survey to show regardless of any other rules present.

Step 3: Click Done.

Step 4: Add trigger code to the website

In the example above, we’ve created a trigger called user_logs_in. Next, you will need to add the trigger code to your website:

window.surveysensum.startSurvey(‘user_logs_in’);

When you want to set user info to be captured in the respondent data your can use setUserInfo method. If you want to save the transactional data in the respondent for example transaction amount, you can use seetMedatadataInfo method:

const userInfo = { "Email": "sample@test.com", Name: "Sample user", "Phone Number": "911234567890" };
window.surveysensum.setUserInfo(userInfo);
const metadata = { "Sample Metadata 1": "Meta 1", "Sample Metadata 2": "Meta 2" };
window.surveysensum.setMetadataInfo(metadata);
window.surveysensum.startSurvey("transaction_completed")