Skip to main content
Analytics and BI

How to Track the Origin of Leads with UTMs and Scripts

By No Comments4 min read
utm tracking script: image of a team of professionals looking at a computer screen
Know exactly where your most qualified leads come from!

Find out which media channel (Google Ads or Facebook Ads), which campaign and even which ad or keyword generate the best leads. With the URL parameters, the so-called UTMs, tracked correctly, it will be possible to have this control and enable precise optimizations.

Let's look at a common problem

Suppose your company focuses on lead generation and chooses to use an external form on your website. A major advantage of using external forms, such as Typeform, is that it's easy to maintain and edit the fields.

It's also beautiful, has the latest features and integrates with various other tools, such as Google Sheets and Pipedrive.

However, when we use links or their embedded codes, we lose the UTMs that were in the URL of our pages. This is because the user is taken to another domain, as in this example:

The user arrives at this page via a Google ad:

When you click on the button, you are taken to a link on the Typeform domain or an embed code is triggered. This is an example of the Typeform link:

At this point, the UTMs disappear. So we can't track which channel or campaign the leads are coming from.

banner advertising a free e-book on optimizing Google Ads and Meta Ads campaigns

Script solution

Para não perder essas UTMs, é necessário incluir um código JavaScript ao final da página, como um elemento mesmo no <body>. Apresentamos o script a seguir, para que possa ser utilizado nessa solução:

buttons = document.getElementsByClassName('typeform-button')
const queryString =;
buttons.forEach(button => button.setAttribute('href', button.getAttribute('href') + queryString))
typeform_buttons = document.getElementsByClassName('typeform-share')
newQueryString = queryString.replaceAll('?', '&')
typeform_buttons.forEach(button => button.setAttribute('href', button.getAttribute('href') + newQueryString))

If you have a website built in WordPress, just add it directly in the Page Editor:

The first part of the code identifies all the buttons on the page that contain the "typeform-button" class and adds the UTMs that are in the page URL to their links. Therefore, the buttons need to be configured with this Class Name:

In the case of Typeform, you also need to create hidden fields with the UTMs you want to track. This way, Typeform itself will store the values each time you fill them in:

utm google tracking 1

utm google 2 tracking

Remember that in order to track the UTMs of Google and Facebook campaigns, they need to be configured in the account:

Example for Facebook Ads (we usually include it at the ad level):

Example for Google Ads (we usually include it at the ad group level):

Please note: The tracking templates used by the platforms will be those at the most granular level, i.e. if there is a tracking template at account level and another at ad group level, the one at ad group level will be considered.

advertising banner

The big gain for advertisers who work with lead generation is to be able to understand exactly where the qualified leads are coming from!

You can even understand which ad they are coming from. By sending this data to a Google Sheets spreadsheet, you can generate reports and get great insights to improve your Google and Facebook campaigns.

In this example, we track a lot of information. See what Typeform stores:

utm google 3 tracking

Here, we have the source (google), the media (cpc), the campaign and ad group IDs, the network (g = google), the device (m = mobile, c = computer), the type of match (b = broad) and the keyword that generated the lead (+facebook + ads = broad modified "google ads").

Check out other articles from the Pareto Blog for paid media optimization.

Did you like this article?

0 / 5 Results 0 Votes 0

Your page rank:


Author: Pareto - Learn more about the world of AIs and Digital Marketing. Access our content collection now!