This guide shows you how to track UTM parameters in Salesforce Web-to-Lead forms.

Salesforce Web-to-Lead forms are great at creating leads in Salesforce for each submission. But they don’t tell you where your leads come from.

  • What websites referred them?
  • Which Adwords keyword brought them to your site?
  • Which Facebook ad campaign converted them?

Overview of tracking UTM parameters in Salesforce Web-to-Lead forms

In this article we’re going to explain how you can track UTM parameters in Salesforce and have a section like this for each of your Leads:

Example of tracking UTM parameters in Salesforce Web-to-Lead forms

Example of tracking UTM parameters in Salesforce Web-to-Lead forms

You’ll also be able to build Salesforce dashboards with UTM information.
As a result, you’ll see which campaigns generated the most sales:

Salesforce report breaking out the number of qualified leads by Adwords campaign

Salesforce report breaking out the number of qualified leads by Adwords campaign

Let’s say this is your Web-to-Lead form:

This is just an example – yours will look differently.

To bring UTM fields to Salesforce, you need to do three things:

  1. Add new fields to Salesforce that will store these UTM fields.
  2. Add these fields to your Web-to-Lead forms (and make them hidden).
  3. Add some JavaScript code to your page. This code will grab the UTM parameters and put them in the hidden fields.

Step 1 – Add new fields to Salesforce

First, you need to add five new custom fields to Salesforce: UTM Source, UTM Medium, UTM Term, UTM Campaign, UTM Content.

The JavaScript code in step 3 will fill in these fields with the appropriate values.

To create these fields, go to Salesforce and click Setup. This will open a search field. Search for the word “Lead” and select Fields from the results.

Salesforce Lead fields search screenshot

Salesforce Lead fields search screenshot

Then scroll down to Lead Custom Fields & Relationships and click New:

Custom Lead fields in Salesforce

Custom Lead fields in Salesforce

Choose field type Text:

Salesforce - Choose new custom field type

Salesforce – Choose new custom field type

Set Field label to “UTM Source”, and Length to 255 (Salesforce fills in Field Name for you):

Set UTM source fields parameters in Salesforce

Set UTM source fields parameters in Salesforce

Click Next, and then Save & New.

Repeat this process four more times, creating the following fields:

  • UTM Medium
  • UTM Term
  • UTM Campaign
  • UTM Content

If you also want to know the source/medium/term/etc of each opportunity or account, do the following:

  1. Create the same fields for the Opportunity and/or Account object. You can do this in Setup -> Opportunities – Fields and Setup – Accounts – Fields.
  2. Go to Setup – Lead – Fields again, and click the button Map Lead Fields:
Salesforce - Map UTM fields from Lead to other objects

Salesforce – Map UTM fields from Lead to other objects

On this page, you will be able to map the Lead fields to the corresponding Account/Opportunity fields. This will add the UTM fields to the Account and/or Opportunity objects.

Step 2 – Add new fields to the forms

In step 1, you created custom fields to store UTM parameters in Salesforce. Now we’re going to add the same fields to your Web-to-Lead forms.

Generate the code for new fields in Salesforce

To do this, go to Salesforce – Setup – Web-to-Lead, and click “Create Web-to-Lead Form”:

Salesforce Web-to-lead form create button

Salesforce Web-to-lead form create button

Find the UTM fields you just created in the “Available fields” section. Then, move them to “Selected Fields” using the arrow buttons between sections.

Click “Generate” and Salesforce will create a new Web-to-Lead form for you:

Sample Salesforce Web-to-Lead form

Sample Salesforce Web-to-Lead form

Don’t worry, you don’t need to replace your existing forms with this new form.

You just need to:
a) extract the UTM fields from this new form, and
b) put them inside the existing Web-to-lead forms on your website.

In the form just generated, you should see the following block of code:

Put the code for the new fields in your form(s)

Take the input name (e.g. 00N5800000Bew3F) and add it to this template:

In this example, the input name is 00N5800000Bew3F, but in your form it will be different.

 

Repeat this process for all five fields, and as a result. Your end result should be a block of code like this:

In this example, the input name is 00N5800000Bew3F, but in your form, it will be different.

 

Then put this block of code in your Web-to-Lead form, just above the closing </form> tag:

 

Congratulations! You have completed the most time-consuming steps, 1 & 2. Only one more step to go!

At this point, you already have UTM fields in both Salesforce and your forms.

Plus, you don’t need to worry about synchronizing these fields because it happens automatically.
There’s just one missing piece. You need to insert the code that will populate these fields with actual UTM values.

Step 3 – Populate hidden fields with values (using JavaScript)

As a final step, put this JavaScript code somewhere on your page:

 

You can put it inside a Google Tag Manager tag if you’d like.

Congratulations! You have completed the most time-consuming steps, 1 & 2. Only one more step to go!
By now, you already have UTM fields both in Salesforce and your forms.
Plus, these fields get automatically synchronized. So you don’t need to worry about that.
There’s just one missing piece left. You need to insert the code that will populate these fields with actual UTM values.

Bonus Step 4

If you’ve followed this guide and and implemented, you’re already ahead of most marketers out there.

If you want to go one step further, you can implement GA Connector – a tool that allows you to find out even more about your clients.

You see, tracking only UTM parameters has its limitations:

  • It doesn’t work when users leave your page and then return from a bookmark or by typing your URL. UTM information is lost for these leads (unless you use a tool like GA Connector).
  • It also doesn’t work if you have a multi-page website: if a user lands on one of your pages, but the actual form submission happens on another page, the UTM information is lost.
  • This approach only tells you which channel converted the lead. But sometimes it takes more than one visit to seal the deal and thus there could be more than one channel. You user could have found you through Google but came back through Facebook remarketing. Does it make sense to attribute the conversion only to remarketing?
  • This approach doesn’t let you track organic Google searches. You can’t put UTM parameters there. Same with referrals that you don’t control (not everyone wants to put UTM parameters in their links).
  • This method doesn’t give you other important information about your customers: which device/browser they are using, their referrer,  where are they located etc. These are all important clues that can be valuable during the sales process and for analytics.

GA Connector solves all those issues. It allows you to trace the user’s entire path, no matter which page they landed on and when they submitted the form.

GA Connector remembers the initial channel, as well as the last channel, plus other useful information about this visitor.

Here is a section you will see for each of your Salesforce leads after implementing GA Connector:

GA Connector: Tracking website visitor information inside Google Analytics

GA Connector: Tracking website visitor information inside Salesforce

Sign up for GA Connector here.