Freeform Freeform for Craft

User Guides

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

  • 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

    TIP

    The field names/handles do not have to match the query parameter names, but we've done it that way for this example.

  • 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() }}
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
  • 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!
User Guide:

Check out our other guide for passing along other types of data to Freeform form fields.