Storing URL Tracking Parameters
In the event you'd like to store URL tracking parameters (e.g. utm_source
, utm_medium
, etc) in your form submissions, this can easily be done. Just follow the steps below:
Instructions
1
-
Open up an existing form in Freeform. For the purpose of this example, let's assume it's called
Contact
. -
Create and add 3 new Hidden fields to your form layout with the handles of:
utm_campaign
utm_source
utm_medium
The field names/handles do not have to match the query parameter names, but we've done it that way for this example.
2
- In the regular template where you are loading the form, you'll need to add the values parameter and grab the values from the URL with
craft.app.request.getQueryParam('')
:{{ freeform.form("myFormHandle", {
fields: {
"utm_campaign": {
value: craft.app.request.getQueryParam('utm_campaign'),
},
"utm_source": {
value: craft.app.request.getQueryParam('utm_source'),
},
"utm_medium": {
value: craft.app.request.getQueryParam('utm_medium'),
},
},
}).render() }} - Assuming your URL looks something like the following, Freeform will then grab those values and plug them into the corresponding hidden fields:
https://mysite.net/contact?utm_campaign=my_campaign&utm_source=google_jobs_apply&utm_medium=organic
Finished!