Tracking logged in users with SurveySparrow Widget

Very often, you might want to send additional information about the user who is answering your questionnaire through the SurveySparrow widget. 

If you are getting feedback from the users of your application, you already know who is answering, since they have already logged in. Asking for the name and email address again in the widget doesn't make much sense. Also, when you ask a question, addressing your users by their name offers more personalization. With the ability to send variables through SurveySparrow widget it is possible to do so. 

Important Note: Please note that there can be instances when the widget may not appear. In such cases, please ensure the following:

  1. There are no misconfigurations in the script embedded. For example, if the user has set the widget to show only if the URL has "billing" in it, the widget will not appear for any other scenario.
  2. The survey is not in the Private mode.
  3. There is no cut-off date set for the survey.
  4. The channel in use is not paused.
  5. The response limit is not crossed.
  6. The number of responses set by the user(in survey settings) has not crossed the limit.
  7. The survey is not taken already when the user has enabled only a single submission.
  8. The respondent has not closed the window of an auto-triggered survey.

The following steps explain how to send variables through the widget:

  1. Configure widget to load on demand
  2. Create variables in your survey
  3. Trigger the widget with variables when an action takes place
  4. Use the variables in questions
  5. Tracking the variables in responses

Configure widget to load on demand
You have to set a configuration to stop widget from loading when the page loads.

window.sparrowConfig = {
triggerOnLoad: false

Setting triggerOnLoad   to false  will stop the widget from loading, on page load. By default, this is true.
In order to get the name and email, you might want to trigger the survey only when the users have logged in.
Setting  triggerOnLoad  to false would be useful in these kinds of use-cases.

Create variables in your survey
The variables that must be tracked through the widget should be created in the survey. To add variables in the survey, 

  1. Open your survey.
  2. In the Build section, click on the Global Variable icon on the left-side bar.
  3. Click on +Add a Custom Variable and add your variable names in the text field and click Save Variable.

In this example, we have added the name and email address as the variables in the survey.

Trigger the widget with variables when an action takes place
Once the user has logged in, you can trigger the widget and set the variables using the following code.

window.SparrowLauncher('popup', {
variables: {
name: "John Doe",
email: ""

In this manner, your survey will have access to the variables name and email address.

Use the variables in questions
Additionally, you can also use the variables in the questions to give a more personalized experience.

  • Configure the variable in the question. You can do this by clicking the dollar sign($) next to the question.

When a logged in user answers the widget, he will see his name.

Tracking the variables in responses
Once the user starts answering, a response entry will be created with the user details, name, and email.

In case you would like to remove the widget based on a specific user action, you can call the following code.