How to Add Source Tracking to Contact Forms

Created by Mark Alfon, Modified on Tue, 11 Aug at 6:35 PM by Mark Alfon



How to Add Source Tracking to Contact Forms

Capturing the exact page URL—including UTM parameters and campaign tags—when a lead submits a contact form is essential for tracking source attribution. Since native contact forms do not include a built-in hidden field type, you can easily capture this data by adding a standard text field, auto-populating it with JavaScript, and hiding it visually with CSS.

Step 1: Add the Tracking Field

  1. Open your contact form settings and go to Content → Form Items.

  2. Click + Add field.

  3. Set the Field label to Submission URL.

  4. Set the Field type to Short text.

  5. Leave the field unrequired.

Step 2: Add the Auto-Fill and Hide Script

  1. Navigate to Site Settings → Head HTML in your site dashboard (or place this in a Footer HTML widget).

  2. Copy and paste the following script exactly as shown:

HTML
<script>
(function () {  function apply() {    var labels = document.querySelectorAll('label[data-dm-for]');    for (var i = 0; i < labels.length; i++) {      var txt = (labels[i].textContent || '').trim().toLowerCase();      if (txt.indexOf('submission url') === -1) continue;       var input = document.getElementById(labels[i].getAttribute('for'));      if (!input) continue;       input.value = window.location.href;                 // fill the URL      var row = labels[i].closest('.dmforminput') || input.closest('.dmforminput');      if (row) row.style.display = 'none';                // hide the field      return true;    }    return false;  }   var t = 0, timer = setInterval(function () {            // wait for lazy render    if (apply() || ++t > 25) clearInterval(timer);  }, 300);   document.addEventListener('submit', apply, true);        // refill before send
})();
</script>

Note: If you name the field something other than Submission URL, update 'submission url' in the script to match your exact label in lowercase.

Step 3: Publish Your Site

Click Republish. Code changes and scripts will not run until the site is live.

Step 4: Verify the Setup

  1. Open the live, published page in an Incognito/Private window to bypass cached assets.

  2. Verify that the Submission URL field is completely hidden on the form.

  3. Submit a test entry and inspect the email notification or the Content → Submission log in your dashboard.

  4. The Submission URL entry should output the full page URL, including any campaign parameters (e.g., [https://www.yoursite.com/employers?utm_source=google](https://www.yoursite.com/employers?utm_source=google)).

Important Notes

  • Captured Data: This script records the protocol, domain, path, and full query string (all UTM and ad parameters).

  • Current Page vs. Referrer: This records the page the form is actively on. If you also want to capture the referring website URL, create a second field and populate it using document.referrer in JavaScript.

  • Live Site Testing: Always test on the published URL. This script intentionally does not run inside the site editor or preview mode.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article