You can track the page that the user was on before visiting the form page by adding a Hidden field to the form and at the Default value option choosing Insert variable… then Referring URL. However if you wish to track what site the user was on before arriving on your site (let’s call it the External Referrer) you will need a different method, and this is what this guide is about. Say they visit a couple of pages on your site before submitting the form, the above method would not show the External Referrer URL, it would show the last page they were visiting on your site. So to track the External Referrer we will add some code to save the referring URL the first time that the user visits any page on your site.
Add a Hidden element to the form.
In the Settings for it, give it a Label such as “External referrer” and on the Data tab turn on the Dynamic default value option and at the Parameter name field enter
Repeat this step for any other forms where you want to track the External Referrer URL.
Add the following code to the WordPress theme functions.php file (or create a plugin for it).
The referring URL will be empty in certain circumstances:
- The user types in your site URL directly, or visits from a bookmark
- If your site does not have an SSL certificate (the URL starts with http:// and not https://) then the referrering URL will be empty from users arriving from https:// sites, such as Google Search
- The referring URL is deliberately blanked out by redirectors
If the referring URL is determined to be empty, the code will set it to “Not set”.