How to Add UTM and Referrer Information to Lead Forms?

Every lead is valuable for at least two reasons:

  1. For being a lead that moves your business (duh)
  2. Identifying your most valuable channels

So how can you find out where a lead came from?

One way is to have them answer “How did you find us?”. But many people don’t answer it, either because they don’t want to or they forget where they found you first.

You can also get this information by configuring goals/conversions in your favorite analytics tool, let’s say Google Analytics. Your reports then tell you where the most conversions came from.

However, there’s one drawback of this approach. You get this information in aggregate. You can’t look at a subscriber and tell where they came from.

Let’s discuss a simple technique to capture UTM and Referrer information along with your lead generation forms. I covered a basic version of this in another post. The technique discussed here is simpler and more powerful than the old one.

I might be duplicating some parts from the old post, but it’s better to have everything in one place.

Let’s get started.

1. Configure your CRM or email service provider

Since you’ll be collecting extra information about your leads/subscribers, you need to tell your CRM or email service provider to accept the new fields. Here I’m using Mailchimp as an example:

Mailchimp UTM and Referrer Fields
Mailchimp UTM and Referrer Fields

How to do this for Mailchimp?

  1. Go to your subscribers list. Select List fields and *|MERGE|* tags from Settings.
  2. Click Add A Field, select text. Add “UTM_SOURCE” for Field Label and “USOURCE” for Put this tag in your content.
  3. Make sure Required? and Visible? are unchecked.
  4. Repeat the same for each of the remaining UTM parameters. i.e. UMEDIUM, UCAMPAIGN, UCONTENT, UTERM
  5. Also repeat it for IREFERRER, LREFERRER, ILANDPAGE and VISITS as shown in the above image.
  6. Click Save Changes.

2. Add UTM Form script to your website

Just add this before the closing </body> tag at the bottom of every page on your website.

<script src="//" async></script>

It’s that simple. You could either make a change directly to your website or use Google Tag Manager for this.

NOTE: The script will be loaded from Terminus CDN and I’ll pick up the tab for your traffic. However, I don’t provide any guarantee that this will always be available. To be safe, you could host it yourself.

3. See UTM and Referrer information for each subscriber

So what information will you be able to capture about your leads/subscribers?

  • 5 UTM parameters – Any UTM parameters in the URL that a visitor used to come to your website will be added to the form
  • Initial Referrer – The webpage where the visitor came from for the first time
  • Last Referrer – The webpage where the visitor came from most recently
  • Initial Landing page – URL of the page on your website where the visitor landed the very first time
  • Number of visits – The number of times the visitor came to your website before filling your form

All of this information is saved in a cookie. So it doesn’t matter if a visitor navigates to different pages on your website before filling your form. This information is added to the lead form in all the cases.

How does a subscriber look like in Mailchimp?

Subscriber with UTM and Referrer information
Subscriber with UTM and Referrer information

As you can see, this subscriber initially came to Terminus from Google (Initial Referrer) and then later from Quora by clicking on a UTM tagged URL. I also know the exact question (Last Referrer) they saw on Quora. The visitor converted on their second visit (Visits). Additionally, I know they initially landed on a blog post (Landing Page) on Terminus.

So what could have happened?

The visitor was probably searching for some UTM related information on Google and landed on Terminus. They then went to Quora looking for similar information. They again found Terminus mentioned there, came back to Terminus blog and converted. Now I know that the combination of SEO and answering Quora questions is working. And I know this without getting lost in multi-attribution reports.

I’m sure you can use this information in various innovative ways and get some unique insights about your leads.

Since this information is attached to each lead/subscriber, you can move it between different CRMs or email service providers. It’s not tied to any analytics tool. You can also export it to any spreadsheet and analyze it.

NOTE: If you want to take your UTM tracking to the next level, sign up our FREE email course:  Learn the Best Practices for Building UTM Tracking URLs.

What if I have some advanced needs?

You may want to change the default values of UTM Form script if your setup is a bit complex. You can easily configure it for the most common cases.

1. Track visitors across all subdomains

If you have more than one subdomain and you want to track the visitor information across all of them, you can change the code as follows:

<script type="text/javascript" charset="utf-8">
  var _uf = _uf || {};
  _uf.domain = "";

<script src="//" async></script>

Change to your domain name.

2. Change the fields names

If you don’t like the default form field values (i.e. USOURCE, UCAMPAIGN, IREFERRER, etc.), you can specify them as well. Besides these, there are a bunch of other configuration options that can help with your particular needs as well.

<script type="text/javascript" charset="utf-8">
 var _uf = _uf || {};
 _uf.domain = "";

_uf.utm_source_field = "YOUR_SOURCE_FIELD"; // Default 'USOURCE'
 _uf.utm_medium_field = "YOUR_MEDIUM_FIELD"; // Default 'UMEDIUM'
 _uf.utm_campaign_field = "YOUR_CAMPAIGN_FIELD"; // Default 'UCAMPAIGN'
 _uf.utm_content_field = "YOUR_CONTENT_FIELD"; // Default 'UCONTENT'
 _uf.utm_term_field = "YOUR_TERM_FIELD"; // Default 'UTERM'

_uf.initial_referrer_field = "YOUR_INITIAL_REFERRER_FIELD"; // Default 'IREFERRER'
 _uf.last_referrer_field = "YOUR_LAST_REFERRER_FIELD"; // Default 'LREFERRER'
 _uf.initial_landing_page_field = "YOUR_INITIAL_LANDING_PAGE_FIELD"; // Default 'ILANDPAGE'
 _uf.visits_field = "YOUR_VISITS_FIELD"; // Default 'VISITS'
 _uf.additional_params_map = {
 affiliate: "AFFILIATE"
 }; // Maps affiliate parameter to AFFILIATE form field
 _uf.sessionLength = 2; // In hours. Default is 1 hour
 _uf.add_to_form = "first"; // 'none', 'all', 'first'. Default is 'all'
 _uf.form_query_selector = 'form[action="/sign_up"]'; // custom form selector. Default is 'form', to select any form.

<script src="//" async></script>

3. Super customization

Do you want to look at the code and play with it? Awesome. The code is open sourced at Github. It also has some more detailed information about what happens when you add this script.

If you can improve it, just send a pull request and I’ll be happy to merge it if looks good.

What now?

You can now capture a lot of valuable information about your visitors, especially where they are coming from. Get the power of expensive analytics tools without the expensive part.

Sometimes looking at each person individually gives you much better feel about them, what they are looking for, how they found your site, etc. It’s much better than treating them as a point on your chart.

FREE UTM Best Practices Email Course

If you are like me, you probably want to take your UTM tracking to the next level. Learn the Best Practices for Building UTM Tracking URLs by signing up for this super actionable email course. You’ll love your analytics reports after you implement these tips.

