Web SpotChecks
Last updated
Last updated
The step-by-step instructions to install SpotChecks within your web application are as follows. For each step below, the respective snippet is found in the SpotChecks.
In the installation steps for the target, copy the JavaScript snippet and place it right before the </body> on all the necessary pages. This bundled JavaScript allows for efficient interaction between the survey and your application.
Note: If your application runs on SPA(Single-Page Application) architecture, then the JavaScript snippet should be inserted in the root file. For instance, if you are using a React application, then you should insert it in the index.js file, right below the <App/> component. But if you are a using Multi-Page application, then the snippet should be inserted on all the necessary pages.
You can find the installation steps while creating the target or under the target dropdown field.
Note: Make sure to insert the snippet on all the necessary pages in your application.
The next step in the installation is to display the survey which requires adding the following snippet right below the installation snippet.
It is recommended to pass the visitor's or user's email or user's mobile in the userDetails. This will help create a contact in your SurveySparrow account. If no email or mobile is passed, then a unique ID will be generated and an anonymous contact will be created.
Also, If you are not collecting email from the user, then you can pass in a unique key in the userDetails in the below format.
Note: the userDetails should be the same as the contact properties in SurveySparrow such as firstName, lastName, etc.
In simple words, userDetails allows you to keep track of the user data and create a contact.
Global Variables are the key-value pairs that you pass as query parameters in the survey URL. You can find it in the builder section of the survey. Make sure to use the API identifier of the global variable, which you will find when you are creating a variable.
While using variables of type "Date", it is recommended to pass the value as a String in the following format -> "yyyy-mm-dd" or "mm-dd-yyyy"
To dynamically change survey language, you can utilize the sparrowLang property within the variables. The key thing to note here is you can only use the languages configured in the languages tab of the builder page of a survey.
These are the custom properties that you can pass along with the survey trigger. These properties can be used as a condition in the "visitors" section of the configure panel.
To set a condition, go to the Configure panel, click on visitors, add a condition, select Visitor Properties, and then select Custom Properties. The Custom Properties can be shown only when the survey is triggered for the first time.
To let spotcheck listen to the events happening within the application and trigger the survey when those events get triggered, just pass the class name or the ID of the element in the checks section of the configure panel.
Go to the "configure" panel, toggle the "Checks" section, choose "on a mouse event", select the event "Click" and enter the id(#survey-trigger) of the button element in the "Add element" field. You can also enter the class name of the element.
The list of all mouse events is as follows:
Click
MouseOver
MouseOut
MouseEnter
MouseLeave
In some instances, your app might need more events because the existing mouse events might not suffice the app's requirements. In that case, Spotcheck allows you to create a new event and trigger that event from within your app.
Go to the "configure" panel, toggle the "Checks" section, and choose "After a custom event". Here, you can create a new event and also choose when the survey should be displayed when that event gets triggered.
Below is the syntax to set up custom events in your web application.
There is also an option to pass custom properties to the event triggers using which you can set conditions in the visitors section of the configure panel.