[Guide] Capture UTM's in Webflow and pass them to a form

Sean Gowing
Sean Gowing
July 14, 2022
[Guide] Capture UTM's in Webflow and pass them to a form

(updated March, 2023)

What is a UTM

The UTM code is the key to tracking your digital marketing campaign's performance. This simple little module can be attached seamlessly on any URL, generating Google Analytics data for all online platforms - including Facebook or Twitter ads! If this is done right you can track campaign success all the way to the bottom funnel/ closed wins. UTM's are very important to determine campaign ROI. So if you are not tracking campaign success with UTM's you should be! True ROI, very important.

What are UTMs check out this article here.

How do UTM's Work?

UTM's are a link that you would build that you then use in your campaigns. it would look something like this:

Now onto an example:

We are running a custom piece of code in the head of the project in Webflow to grab the UTM's. We want the UTM's to persist past the first page so we will use local storage in the browser to save them for later use. Here is an example of the code I am using to do this. update: When I wrote this original post, I was intending to use this code on one page. The problem is if we dont check to see if the UTMs are stored when we run the getUTM function it will just overwrite the code. We need to look into localstorage for the UTMs and then if they are present do nothing. If they are not present them we will try and extract them again.


 function getUTM() {    
 let params = {};    
 const searchParams = new URLSearchParams(window.location.search);
 searchParams.forEach((value, key) => {
 params[key] = value;
 console.log("storing UTMs")
 localStorage.setItem('params', JSON.stringify(params));
 //adding this conditional check means the code wont overwrite the values once they are set.
      if (localStorage.getItem("params") && localStorage.getItem("params").length > 3) {
        console.log("do nothing");
      } else {
        console.log("run utms");


Now that this code is running we will see the green arrow above, the UTMs will be stored in the "params" value in your local storage. We can then retrieve them from there and place them into our contact form in hidden fields to use for bottom funnel campaign measurements. We run this on a document.ready because we want to ensure that if we are using something like a Marketo form it is fully loaded before we attempt to insert the utms.

      $(document).ready(function () {
        console.log("fetching utms");
        var param = JSON.parse(localStorage.getItem("params"));
        let utm_source__c =
          param["utm_source"] == undefined ? "" : param["utm_source"];
        let utm_medium__c =
          param["utm_medium"] == undefined ? "" : param["utm_medium"];
        let utm_campaign__c =
          param["utm_campaign"] == undefined ? "" : param["utm_campaign"];
        let utm_content__c =
          param["utm_content"] == undefined ? "" : param["utm_content"];
        let utm_term__c =
          param["utm_term"] == undefined ? "" : param["utm_term"];
        let GCLID__c = param["gclid"] == undefined ? "" : param["gclid"];
        let FBCLID__c = param["fbclid"] == undefined ? "" : param["fbclid"];

        let gclidInput = document.getElementById("input");
        gclidInput.value = GCLID__c;

Now you just have to match the inputs on your form with the inputs that this code would feed the UTM's to. We use turnery operators to place the UTM's if they are present or to do nothing. We don't want this to error out which is why we use them as well if the UTM codes are not present. As always if you need help setting up tracking or implementing bottom of funnel UTM's measurements feel free to reach out. We are always here to help! If I can improve this article, send me an email at sgowing at socialcatnip.com or let me know!

If you are looking to pass UTMs to a app from a marketing website check out this solution here.

Written By
Sean Gowing
CEO of SocialCatnip
Need help?

Contact Us

Reach out to us today. We are always working to improve our services so you can stay on top of your digital marketing goals. Simply fill out our online form to get jump-start your digital marketing today!

Contact submission will be responded to within 24 hours. Thank you for reaching out to us.

Fields marked with an asterisk (*) are required.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.