Click here to access Free UTM Email Course

  • That’s awesome Puru! Thanks for sharing 🙂

  • Tommy


    Having a tough time getting the parameters to track after signing up on my site

    Any thoughts? Is the popup a factor?


    • Hi Tommy,

      Looks like there are two quotes in the “src” value.

      This is what I see:

      Can you please try removing the duplicate quotes and see if it works?


      • Tommy

        Ahh got it! Looks like something wasn’t copying correctly. Thanks for your help! Great tool

  • Sandro Wiggers

    Really awesome! Thanks for sharing! @medius:disqus

    • Thanks Sandro. I’m glad you like it.

      • Sandro Wiggers

        Hey Puru! This will track also the “organic” sources, or the UTM must be declared as custom URL? Regards!

        • Hi Sandro,

          This will track any source. If UTM is present, it will fill the appropriate “utm_” fields. And it will always fill “Initial referrer” which can include organic sources, like, or any another referrer etc.

          Does that answer your question?

          – Puru

          • Sandro Wiggers

            I’ve already grabbed the code from github, now I’m working on my site and MailChimp updates.
            I’ll come back to tell you the results.
            Thank you for the answers!

  • That’s not working on my site. Optins completed, all empty values.
    Any idea of what could be occurring?

    • Sorry Franck, it’s hard to tell without actually looking deeper into it. I could take quick look, but can’t promise anything.

  • this is brilliant! Am going to try install now and have it set up with Infusionsoft. Thanks Puru, really appreciated. Hopefully I can get it working successfully.

    • I’m glad you find it useful, Ben. Hope it works for you. Let me know if you have any questions.

      • Think I have it, so just to clarify; in my CRM I’ve set up a custom field, which has the name & database name of USOURCE

        then in my form I have added a hidden field with the name and label of the field as USOURCE but the value as blank.

        So will the script add the value of USOURCE into the blank field for me?


        • You only need to add the custom field in your CRM. The script will add the hidden fields in the form along with their values.

        • rick

          Did you get this script to work on infusionsoft?

          • No haven’t managed to get it working yet. Not sure what I have set up incorrectly. The script is firing on all pages using Google Tag Manager. Custom Fields are set up in Infusionsoft. I’m using a form that integrates with Infusionsoft, will try it with Leadpages to see if the form is the issue.

          • rick

            Interesting. Leadpages should work just fine. We are using the classic web forms in infusionsoft and had a hard time getting it working. I tried iTrackers javascript and that one seems to work pretty well so far. Still need to do more testing. Would appreciate an update if you somehow get it to work with IFS.

          • Do you know what part is not working? Are you seeing fields populated in the form when you load the page?

  • rick

    Hi Peru, Will this work with Google Adwords Auto-tagging? I can use UTM’s on other mediums, but will auto tagging be picked up in the hidden fields even though Adwords uses Gclid? Look forward to your response!

    • Hi Rick,

      Unfortunately, it won’t work exactly the same with gclid since only Google knows what its value means. The referrer and landing pages information will still be picked up, but not UTM values (since there aren’t any with auto-tagging).

      Hope this helps,

      • rick

        Thanks for the swift reply, Puru. Appreciate all the feedback you provide on your website. I currently use UTM’s to track my FB campaigns, as well as email. What would you recommend I do for Adwords? Should I stop auto-tagging and use UTMs? Is that the best route to get that information into our CRM? Do you have any insight on this matter? Look forward to your response.

        • Hi Rick,

          It depends on how much you use Adwords. For heavy usage, I would recommend keeping the auto-tagging on since it can get very cumbersome and error prone to do tagging yourself. Additionally, the deep integration between Adwords and Google Analytics probably is useful to you. But if having all the data in CRM is much more important than the richness of your Google Analytics reports, then you could definitely consider manual tagging.

          However, to start with, you could just see what information you get by using the technique mentioned in this post for your FB and email campaigns. Once your setup is working correctly, you will know if the information you are getting about your leads is valuable to you or not. Sometimes looking at your own data gives you a much better idea of what to do next. If it still makes sense, then you can consider switching to manual tagging for Adwords.

          – Puru

  • Lucas Sanchez

    Great post and hack. Thanks Puru. I have one question: If a subscriber fills multiple forms (adwords campaign first, a lead magnet one week later and so on). Custom fields will be replaced?

    • Hi Lucas,

      If on subsequent visits they came through a different link with UTM parameters, then the UTM values will be updated. If they just came directly or through some link that does not have UTM tags, the previous values will be populated. The initial referrer and initial landing page will not change in either case. The visit count will be always be updated.

      Does that answer your question?

      • Lucas Sanchez

        Yes Puru, thanks for your quick reply.

  • Melissa Parker

    This article has been so helpful. My company uses Salesforce and have decided to add an UTM tracking code in our Web-to-Lead form. I am VERY new to UTM functionality and have a pretty simple question that you could answer quickly??

    I have created three Custom Lead Fields to capture, Campaign Source, Campaign Medium, and Campaign Name. I have added these custom fields to the web-lead-form and passed to along to our gal in IT who manages the few websites we have. I guess my question is, do I need to insert the UTM code in our web-to-lead form? How do I accomplish this? I’m assuming she will need to HIDE these fields, but how do I allow the UTM to capture what I need and sparse them in each field.

    Basically I need to report on were our Leads originally came from (i.e email campaign, ad, facebook, etc.) Your article is very informative and I’m still trying to wrap my head around this. Thanks a bunch!

    • Hi Melissa,

      The only thing that you need to configure in Salesforce is to allow the fields USOURCE, UMEDIUM, UCAMPAIGN, etc. to be submitted by the form. Once you include the script mentioned in this post, it will automatically populate your form with hidden fields and put the right values in them. So the only thing that you need to as your IT person is to add the script, i.e.

      var _uf = _uf || {};
      _uf.domain = “”;

      Be sure to change the domain name from “” to your website domain. If everything goes well, this should work.

      Hope this helps.

      • Melissa Parker

        Thanks, Puru. Can I use the custom fields I have already created rather than USOURCE, UMEDIUM, UCAMPAIGN to map? And, can I just map those three fields only?

        • Yes, you can. If you follow the steps in “2. Change the fields names”, you can use your own field names and the form will be populated with those.

          • Melissa Parker


            We are having an issue with pulling in the UTM and parsing them into each field. Can you take a look at the code and let me know if there is something we are missing?



          • Melissa Parker

            in addition this is the utm string we are trying to capture and parse:


          • Hi Melissa,

            It’s difficult to know what’s happening on your website just by looking at this code. Can you please let me know the website address and I’ll try to take a look?

            You can email me at if you would rather not mention it here.


  • Vigasan

    The hidden fields are not being added to my form. This is the code for the form:


    Could it be because I don’t have a VALUE attribute but a PLACEHOLDER one instead?

    This is the bottom of my index.html file:

    var _uf = _uf || {};
    _uf.domain = “.MYWEBSITE.CO”;

    • Hi Vigasan,

      It should work as is. Are there any other javascript errors on your site? If you open developer console in your browser and type UtmForm.utmCookie.lastReferrer(), does it give you anything?


      • Vigasan

        Yes the cookie is saved and it shows the value “Direct”.

        Also, my website has an htaccess file that redirects traffic so if anyone visits the non www version of the site, it redirects them to the www version. For _uf.domain would I have to put in http://WWW..MYWEBSITE.CO?

        • If you use “.MYWEBSITE.CO”, it should work for all subdomains. So the redirect should not matter as long as your final webpage has the script.

          Since the cookie is saved, I’m not sure why it’s not adding the fields. Can you also try UtmForm.addAllFields() in the console and check if the fields got added?

          • Vigasan

            I get “undefined”

          • That’s fine since it won’t return anything. Were you able to see any fields added? You’ll need to inspect the form element and not just view the source.

          • Vigasan

            Hmm what do you know, all the fields are there! For some reason they aren’t showing up in my Mailchimp lists. I’ve added the fields to Mailchimp though, they just aren’t being populated.

          • Not sure how to fix that though. You might want to play around with the mailchimp settings and test it out. Make sure the field names match.

          • Vigasan

            Hello Puru, my form does not lead to a new page and although I see the new fields when inspecting element, they are not being posted. When I try to pull out the value using $_POST, they appear to be blank so nothing was posted.

          • Are you able to see the values in the hidden field? If yes, then there must be something unusual with your form, because those are just standard HTML fields. The job of the script is done at this point and it’s all up to your form and the underlying service (mailchimp).

          • Vigasan

            I should have replied earlier but I figured it out. This was some work done for a client and the person before me had added javascript that caught the submit and only submitted email. Didn’t even see it since it was minimized. Thanks for this!

  • Hi Puru,

    Thanks so much for this info. My main goal is to just obtain the initial referrer info (We use Adwords a lot, but people don’t always convert on their first visit) Your script looks perfect, in that it’ll be able to tell us if people came from Adwords originally.

    My only question is – Could you explain in a little more detail what you mean by hosting the script myself? I don’t particularly like the idea of you paying for my traffic (nor the script disappearing if you ended up needing to take it down, of course). I’d like to host this script myself so I can always have it, but I’m not sure exactly what you mean by that. Any details you could provide would be greatly appreciated!

    • terminusapp

      Hi Kyle,

      If you would like to host the script yourself, you can download it from and put it on your server. Let’s say the URL of the script is

      You can then include it in your HTML pages as

      This way the script is served from your own servers and it will always be available as long as your website is working.

      Hope this helps.

  • Neil

    Hi Puru,

    Thanks for the awesome guide, works like charm.

    Do you have a cosmetic workaround for the URLs to store them in decoded format, so instead of https%3A// the script would return ?

    • Hi Neil,

      I didn’t try hard to make it work without the decoded format because it didn’t bother me. But if you would like, you can use “unescape” in Javascript on that value to get what you want. You could either change the source code of the script directly or implement a workaround on your website for any values you would like to fix.


  • Brad Hemze

    I’m working to integrate this with a 3rd party online form building tool. I’m using the tool created embedded HTML version of the form on my page. The script is working to capture the UTM parameters from the URL to hidden fields. But the values don’t post with the form. My guess: the field names don’t match because the form tool uses its own custom nomenclature to relate field names to database field names. So I’m trying the custom field names script addition and mapping the form tool’s field id to UTM names. Still not getting the values posted. I’m going to discuss with the Form Tool’s support. But I’m wondering if you had any experience or insight into using um_form scripts with a form builder generated HTML?

    • Hi Brad,

      Since there are so many different kinds of form builder tools, it’s difficult to predict what could go wrong. Some forms do need custom configuration to make it work with this script. It’s mostly because of their own typical behavior.

      The only requirement of this UTM script is that your form should be able to accept the values and it works with most forms without any problems.

  • czydrm1

    Great find! It all seems very simple but can I also pass the utm_placement info as well?

  • Hi Olivia,

    Actually they do appear. Try visiting your webpage with some UTM parameters, e.g.

    You’ll see that the UTM values are properly added. Any UTM values are only added if there was a visit to your website with those parameters by a visitor.

    Hope this helps.

    • Olivia Helling

      Ah, I see. Thanks so much!

  • Bruno Reis

    This post helped me a lot!

    Just one question: we already have the name of our subscriber, and we want to have this information in the UTM code in order to already have the field completed when our subscriber wants to fill it. How can I do that?

    • Hi Bruno,

      I’m not entirely sure what you mean. Do you mean you want to pre-populate the name field for your existing subscriber on a form?

      • Bruno Reis

        Sorry for my English!
        Yes, thats exactly what I want!

        • Unfortunately, the script currently doesn’t handle that case. You can start with the source code (URL in the blog post) and modify it as per your needs.

          I assume it’s going to be a visible field that the subscriber can edit. Since visible fields are very specific to a particular form (because of style and form structure), it’s not easy to make it generic for all use cases. So you are in the best position to change the script that matches your exact needs.

  • Hi Puru,

    I have a bit of a sticky problem that has taken me ages to get to the bottom of, but I think I finally have.

    I think It all comes down to the fact that there are no default values put in page for parameters your script couldn’t get hold of.

    For instance, if someone gets to my site using a link with a UTM value in for the campaign, then I would see this in the page:

    If there is no UTM value, then nothing is in the page, rather than something like this:

    I guess that isn’t usually a problem, but I have the following set-up:

    I’m using WordPress with Contact Form 7, which is extended with Contact Form 7 MailChimp Extension talking to MailChimp via their API.

    I use the extension to pluck items out of the form that can be passed into MailChimp. The problem is, if an item isn’t in the form (like when there is no Campaign value) then the submit fails. I assume because it’s trying to submit a null value or some such. The problem would be solved if all parameters were added to the page with default values if a ‘real’ value can’t be found.

    Just wondering what your thoughts were on this?

    • Hi Rob,

      I see what you mean. Since there is no universally acceptable default value for UTM, it’s a bit difficult to set some value and not mess up the analytics. Since UTMs are optional, especially utm_content and utm_term, I feel that a form submit should still work even if there is no value.

      Just to give you an example, a lot of forms on the web generally work even when there is no value entered by a visitor, say, a phone number is optional. So extending the same concept to UTM parameters should also be possible.

      The best way would be for the extension to not be so strict about parsing the values. Do you mind telling me what extension are you using? I’m curious if there is any other workaround for it.


      • Hi Puru,

        Thanks for the reply.

        I’ve got a WordPress install and I’m using Contact Form 7 for the form. I then installed a plugin called Contact Form 7 MailChimp Extension by Renzo Johnson that talks to Mailchimp via its API.

        The extension can pull parameters out of the form to give to MailChimp, but if any are missing, then it just gets stuck (the person filling in the form just sees a spinner and the page doesn’t re-direct to my Thank You page).

        As a bit of background, I have set up CF7 to send a 2 emails on a form submission. The first sends a mail to the person who filled in the form for a follow-up. The second mail is sent to a CRM system we use (Pipedrive). Pipedrive has an ’email API’ where you can email it new subscribers. You just format the mail using JASON. You just pad out the JASON with the parameters out of the form to get the values in the CRM (Name, email etc). We also send a copy of that JASON mail to ourselves too (so we know someone has signed up). This is how we worked out that missing parameters aren’t handled very well by CF7.

        In the mail that’s generated, we can put in the collected data, for example, the UCAMPAIGN. You add it to the mail using the square brackets, e.g. putting this in the mail [UCAMPAIGN] would add whatever your code got as the Campaign value, but when it’s missing, you just get “[UCAMPAIGN]” as a text string rather than nothing or a default value. All this is CF7’s functionality I assume. We’re guessing that when the extension sees a text string with the sqare brackets in, it freaks out. Just a guess..

        We were wondering if there was a way your code to deal with missing parameters somehow. Either that or we get in touch with the extension builder and see what his code could do..?

        I tried looking at the extension’s code, but it’s all a bit much for me. My hope was that I could spot an easy fix and tell Renzo. No hope there though, I’m no WP/PHP coder. My coding ability is still at ZX Spectrum Sinclair BASIC I’m afraid!!

        I hope all that makes sense!

        • Thinking aloud here, would this cause a problem?

          If your code had an option in it to “always include inputs on page”. When enabled, all inputs are included on the page, even if you could not determin the value. When you can’t find a value, rather than setting a default (like I originally suggested) have no value, ie,

          Just a thought. I’m not sure whether that would fix my particular problem or even if it did, whether it would cause others. I was prompted to think of this due to a comment you made; “a lot of forms on the web generally work even when there is no value entered by a visitor”. This is true, but the is still present in the page, it’s just that it had no value (rather than not present at all). That’s why I was wondering whether the above hack would work..?

          • Hi Rob,

            You could definitely test that by adding the above HTML using browser developer tools and then submitting the form.

            However, since most services are capable of handling if no value is returned for a parameter, I still think the extension should handle it the way a direct Mailchimp form would do. My forms submit directly to Mailchimp and I haven’t seen such issues. Even other CRMs don’t seem to have this issue when I worked with a few people about this script.

            So I would recommend getting in touch with Renzo Johnson and see if it’s possible to handle this case in the extension as well. It would definitely prevent any other unexpected behaviors if it’s done the right way.


          • Azam

            I’m using the same setup with Contact Form 7 plus Mailchimp Extension and it works fine in terms of sending the UTM data to Mailchimp. It’s just necessary to set UMEDIUM = UMEDIUM, etc., in the Mailchimp Extension tab of CF7. If there’s no data the field is just empty in Mailchimp.

            My problem is getting it to work with the Elegant Themes Bloom plugin. The hidden fields are added so this again is a submission issue that I suspect probably can’t be resolved.

            Brilliant script Puru, thanks!

          • Matthew Miao

            hi, Rob.

            I am in the same position with you.

            I want to use contact form 7 and extentension to pass the value to mailchimp also.

            I want to know if you have find the workaround solutions to pass the UTM information along with form submit?


    • MM

      I don’t know if you’ve figured this out already, but isn’t the solution as easy as to unclick the ‘required’ option in Mailchimp for the hidden fields and merge tags?

  • Seva

    Hi Puru,

  • Vsevolod Khalizev

    Hi Puru,
    Thank you for very usefull post!
    Script works perfect when I embed mailchimp form as html code.
    But if I use plugin to add registration form to my page, I can see just emty fields in mailchimp subscriber statistics.

    I use Chimpy, it allows embed forms with shortcode.
    Could you give me any advice, what can be the reason that plugin igores utm_form.js?
    It generates form itself and doesn’t take into account other scripts, placed on the page?

    • Hi Vsevolod,

      After browsing Chimpy demo, it looks like it requires you to define the fields in the forms again in WordPress. I suspect that when you submit the form, Chimpy only takes the information that’s configured in the WordPress admin panel and ignores the rest.

      utm_form.js script submits UTM and other information via hidden fields so that the visitor does not see them on the page. Chimpy seems to be ignoring those.

      You could try adding the same UTM fields in Chimpy and see if it allows them to be set to hidden type.

      Hope this helps.

      • Vsevolod Khalizev

        Hi Puru,

        Thank you for advice.

        It seems like I do something wrong.

        Tried it with embeded Mailchimp html form – works perfectly.

        Tried it with complete set of UTM fields in Chimpy – nothing.

        Tried it with Gravity Forms (hidden and visible fields) – nothing.

        Created form with Contact Form 7 – nothing. And I remember, that Rob said in comment below, that he uses CF7 and it works fine (at least until UTM parametrs exist).

        It looks like some difference between common Mailchimp form and my forms cuases this problem.

        But utm_form. js script works with any form on the page, does it? The only condition – to use same field names in fors and in the script.

        • Hi Vsevolod,

          The script requires only two conditions to make it work:
          1. The form element must exist on the page as part of the HTML delivered by the server and not added later on (e.g. with javascript)
          2. The form should be able to accept the new hidden fields and submit them to the server.

          The script works with any form element. If any of the forms do anything unusual, say render the form with javascript or submit the form in some unusual way, then it might need a little bit more care to make it work.

          One good way to debug is to use the Chrome debugger and look at the from element and its fields after the page is loaded. If the script is working, you’ll see the new fields added to the form. If they are not added, then the script is not initialized correctly. If they are added, then something must be going wrong in the form submission.

          Let me know if this helps. I can also take a quick glance at your website if you prefer.

          • Vsevolod Khalizev

            Hi Puru,

            Thanks for your reply.

            I’ll be greateful for your glance at my site.
            My page with forms:

            My Chimpy form uses field names different from common Mailchimp form names. For example name=”chimpy_shortcode_subscribe[custom][EMAIL]” vs name=”EMAIL”. I suppose, that can be the reason the script can’t recognize form fields.

            And I detected strange thing. If I embed Mailchimp form with hidden fields, everything works. If I set all fields to ‘visible’, I recieve empty form.

          • Hi Vsevolod,

            Yeah, that might be the reason. After looking at your site, I can see that all the fields are added as expected in your form by utm_form.js script.

            When you set Mailchimp fields to visible, there’s probably some conflict with the script since it tries to insert the fields in hidden form.

            When I submit the form (in both the cases), I see that the data is being sent to your website. I’m assuming that Chimpy plugin then takes the data and sends it to Mailchimp. It’s during this step, I think, Chimpy ignores the USOURCE and other fields and only sends the fields that Chimpy recognizes.

            Can you try putting this code before adding utm_form.js script?

            var _uf = _uf || {};
            _uf.utm_source_field = “chimpy_shortcode_subscribe[custom][USOURCE]”;
            _uf.utm_medium_field = “chimpy_shortcode_subscribe[custom][UMEDIUM]”;
            _uf.utm_campaign_field = “chimpy_shortcode_subscribe[custom][UCAMPAIGN]”;
            _uf.utm_content_field = “chimpy_shortcode_subscribe[custom][UCONTENT]”;
            _uf.utm_term_field = “chimpy_shortcode_subscribe[custom][UTERM]”;
            _uf.initial_referrer_field = “chimpy_shortcode_subscribe[custom][IREFERRER]”;
            _uf.last_referrer_field = “chimpy_shortcode_subscribe[custom][LREFERRER]”;
            _uf.initial_landing_page_field = “chimpy_shortcode_subscribe[custom][ILANDPAGE]”;
            _uf.visits_field = “chimpy_shortcode_subscribe[custom][VISITS]”;

            Not sure if it will work, but let’s give it a try. You might want to setup all these fields in Chimpy and mark them as hidden.

            Hope this works.

          • Vsevolod Khalizev

            Hi Puru,
            Thank you for you attention and patience.

            Unfortunally it didn’t help.
            I’ll try some other form.

  • melissa

    This is really amazing. Thank you for sharing. I’m guessing it will work the same way with Formstack, if I match up the field names but I’m am unclear what the action, “Add … “USOURCE” for Put this tag in your content.’ does for the script. I don’t understand what “Put this tag in your content” means on a form. I can’t find a similar setting in Formstack. any ideas?

    • Hi Melissa,

      It should work with Formstack as well, though I haven’t tried it myself. Since the explanation above is specific to Mailchimp, it will be different for Formstack. Basically you’ll need to create fields in your Formstack form to allow accepting values for “USOURCE”, etc.

      This should be similar to say, adding a “Company” field of type “text” to your form. But in this case, you’ll add a field “USOURCE” of type “hidden” to your form. Since I haven’t used Formstack, it’s difficult for me specify where exactly to do that in their interface.

      Hope this helps.

  • Hello,
    [Sorry for my broken English]
    This tutorial is great, a big thank you.
    I use CF7 and I admit I am a little lost …
    After several hours of tests, everything works BUT I do not understand why. One thing is certain: when I look at the source in Firefox, I do not see the USOURCE fields, etc. As against everything happens well in the DB.
    Can you confirm that in CF7, we must “do nothing” and that the fields arrive by miracle?

    • Hi Christian,

      I’m glad it’s working for you with Contact Form 7. I haven’t used it myself, so I’m not sure why it would or would not work.

      Since the fields are added dynamically, viewing the source would not show USOURCE and other fields. However, if you look in Firefox inspector, say by right clicking on the form and choosing “Inspect Element”, then you’ll see the fields being added to the form.

      As much as I wish this script worked by miracle, it, unfortunately, still obeys all the laws of physics.

      (I should buy myself a wizard hat)

      • Nice!

        I begin to understand your code, I am impressed.
        (I touched it a bit to add a personal variable, it works)
        I think you can wear your wizard hat;-)


        • Vsevolod Khalizev

          Hi Christian,
          Could you share your example of CF7 form?

          • I use a “child theme” in WP and I put the JS code of Puru in footer.php (just before /body). There are two points to follow :
            1) the code :

            var _uf = _uf || {};
            _uf.domain = “”;

            is mandatory in WP, it seems…
            2) I have opted for an local hosting

            For your info, I use also “Contact Form DB” and “Contact Form 7 MailChimp Extension” with success.


          • Vsevolod Khalizev

            Thank you, Christian.
            Using Contact Form DB was great idea for me.

            I recieved letters with emty fields as CF7 reports, but now Ican see all UTM parameters.

            Thanks again, you are magician!

          • I’m glad it worked for you, Vsevolod.

            And thanks a bunch for helping, Christian. I really appreciate it.

          • Matthew Miao

            Christian, Can you share with us that how to pass contact form 7 mailchimp extension to mailchimp? I am having problems here

          • Hi Matthew,
            I do nothing special, it works without modification.
            You must use the “Custom field” section, maybe you forgot the square brackets in the name of variables CF7?
            (it happened to me the first time …)

        • Matthew Miao

          Yes, I am using the same contact form 7, Could you share it with us?

  • That’s great! Thanks a lot Puru.
    I spent a day writing my own and it’s no where near this good so I’m ditching the old one.
    Huge help, thanks again!

  • Matthew Miao

    It is very good code. Also, I make it work with contact form 7. But i am deploy the javascript to through google tag manager for all pages? Is this necessary, or should i just fire the code on the landing page or the contact form page?

    • Vsevolod Khalizev

      Hi Matthew,
      Could you share your example of CF7 form?

    • Hi Matthew,

      I would recommend putting it on all the pages of your website. Just make sure your other forms are not breaking (they shouldn’t unless they are doing anything unusual). This will make sure that you capture data about your visitors even when they land on a different page and then go to your contact form.

      So firing it through Google Tag Manager would be a good approach. I do it myself.

      • Matthew Miao

        Thank you for your prompt reply.

        So, will fire through all pages

  • Hi Magic Puru,

    I would like to talk to you of variables that I added in your code and explain why.

    Initially, the “UTM” are intended to describe the sources of an advertising campaign. However, since the arrival of “Universal Analytics,” Google advises against the use of UTM from AdWords (which uses the “gclid” single variable).

    But UTM remain through other media, essentially “Display”. I wanted to solve this problem by adding two more variables that I called “ush” :

    1) ush_alpha : is designed to receive a single code set from the original URL of my AdWords campaigns
    2) ush_bravo : a use only for a CTA (Call To Action) inside a Web site.

    Example scenario:

    A user clicks on an AdWords ad :

    Sometimes on the site during his visit, the user clicks a CTA type

    This lets me know that a surfer has converted on my website from the CTA Nr1 and it came from an AdWords campaign.

    Well in this case, with your code, the variable will be perfectly informed ush_bravo but ush-alpha variables and all the UTM will be erased (no change for ILANDPAGE and REFERRER *).

    Can you think, without much trouble, fix your code so that it does not erase the existing variable ?

    I think this is a good change that remains in the logic of tracking. The rule could be: if variable exists, it is conserved or updated but never erased.

    What do you think ?


    • Hi Christian,

      I think I know what you mean. However, before we debug this issue, do you want to try the updated code The code and instructions are updated to add additional parameters besides UTM codes. e.g. you can add an variable “affiliate” as,

      _uf.additional_params_map = {
      affiliate: “AFFILIATE”

      This way you can define your own variables very easily without actually changing any code. These additional variables work independently of UTMs. See if this works for you. The version of the script has been updated to 1.0.2.

      Even though the code is updated (by contribution from other people as well), I haven’t updated this blog post to reflect the improvements.


      • Thank you for your help.

        But I am not at all a JavaScript specialist …
        So, I confess I do not know where I have to put the code “_uf.additional_params_map …” and also how to code if two “affiliate” variables exist

        : – /


        • Well, replace your current setup with this, i.e. remove what you currently have for utm_form and put the following code before the closing tag

          var _uf = _uf || {};
          _uf.additional_params_map = {
          ush_alpha: “USH_ALPHA”,
          ush_bravo: “USH_BRAVO”

          And cross your fingers.

          • Of course…
            (I am ashamed)

            With these changes:
            1) it works, the new variables are taken into account.
            2) but if in the navigation, I change one of the two variable, the other is empty.

            Example on my site

            1) I tested with this query string:
            I look Cookies with Firebug : OK, “Alpha” is loaded with 421 and Bravo exists but as empty (normal). All other variables (UTM) are there too. Perfect.

            2) In the bottom of the page, there is a CTA to the “Contact” page with QS:
            ? ush_bravo = ctahome
            In the Cookies, I see “bravo” loaded with “ctahome” but by against, “alpha” is now empty.

            I hope I am clear; – /


          • Looks like this is a very specific use case and I’m afraid the script doesn’t support it. I would recommend using Google Analytics events to keep track of any clicks/CTA. The intention of the script is to capture the information where/how a visitor landing on your website and not what they do on your website.

            I’m not sure if there’s a way to do it without writing custom javascript for your use case. Sorry I couldn’t help in this case.

          • You’re right, it starts to get complicated.
            Your solution is so friendly that I had hoped to bring together all the tracking in one place.
            You can not imagine how much you already have helped me a lot.

          • Matthew Miao

            I am trying the same thing. So i need to add the query string of additional for the target links to make this work?

          • Sorry Matthew, I didn’t get a chance to reply to your comment until now.

            Yes, the additional parameters are part of the query string, but it should not break anything if they are absent. I’ve used the new feature a few times and it worked. But this is new feature and if you see an error or some unexpected behavior, please let me know.

  • Matthew Miao

    Hi, Puru

    I have noticed that you have updated to 1.0.2, Can you tell us what is newly added into the script?

    Also, I have one suggestions, Is it possible to add first landing time, and final convert time from the cookies.

    If it is possible, it can tell us how long it takes for visitors to convert. it will be valuable, what do you think?

    • Hi Matthew,

      Version 1.0.2 has two new options you can pass to the script.

      1. You can add new custom parameters that you can add to your forms. e.g.

      _uf.additional_params_map = {
      affiliate: “AFFILIATE”
      }; // Maps affiliate parameter to AFFILIATE form field

      2. If you have multiple forms on a page and would like to attach the UTM and other information only to a particular form, you can define the selector, e.g.

      _uf.form_query_selector = ‘form[action=”/sign_up”]’;

      That’s a good idea to add the two times. It’s very easy to add the first landing time. However, the final convert time, though not difficult, requires the script to interfere with the form submission and can potentially break it in a variety of setups. However, that information is readily available since your CRM/email signup tool captures it automatically anyway. I’ll definitely investigate it if there’s a good way to achieve this.

      I’ve written down these as the next set of updates. It’s hard to promise when they’ll be available though. I’ll try to comment here if there’s a new update.


      • Matthew Miao

        Dear Puru:

        Thank you for your reply. I am waiting for the fist landing time added. No rushes, take your time.

        Meanwhile, I have another suggestions.

        Your code tells where the visitor come from fist, and last, But with the below code added. We will be able to know what is happening in-between. We use sourcecookie to make this happen.

        I am posting the video, from Julian,

        But Now i am having the problems to pass the sourcecookie value in the form.

        I am revising the code below:

        _uf.additional_params_map = {
        affiliate: “SOURCECOOKIE”
        }; // Maps affiliate parameter to AFFILIATE form field

        In the Contact Form 7, The Sourcecookie Value id below:

        [dynamichidden SOURCECOOKIE id:SOURCECOOKIE]

        So, I want to poplulate the Sourcecookie in the form filed, and submit the value, Can you point what is wrong?

        By the way, my contact form is here:

  • Daniel Kiryakov

    Hi Puru,

    First of all, this is a great script – thank you! I successfully managed to integrate it into an older version of my website, but I cannot get it to work on the test version of a new one. Any idea why? You can see here:

    It appears in the source before closing the body tag, but doesn’t add the hidden fields anywhere 🙁


    • Hi Daniel,

      I see it before the closing tag. Can you try putting it before the closing tag?


      • Daniel Kiryakov

        Done. It was just before earlier, but I moved it further up to experiment.

        • I see all the fields being added to the form correctly. Is your new form able to accept these values?

          • Daniel Kiryakov

            I am using wordpress’ contact form 7 plugin. I believe it is as it worked somehow before.

          • I haven’t used Contact Form and not sure what could be happening in your setup. Maybe you could try comparing all the CF7 settings if it’s the version in both the versions of your website.

          • Daniel Kiryakov

            I now see that the entries started to be recorded in the Contact Form DB (another plugin that captures Contact Form 7 submission). So I am good to go, thanks 🙂

          • Great. I’m glad it’s working for you, Daniel.

          • Hi Daniel,

            What did you do to implement this script using Contact Form 7?

            Thanks in advance!

          • Daniel

            Hi Gabriel, yes it works perfectly with CF 7

          • How do you configured CF7 to make it work, Danel?

  • Larissa Reynolds

    Puru, just brilliant. Thank you so much for sharing this script. Cannot wait to put it to work. Love your service!

  • Taylor Coil

    Hello Puru,

    Thank you so much for this awesome script. It works phenomenally with Mailchimp.

    Unfortunately, it’s breaking my search bar and adding the parameters to search submissions, as well. I tried limiting the form action to just a Mailchimp subscribe, but the script no longer fires. Any ideas on how to fix that?


    • Hi Taylor,

      Are you using 1.0.2 version of the script? You can get it at,

      Then in the settings of the script, you can use

      _uf.form_query_selector = ‘form#mc-embedded-subscribe-form’;

      as one of the options. I’m assuming your Mailchimp form has an id of “mc-embedded-subscribe-form”.

      Not sure if your current changes are similar to the above, but you could give this a try if they are different.


      • Taylor Coil

        Thanks, Puru. I did have a _uf.form_query_selector in my code, but it wasn’t working. I’m not using Mailchimp embedded forms (not enough customization) – I’m using a third party tool. I’ll try to find the form id and edit. Thanks!

  • I want to add your script using Google Tag Manager.

    So, I need to add a Custom HTML Tag just before the tag that triggers in all pages.

    How do I configure that in GTM?

    Thanks in advance!

    • Hi Garbriel,

      If you are using GTM, you don’t need to worry about adding it before the tag. Since GTM loads scripts asynchronously, in almost all the cases the script will be loaded after the page has loaded. This is enough for the script to work.

      So just add it as normal HTML Tag and you are good to go.


      • Hello again,

        I did just what you told me, but I’m seeing some strange behaviour.

        The tag is firing OK, but when I inspect the source code, I see all the hidden fields of my form (UMEDIUM, UCAMPAIGN, UCONTENT, UTERM, etc), but the values are all empty.

        BUT… If I inspect the form (using the Inspect Element feaure of both Chrome and Firefox), I can see that the values are filled for VISITS, ILANDPAGE, IREFERRER and LREFERRER.

        Nevertheless, when I receive the email generated by the form, I see all the hidden fields, but they’re all empty.

        I’m using WordPress and the Fast Secure Contact Forms plugin.

        Any ideas?

        Thanks in advance!

        • Hi Gabriel,

          Hmm, it seems that there is something strange going on with the behavior of Fast Secure Contact Forms plugin. Did you configure it to accept the new parameters? If you did, then it might be adding its own version of these parameters in the form. Sometimes the behavior of form plugins is unpredictable since they all have their own quirks.

          The UTM script adds the hidden field at the top of the form. If there are same fields filled later in the form with an empty value, then the empty value will be sent.

          I haven’t used that form plugin before, but is there a way for the plugin to accept the hidden values, but not add them to the form?

          – Puru

          • Yes, I configured the plugin by adding hidden fields, and as you said FSCF is overwriting the values generated by your script.

            I’ve found that I can pass query string parameters to a contact form page. So, if my URL goes something like this:

            Then I’ll get the proper values on the USOURCE and UMEDIUM hidden fields.

            This is explained here:

            I’ve changed your script so instead of your filled is called USOURCE, it’s now called 1SOURCE instead, with the hopes that that would work… but no.

            Could you please help me to solve this? I think that I’m close to the solution, but I’m not a programmer.

            You can find the source code for FSCF here:

            Thanks a lot!

          • Hi Gabriel,

            To be honest, it’s hard to predict the behavior just by looking at it. It’s difficult for me to spend too much time trying to reproduce and debug this.

            Hope you are able to work this out.


  • g

    Hi Puru,

    Is this something that could be integrated with Wufoo? I’m currently embedding a wufoo form on my site and would like to pass UTM parameters through hidden wufoo fields. I can see that you provided a solution to change the field names to new mappings, however, I’m curious if you or anyone has tried this with Wufoo as the CRM instead of Mailchimp.

    Please let me know.


    • Hi,

      Yes, I think it should work with Wufoo though I haven’t personally tried it. You could give it a shot and see if it works. If not, I can also look at your website and see if can spot any obvious errors.


  • Blaine


    Thanks for sharing this code, it has been very helpful! I have successfully passed the referrer, visits, and landing page parameters to my database.

    However, I have not been able to pass the UTM parameters on my main form page. On the majority of my pages, I can view all of the hidden inputs, including the UTM values. But on the main form where I pass my info, the UTM inputs don’t show up.

    I know the UTM data is present in the cookie on that page. The only difference I can think of between the problem page and the pages passing all of the inputs correctly, is that the problem page is a secure page, while the others are not.

    I will keep working on this, but nonetheless, thanks so much for your help and any guidance you might have.

    • Hi Blaine,

      I’m glad you find the code useful.

      The code has works secured pages without any problem since I myself have some pages on https. You might want to check if the hidden inputs are added by inspecting the form in the browser. It’ll at least tell you whether there’s an issue on the page or the backend/database side of that form.


  • Joel Kiess

    This seems to be exactly what we’d like to do but have been struggling to make this work.

    Added the code to our site, added fields to MailChimp. We set up urls using Googles URL builder. We use Ninja forms in a pop-up form connected to MC. We can see the MC fields in the settings. However we get no data in our MailChimp list when testing the form submissions.

    • Hi Joel,

      It’s possible that Ninja forms is overriding the fields set in the form by the script. When you load the page with the script added, do you see the new fields correctly populated? Also, do you see duplicate fields in your form after the page load?


  • Hi Puru – Exactly what we were looking for. We are trying to get this to work on our site – Form using a simple Mailchimp plugin form “Chimpy” & the code in Google Tag manager. Our utm show in Google Analytics but are not showing in fields we setup in Mailchimp. Any ideas as we would love to track these in Mailchimp?

    • Hi Teri,

      I’m not able to see the code loaded on the website. Were you able to see it? Maybe GTM has not published the code yet?

      – Puru

  • Brian Barr

    Hi Puru,

    This seems really handy. I installed this in the wordpress theme editor & it kept trying to redirect the pages to (not encoded, just copied + pasted that way).

    This causes a loop redirecting to this non-existent page which seems to be referencing the URL in the script. Any idea why this is happening? I put analytics & other tracking codes scripts in there just fine.

    • Hi Brian,

      This is strange. It has never caused this problem before. Can you try deleting the double quotes (“) around the script url and typing the quotes manually instead of copying? You can also try adding “https” in front of double backslash (//).

      Let me know if that works.


      • Brian Barr

        I was able to resolve the issue (see “edit” above). So no worries. I just had to move it above Google Analytics. Unfortunately, it doesn’t seem to work with SumoMe :/ but I don’t think that’s your fault. If a mod is able to remove the image in my initial post, it’s probably best 🙂 Thanks for your speedy support!

        • Hi Brian,

          Yeah, it’s difficult to make it work the SumoMe since they dynamically inject forms on the website.

          Also, looks like it’s not possible to delete just the image using admin tools. If you prefer, we can just delete the comment.

          • Brian Barr

            Haha yeah, Disqus is weird. If you have anyone that’s made it work with SumoMe let me know, I’d love to ask them how they did it! For now I figured out a hybrid, using this with my Mailchimp forms & passing the full URL with SumoMe to parse out the UTM codes.

            You can go ahead and delete the comment to make things easier.

            Thanks again for you quick replies and this helpful tool. You rock!!

          • Rob

            Hey Brian, I’m just looking into tracking UTM parameters for my exit popups – I’m trialling SumoMe and we use Mailchimp so I’d be really interested to hear a little more about how you did this – if you’re willing to share?


          • Brian Barr

            Hey Rob,

            Happy to show you what I did. We don’t like to keep secrets 🙂

            It’s a bit of a work around as SumoMe doesn’t support UTM codes natively.

            SumoMe DOES allow you to pass the full value of the signup URL however, and I sent that to mailchimp. From there, you can use Zapier ( to send new subscribers to Google Sheets and write a few formulas using RegEx (which is epic btw).

            Alternatively, if you want to skip the automation setup (though it’ll save you tons of time in the long run), you can just export the contacts when you’re ready for reporting and using the find & replace feature to isolate the values you want.

            I still have yet to build the formulas, but it shouldn’t be too hard, done similar tons of times. If you want I’ll send you a copy once it’s done – just email me brian (at) (we give this kind of stuff out like it’s our jobs – because, well, it is haha).

  • Kumar

    Hi Puru
    I’m using custom made contact form on all my landing pages. I’ve added a functionality where I get the data to my email as well. Is there any way where I can capture the UTM data as well for custom forms.

  • So that’s a great example with MailChimp — but do you have any idea how to add it to my contact forms? I’m using Gravity Forms for WordPress. I have made some hidden fields on my form, but I have no idea how to get them to fill with data.

    • Gen, the data will be filled by the script. Your form should just be able to accept the data when a visitor submits the form.

      • Then I have no idea how to get the form to accept data.

        I’ve made a hidden field and given it the field label: UTM_SOURCE
        On the advanced tab I checked the field “Allow field to be populated dynamically”.
        Then I put in the parameter name “USOURCE”.

        Then on the forms that it emails me I have it supposed to be filling in those values, but all I get are blanks for the values. I tried looking at the hidden fields in my web viewer and they are empty there too.

        This is the page where I have the hidden fields

        • Looking more into it, it seems that Gravity forms do not allow customization of “name” attribute of a field. They are dynamically generated. So you’ll need to tell the UTM script the name attributes of the, e.g.

          _uf.utm_source_field = “gravity_form_field_for_usource”

          This might work, but it does make it a bit complicated since Gravity form also inserts its own field into the form.

          There’s a simple way by just using Gravity forms and not using this script at all. Gravity Forms supports populating the field from query parameter. So instead of putting “USOURCE” in the parameter name for “Allow field to be populated dynamically”, you should use “utm_source”. This will tell Gravity Forms to capture it directly from the query params.

          In that case this script is not required. However, this will also only capture visits with UTM parameters that directly land on this form.

          Hope this helps.

          • Well, it tells me I’m in over my head and need professional help. Which does help knowing that.

          • Hey Gen, I have successfully implemented a version of this with Gravity Forms. Feel free to email me at cody[at] and I can help.

  • Chris Ebel

    We have integrated this tool with Eloqua, and overall it works great. However, every value submitted from our forms comes across with a comma “,” appended to it, and I can’t figure out why.

    Example when someone submits a form on:

    The submitted value comes in to eloqua as “social,”

    Any idea why this is happening?

    • Hi Chris,

      Looks like the script appends the the correct value, “social”, to the form. However marketing tools like Eloqua, Hubspot, Marketo, etc. track a visitor across various/multiple form submissions. So based on the field configuration of your form, these tools can accumulate the field values separated by comma, semicolon or other separators. And looks like Eloqua preemptively adds a comma in preparation for the next submission of the same form by that visitor.

      Hope this helps.

  • Manoj


    I have one landing page and same i want to use for Google and Facebook paid promotion. the enquiry form have NAME, EMAIL ID, PHONE, SELECT COURSE (drop down) and MESSAGE option. This enquiry form is forwarded to my email id.

    Is there a way that when a lead is coming from Google the enquiry which i receive on my email should contain the SOURCE (ex. Google) and SUB-SOURCE (ex. Vendor A) so that i will know that this particular enquiry came from google.

    And same if the enquiry is coming from Facebook then the SOURCE (eg. Facebook) and SUB-COURSE should be different.

    Lets say total 10 enquiry received from the same landing page and i should be able to see how many came from Google and how many from Facebook. HOW THIS CAN BE DONE through UTM please?

    Note: my landing page is custom and not using any CMS platform.

  • Jeroen

    Hi Puru,

    Great post! I tried to add the code to our website but it seems that it doesn’t load any data at all. We are using Infusionsoft CRM HTML forms. It is not possible to change the datbase field so I tried your code like when changing the Source I did this:

    _uf.utm_source_field = “inf_custom_USOURCE”; // Default ‘USOURCE’

    But it still didn’t worked. Do you have an idea where I did something wrong. Maybe it is because we are using infusionsoft forms?

    • Hi Jeroen,

      Without looking at the page, it’s a bit difficult to know what could be going wrong. You could try inspecting the form using Chrome developer tools and see if the script populates the form correctly. If you submit the form, you can also see what fields are sent over in the network requests.

      Having said that, I wouldn’t rule out any strange issues due to it being Infusionsoft forms, especially if the forms are dynamically loaded by a script. I haven’t dealt with them yet.

      If you like, I can take a quick ,1 minute look at your website/form to see if the script populates the form or not.

      Hope this script works for you.

  • Hi Puru
    Great post! Very useful, thank You.
    I’ve installed the code, updated the merge fields in the list in mailchimp.
    There are some signups today, but there is no data on the referrer or other data.
    Any idea?
    I kindly ask You for help.
    Best Regards

    • Hi Marcin,

      There are duplicate quotes in the script URL on your website. It currently looks like,

      But the URL should look like this.

      Maybe this will fix the issue if everything else is working fine.

      – Puru

      • Dear Puru
        Thank You. It was a stupid error (formatting got in the way).
        Now it works like a charm.
        Great solution! Great source of infos.
        Best Regards

        • Hi Marcin,

          I’m glad it’s working for you. Yeah, the web based editors tend to do that. Even in my comment above, there shouldn’t be anything after ‘async’, but it added an equal (=) sign with quotes next to it.


  • Hi Puru,
    Thanks for putting this together it’s great. I’m struggling a little bit. I’ve added the field to the CRM and added the code to the landing page ( which I’ve added above the Hubspot tracking code. Any ideas would be greatly appreciated!

    • Hi Adam,

      Unfortunately, Hubspot makes it really difficult to add fields dynamically to their forms. They populate their forms on the fly and don’t do a normal form submission. If you look at the source code of the form on your website using Chrome developer tools, you’ll see that the fields are populated correctly by the script. However when you submit, Hubspot doesn’t just submit them, but overwrites their values with their javascript before submission based on what it thinks the values should be.

      I can understand why they do all this, but I haven’t had time to come up with a reliable solution that’ll work with Hubspot forms.

      You can try the newer version of the script

      and see if that helps. It puts the fields towards the end of forms to account for such issues.

      Hope this helps.

  • Aaditya Sharma

    I added above code in header file but no luck.

    Can you help me? I am using Zoho crm web form in my website and want to pull data into that form?

  • Babu

    Hi puru,

    I have one general form, i need to add source,medium and campaign in this form as hidden for storing into the database. Visitor may come to this form by google or ads etc. i want to capture source information.

    I have added this before tag.

    Then, what to do that i don’t know. how to capture can you help?

    Advance thanks.

  • Horacio Reyes Rios

    Hi Puru,
    I’m trying to include your code in wordpress, I included in the footer before the /body tag, but the code is not including the new fields in my forms, what can be the problem?


    p.s. I’m generating the forms using CRM vtiger, I already included the utm fields on the crm.

    this is the code I’m inserting

    var _uf = _uf || {};
    _uf.domain = “”;
    _uf.utm_source_field = “label:handlref”; // Default ‘USOURCE’
    _uf.utm_medium_field = “label:utmmedium”; // Default ‘UMEDIUM’
    _uf.utm_campaign_field = “label:utmcampaign”; // Default ‘UCAMPAIGN’
    _uf.utm_content_field = “label:utmcontent”; // Default ‘UCONTENT’
    _uf.utm_term_field = “label:utmterm”; // Default ‘UTERM’
    _uf.initial_referrer_field = “label:handlip”; // Default ‘IREFERRER’
    _uf.last_referrer_field = “label:handllandingpage”; // Default ‘LREFERRER’
    _uf.initial_landing_page_field = “label:handlurl”; // Default ‘ILANDPAGE’
    _uf.visits_field = “label:utmcantidadvisitas”; // Default ‘VISITS’
    _uf.additional_params_map = {
    affiliate: “AFFILIATE”
    }; // Maps affiliate parameter to AFFILIATE form field
    _uf.sessionLength = 200; // In hours. Default is 1 hour
    _uf.add_to_form = “all”; // ‘none’, ‘all’, ‘first’. Default is ‘all’
    _uf.form_query_selector = ‘form[action=”/submit”]’; // custom form selector. Default is ‘form’, to select any form.

    • Hi Horacio,

      Looks like there’s a mistake in the last line where async has =””. It generally happens in copy-paste in web-based editors. If you could manually remove that and just have async, it might work.

      – Puru