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 unique IDs into and out of the survey, along with response statuses such as terminate, over quota, and complete).
- The word "source" when used as a URL variable is not compatible with quotas in surveys. We suggest avoiding using the word source when creating survey quotas.
- pre-populate 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:
http://survey.alchemer.com/s3/1234567/my-survey
If you wanted to pass a variable with the value equal to the word 'value,' you can add the following to the survey link:
?variable=value
Your survey link would look as follows:
http://survey.alchemer.com/s3/1234567/my-survey?variable=value
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:
http://survey.alchemer.com/s3/1234567/my-survey?userid=121&name=bob
Operators
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
You can use Hidden Values to rename a URL variable for reporting purposes (e.g., a=32 becomes age=32).
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:
- Modify this default code by deleting the three x's 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.
The word "source" when used as a URL variable is not compatible with logic in surveys. We suggest avoiding using the word source when driving logic conditions.
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.
URL Variable Reporting
In Standard Reports, URL Variables 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.
URL Variables in Exports
Upon creation of a CSV/Excel Export select the option to Include URL Variables in order to include this data in your export. If you forgot to select this option when creating the report, it is also available under Customize Report > Settings.