How to track UTM parameters and gclid in Contact Form 7
Contact Form 7 is the most popular form plugin for WordPress, and it does one thing well: it sends you an email when someone fills in your form. What it does not tell you is where that person came from. Was it your Google Ads campaign, a search on Google, a post on Instagram or a link from a partner’s website? Without that, you cannot tell which of your marketing brings enquiries and which only costs money.
This guide shows two ways to get the source into every Contact Form 7 message: by hand, with hidden fields, and automatically, with a plugin.
What you want to know about each enquiry
Most of the answer is in the address of the page where the visitor arrived. A click on an ad usually lands on an address like this:
https://example.com/kitchens/?utm_source=google&utm_medium=cpc&utm_campaign=kitchens-spring&gclid=Cj0KCQ...
- utm_source, utm_medium and utm_campaign name the platform, the type of traffic and the campaign. You set them yourself in your ads, newsletters and posts.
- utm_term often carries the keyword of a search ad.
- gclid is added by Google Ads when auto-tagging is on. It identifies the click, and you need it to report sales back to Google Ads later.
Visitors from a normal Google search, from social networks or from other websites arrive without these parameters. For them, the only hint is the referrer: the website the browser came from.
Method 1: hidden fields in Contact Form 7
Contact Form 7 has a hidden field type, and a hidden field can take its value from the address of the page. Open your form under Contact → Contact Forms and add these lines anywhere in the form template:
[hidden utm_source default:get]
[hidden utm_medium default:get]
[hidden utm_campaign default:get]
[hidden utm_term default:get]
[hidden gclid default:get]
default:get tells Contact Form 7 to fill the field with the URL parameter of the same name. Then open the Mail tab and add the values to the message body:
Source: [utm_source] / [utm_medium]
Campaign: [utm_campaign]
Keyword: [utm_term]
Google click ID: [gclid]
Send a test through an address such as https://example.com/contact/?utm_source=test&utm_campaign=check, and the values appear in the email.
Where this method falls short
The hidden fields only see the address of the page that holds the form. Most visitors do not send a form on the page where they arrive. They land on a service page from your ad, read two more pages and then open the contact page, and by then the parameters are gone from the address.
You can keep them with a few lines of JavaScript that remember the parameters for the rest of the visit and put them into the hidden fields. Add the script to your theme or with a code snippets plugin, and remove default:get from the fields above:
document.addEventListener( 'DOMContentLoaded', function () {
var keys = [ 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'gclid' ];
var params = new URLSearchParams( window.location.search );
keys.forEach( function ( key ) {
if ( params.get( key ) ) {
sessionStorage.setItem( key, params.get( key ) );
}
var value = sessionStorage.getItem( key );
document.querySelectorAll( 'input[name="' + key + '"]' ).forEach( function ( field ) {
if ( value ) {
field.value = value;
}
} );
} );
} );
This covers a single visit. It still leaves some gaps:
- Returning visitors. Someone who clicks your ad today and writes to you next week arrives without parameters the second time.
sessionStorageis empty again, so the ad gets no credit. - Visitors without UTM parameters. Organic search, social networks and links from other websites need the referrer, which the script above does not read.
- No history. Contact Form 7 does not store messages; they exist only in your inbox. To count leads per campaign you need a plugin such as Flamingo and a spreadsheet.
- Cookie consent. In the EU, storing campaign data in the browser for marketing usually needs the visitor’s consent, so the script has to wait for your cookie banner.
Method 2: automatic, with Dealroot
Dealroot is a free plugin that does all of this without changing your forms. It remembers how each visitor found your site, from the first visit to the enquiry, and saves every Contact Form 7 submission as a lead with its source.
- In WordPress, go to Plugins → Add Plugin, search for Dealroot, install and activate it.
- Open Leads → Forms and click Scan site. Your Contact Form 7 forms are listed and ticked.
- Send a test through
https://your-site.com/?utm_source=test&utm_medium=cpcand open Leads → All leads.
Each lead then shows the channel (paid search, organic search, social, email, referral and more), the source, campaign, keyword, click ID, landing page and the pages the person saw before writing. Visitors without UTM parameters are sorted by their referrer, so a visitor from a Google search counts as organic search and one from a partner’s website as a referral.
The source in the Contact Form 7 email
To see the source in the notification email too, turn on Leads → Settings → Forms → Source in your forms. The channel, source, campaign and landing page are then added below the notification emails of all your forms; the email to the visitor stays as it is. If you prefer to place it yourself, Contact Form 7 accepts these tags in the Mail tab:
[_dealroot_attribution]
[_dealroot_channel]
[_dealroot_source]
[_dealroot_campaign]
The source in your CRM
If Contact Form 7 sends its data on to a CRM, for example with an add-on or through Zapier, keep the hidden fields from method 1, without default:get. Dealroot fills fields named utm_source, utm_medium, utm_campaign, utm_term, gclid or dealroot_channel on the server when the form is sent, also when the visitor arrived days earlier on another page.
Which method should you use?
Hidden fields are enough if your forms sit on the landing pages of your ads and you only need the campaign in the email. As soon as visitors browse before they write, come back later or find you without an ad, a plugin that follows the whole visit gives you numbers you can trust. Dealroot also sorts the leads into a report, so you can see which campaign brought how many enquiries and, once you mark them as won, how much revenue.
