[Guide] Persist UTMs and pass them to a subdomain or other website.

Sean Gowing
|
December 7, 2022
[Guide] Persist UTMs and pass them to a subdomain or other website.

Passing UTMs to a Subdomain: Overcoming a Common Challenge

(Updated 03/2023)

Recently, I was tasked with finding a solution to a unique problem: how to persist UTMs and pass them to an application residing on a subdomain. As I began my search for a solution, I stumbled upon an insightful article by Analytics Mania written by Julius, whose code served as the foundation for my solution.

One of the challenges with UTMs is that they are lost after the first click if not saved. Fortunately, Local Storage provides a simple solution. By storing the UTMs for later use, we can ensure that they remain accessible. The code I discovered checks for the desired domain or subdomain and applies it using JavaScript to the anchor tag, allowing the UTMs to pass through.

To illustrate, let's consider my application which is hosted at app.mysite.com. When I click the login link, I want the UTMs to accompany the click so that I can capture them within the application funnel. This provides a comprehensive picture of the entire funnel, from the top to the bottom, enabling the measurement of campaign success and true ROI.

Now, let's dive into the code that makes this possible. I had to move the code to the github repo because it was breaking my whitespace. Grab it from the repo!


https://github.com/twistedx/UTMSubdomain

This code from looking at it you can see it does quite a bit. If you look it targets only links that have a CSS class of outbound. If you are looking for a generic solution you can just swap this targeting back to target just class types of "a". This way it will target all links. I have made some improvements to the code over the last few months and optimized it a bit.

If you need help implementing this code reach out to me 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.