URL Variables make for a quick method for pre-populating existing data into a survey. With a simple query added to the end of the survey link, data can be stored as part of each survey response. This gives you the ability to push information into the survey through your survey link to store for use within the survey and/or to use when reporting on the survey response.
You can use URL variables to:
- integrate with panel companies or other third parties (pass unqiue IDs into and out of the survey, along with response statuses such as terminate, overquota, and complete).
- prepopulate data in the survey that is either visible or invisible to the survey respondent (pass the name of a customer service representative or a ticket number into a survey).
- drive survey logic (show or hide pages and questions based on different variables).
- pass information between surveys (pass a unique identifier in order to connect responses to individuals across surveys).
- perform a unique function (only allow one response per value, go to the beginning of a response, or go to a specific page).
Constructing URL Variables
Take the following example survey link:
If you wanted to pass a variable with the value equal to the word 'value,' you can add the following to the survey link:
Your survey link would look as follows:
If you wanted to add a variable named 'userid' with a value of '121,' and also include a variable 'name' with a value of 'bob' your link would be constructed as follows:
The question mark, ampersand, and equals sign are operators used in the syntax of query strings/url variables.
- ? - The question mark identifies the beginning of the query string and must be placed at the end of the link, before the contents of the query string.
- & - The ampersand is used before each subsequent variable/value pair in the query string.
- =- The equals sign separates the variable from the value assigned to that variable
Best Practice Tip
When constructing URL Variables to use in surveys, we recommend using all lowercase letters for the variable name. This will give you the most reliable results for using URL Variables within surveys, as well as passing them out of surveys using actions like the Webhook and URL Redirect.
If you need to pass special characters via a URL variable, you may need to encode the special characters. Learn more about URL encoding.
Storing URL Variables for Later Use
URL variables are stored by default whenever they are detected. To confirm, click on a response on your Responses tab and go to the Details tab. Any URL variables that were present in the link for this response will be present. As you can see from the screen capture below this survey link was sent out with the below query that was then automatically stored.
Setup a Hidden Value
When you are you are using Hidden Values to capture URL variables, you will want to add these to the first page of the survey.
- Click the Add New Action link on the first page of the survey.
- Select Hidden Value from the list and enter a title for your Hidden Value. A good title is important, especially if you plan on including several Hidden Values in your survey. For example, if you plan on capturing respondents' first names, calling it First Name will be helpful later when you need to use it for pre-population or reporting purposes.
- Click the Select a Merge Code link below the Populate with the following field.
- Search for "url variable" in the available search field
- The URL Variable merge code will return in the search results; click Insert; the merge code will be inserted into the Populate with the following field:
- You will want to modify this default code by deleting the triple x and entering the name of your URL variable. The below merge code example would pull the value of the store variable from this query string: ?store=val
Sample Merge Code: [url("store")]
If the query string variable was STORE, the above merge code would still work properly as it ignores the case of the query string variable.
- When you are finished customizing the merge code, click Save Action.
Using URL Variables in Your Surveys
There are so many things you can do with URL variables in surveys it's nearly impossible to list them out. We have found that the best way to learn about URL variables is to see them in action; head over to our Using URL Variables in Your Surveys Tutorial to learn more!
Using URL Variables in Survey Logic
URL variables are available to in the logic builder throughout your survey under the First Party Data category.
- To set up logic using a URL variable, start by selecting URL Variable from the First Party Data options in the left-most column.
- In the text field that appears to the right, enter your URL variable name.
- Next, choose an operator and enter a value to complete the logic rule. This is one place where having stored the URL variable in a hidden value makes your life a little easier as you will not have to key the variable name when setting up logic.
URL Variable Reporting
In Standard Reports, URL Varibles can be added as a report element via the Insert Tool by selecting the URL, SSO, and Hidden Values option. The URL Variable reporting element will display as a pie chart with a corresponding table.
Learn more about this reporting element by visiting the expanded documentation.
In Legacy Summary Reports, URL Variables will report as an appendix element which is just a list of all possible values and the frequency for which each value was recorded.
If you have a set list of values that you plan to store in a URL variable, you may want to report on this as a pie chart or bar chart for a more visual representation. You'll need to set this up in advance of collecting data.
- To do so, create either a Radio Button or Checkbox question. Choose a Radio Button question if you wish to create a Pie Chart in your Reports and Checkbox question if you wish to create a Bar Chart in your reports.
- Add all possible URL variable values as options in your question. Make sure that the reporting values match exactly, including case, with the values that will be sent to your survey via the URL.
- On the Layout tab of the question in the Default Answer field click the Select a Merge Code below the field.
- Search for url variable within the provided search field and once URL Variable is returned, click the Insert option to insert it into the default answer field.
- Change the xxx to your url variable name and click Save Question.
- By default this question will display to your survey respondents. If you wish to hide it, enter sg-hide in the CSS Class Name field just below the Default Answer field.
- When you run a Standard Report you can now report on the question that is storing your URL Variable.
Adding URL Variables to Survey Links
Now that you have learned how to construct URL variables, it's time to add them to your survey links!
- Go to the Share tab and click on a survey link from the Email Campaigns and Source Tracking list. If you want to create a new link for this URL variable, you can do so by clicking Create A New Tracking Link.
- To add a URL variable to each link, go to the Advanced tab of the link editor. In the URL Variables field you will enter a variable and value pair like so: variable=value.
For example let's say we are creating links for each store and manager. We will start by specifying a variable called store and then add an equal sign (=) and the store value this link represents. We can add a second variable by adding an ampersand (&) and then specifying another variable and value pair. Then, we will repeat these steps for each tracking link we create.
Please note that you do not need to add the question mark at the beginning of the string, it's already built-in!
- Save your link and test as needed! URL Variables added to your links will be hidden from view (for respondents) when the link is shared.
Add URL Variables to an Email Campaign
You can also use these variables in an Email Campaign.
- Click the Share tab and select your campaign or make a new one.
- Once you have accessed the campaign, click the Settings tab and input your variables in the URL Variable field. The URL Variables field is located near the bottom of the Advanced Settings page.
- Make sure to Save Campaign Settings when you are finished.