
April 3, 2025
Transfer UTM Parameters From One Page To Another with GTM
Updated: April 3rd, 2025.
I have completely redone this solution to support more cases and require less configuration. However, in some situations, the older version of this solution is recommended. If the destination URL contains a hashmark (#), you should try using the older version.
====
Imagine this. You’re running a promo campaign that brings traffic to a certain landing page (e.g., landingpage.com). After the visitor clicks the main Call-to-action button (e.g., GET YOUR DISCOUNT), he/she is redirected to another page (2ndpage.com) which asks the visitor to do the final action, install the app, fill in the form, sign up, etc.
When the conversion is completed, a Google Analytics event is fired. Unfortunately, when you look at your GA reports, what you’ll see is that all conversions are attributed to the landingpage.com. Technically, this is correct because all visitors landed on the 2ndpage.com from landingpage.com, but you’d like to see the original source which brought the visitor, wouldn’t you?
Normally, you’d need to implement cross-domain tracking here, but in some cases, that is not possible (I’ll explain them a bit later).
In this blog post, I’ll show you a specific technique using Google Tag Manager to transfer UTM parameters (or basically any URL parameters) from the initial page landingpage.com by automatically finding and appending them to the outbound link(s) pointing to the subsequent one (2ndpage.com). This is useful if cross-domain tracking cannot be implemented.

Video tutorial
If you prefer video content, here’s a tutorial from my YouTube channel.
The problem explained
Say, that you’re promoting a product that is available in the App Store (for example, Shopify App Store). We’ll call it Lorem Appsum. Its App Store page isn’t sufficient to list all the benefits, cool features, etc. So you decided to create a separate landing page that you’ll drive traffic to. You have also marked all inbound links (stored on other websites/forums/etc.) that lead visitors to that landing page with UTM parameters.
That new landing page contains key selling points, descriptions of features, a video, and a big GET APP NOW button (Call-to-action, a.k.a. CTA). Perfect. The visitor lands on the initial page, clicks that CTA button lands on the App Store page, and installs the app. Here’s the scheme of the entire visitor journey:
Notice that UTM parameters are lost after the visitor clicks an appstore.com link on loremappsum.com page.
The problem is that Google Analytics will attribute this conversion to loremappsum.com, although it would be more beneficial to see the values of the initial UTMs.

The Solution – Overview
Update: This is version 2 of the solution. With it:
- you will be able to transfer any query parameters (not only UTMs)
- you will not need to create URL variables
- you can decorate links of multiple domains
- and query parameters that you want to transfer are optional (this means that if utm_campaign is not present in the URL, the solution will still work).
====
One of the solutions is to transfer UTM parameters from loremappsum.com and automatically add them to all links which redirect users to appstore.com/loremappsum. We’ll do this with Google Tag Manager and a custom script.
Important: if you notice that the script is not working in some situation, please let me know and I’ll see what I can do to fix it.
<script> (function() { var domainsToDecorate = [ 'domain1.com', //add or remove domains (without https or trailing slash) 'domain2.net' ], queryParams = [ 'utm_medium', //add or remove query parameters you want to transfer 'utm_source', 'utm_campaign', 'something_else' ] // do not edit anything below this line var links = document.querySelectorAll('a'); // check if links contain domain from the domainsToDecorate array and then decorates for (var linkIndex = 0; linkIndex < links.length; linkIndex++) { for (var domainIndex = 0; domainIndex < domainsToDecorate.length; domainIndex++) { if (links[linkIndex].href.indexOf(domainsToDecorate[domainIndex]) > -1 && links[linkIndex].href.indexOf("#") === -1) { links[linkIndex].href = decorateUrl(links[linkIndex].href); } } } // decorates the URL with query params function decorateUrl(urlToDecorate) { urlToDecorate = (urlToDecorate.indexOf('?') === -1) ? urlToDecorate + '?' : urlToDecorate + '&'; var collectedQueryParams = []; for (var queryIndex = 0; queryIndex < queryParams.length; queryIndex++) { if (getQueryParam(queryParams[queryIndex])) { collectedQueryParams.push(queryParams[queryIndex] + '=' + getQueryParam(queryParams[queryIndex])) } } return urlToDecorate + collectedQueryParams.join('&'); } // borrowed from https://stackoverflow.com/questions/831030/ // a function that retrieves the value of a query parameter function getQueryParam(name) { if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(window.location.search)) return decodeURIComponent(name[1]); } })(); </script>
Once the visitor lands on loremappsum.com AND the Page URL contains utm_medium, utm_source, or any other URL parameter (that you’re interested in), the tag will fire. It will scan the entire page and look for links that contain the domain(s) of the final landing page, in this case, appstore.com.
If the script finds the link, it will:
- Fetch URL parameters (e.g. UTMs) from the browser’s address bar.
- And will add those parameters to that spotted link (which contains “appstore.com”).
So instead of appstore.com/loremappsum, all links on loremappsum.com will be automatically modified to appstore.com/loremapsum?utm_medium=referral&utm_source=promo &utm_campaign=blackfriday2017. Here’s the updated visitor flow:
This solution does not cover 100% of cases
There are situations where this solution will not work properly:
- If the URLs that you wish to decorate contain #, try using the older version of the solution
- If the URLs that you wish to decorate already contain query (a.k.a. URL) parameters from the Custom HTML tag, they will not be replaced. The script will append them to the URL (therefore, you will end up with duplicate parameters).
Notice more situations where the script does not work as expected? Let me know in the comments, and I’ll see what I can do.

The Solution – Implementation in GTM
In Google Tag Manager, create a custom HTML tag and paste the JavaScript code that I provided in the previous chapter.
Now, we need to do some configuration.
Edit the list of domains
On line 3, you’ll see this domainsToDecorate array:
var domainsToDecorate = [ 'domain1.com', //add or remove domains (without https or trailing slash) 'domain2.net' ],
Here you must enter the domain(s) of the final landing page(s). If a visitor lands on the intermediary landing page, the script will be looking for links that contain the domain(s) from the domainsToDecorate array.
In other words, if the journey is some website > loremappsum.com > appstore.com, then you must enter “appstore.com” in the domainsToDecorate array.
If you want to decorate URLs of just one domain, you can keep just one domain. If you want to add 4 domains, you can do that as well. Just make sure you don’t leave any typos, missing commas, or apostrophes.
If you want to be more specific and decorate only some links, you can be even more specific. Instead of the appstore.com, you can enter appstore.com/your-app.
Here is an example with just one domain (obviously, you should replace that domain):
var domainsToDecorate = [ 'appstore.com' ],
Add URL parameters you want to transfer
Next, you must edit the list of URL parameters you want to take from the page URL and transfer them to particular outbound (outgoing) links.
If, for example, the Page URL (where a visitor currently is) is https://www.loremappsum.com/?utm_medium….., then those parameters (e.g., utm_medium) will be added to all the URLs of the appstore.com, e.g., https://appstore.com/loremappsum/?utm_medium…
queryParams = [ 'utm_medium', //add or remove query parameters you want to transfer 'utm_source', 'utm_campaign', 'something_else' ]
What’s cool with the recent update of this solution is that:
- You don’t have to create GTM variables for each parameter
- You can transfer any URL parameter (a.k.a. query parameter), not only UTMs
- The parameters you entered in the queryParams array are all optional. If Page URL does not contain, say, utm_campaign, the script will still work just fine
- UTMs can contain a “+” sign as well. It will be transferred just fine and will not be encoded to %2B.
Here’s an example of what the setup could be:
queryParams = [ 'utm_medium', 'utm_source', 'utm_campaign', 'ref' ]
Save the tag. Now, it’s time for a trigger.
Trigger
You don’t want to fire this Custom HTML tag on every page. Instead, you should activate it only when the URL contains at least one of those query parameters that you want to transfer. Let’s continue our example where I entered these query parameters in the Custom HTML tag:
queryParams = [ 'utm_medium', 'utm_source', 'utm_campaign', 'ref' ]
So, if any of these parameters are in the URL, the Custom HTML tag should fire. Every parameter in the URL should also contain an “equals” sign (=), therefore, our trigger’s condition should be like this:
- Trigger type: DOM ready
- Fire on some DOM Ready Events
- Page URL matches RegEx (ignore case) utm_medium=|utm_source=|utm_campaign=|ref=
What I did here is that I added “=” after every parameter and then separated them with a pipe ( | ), which in Regular Expressions means “OR”. Of course, we could write a more optimized expression, such as:
utm_(medium|source|campaign)=|ref=
…or something even slimmer, but even the first example will work just fine. If you don’t feel confident with regex, just enter all the query parameters you are interested in, add “=” after each one of them, and separate them with a |.
Save this trigger and assign it to the Custom HTML tag.
Let’s Test
Save all changes, and enable Preview and Debug mode. Now head over to the page you’re working on. There are two situations we need to test:
- Make sure that at least one of the query parameters (that you want to transfer) is in the Page URL. In my case, the page URL is www.loremappsum.com?utm_medium=referral&utm_source=promo &utm_campaign=blackfriday2017
- Click the link that contains the domain name you have defined in that custom script I’ve shared in this blog post. In my case, it’s www.appstore.com/loremappsum
- After I’m redirected, the Page URL (appstore.com/loremappsum) should also contain those 3 UTM parameters. The final result in the browser’s address bar should be www.appstore.com/loremappsum?utm_medium=referral&utm_source=promo &utm_campaign=blackfriday2017
Also, do not forget to test the opposite situation when there are no UTMs (or other parameters) in the address bar. In that case, nothing should be appended to appstore.com links.
Oh, there’s also a third case to test. Check at least a couple of other external links (unrelated to appstore.com). They should never contain UTM parameters.
Transfer UTM Parameters: Final words
In this blog post, I’ve explained how to transfer UTM parameters (or any other URL parameters) from one page to another. This is really useful when you have an intermediate landing page that you’re attracting visitors to, and then they have to proceed to the final page, which is stored in another domain.
This is plan B if you cannot implement Cross-domain tracking for some reason.
By default, you’d lose all attribution data, and Google Analytics will display your intermediate landing page as the main referral.
With the script I’ve shared, you can reuse the UTM parameters of the initial landing page and decorate certain links with them.
However, keep in mind that navigation between the intermediary page and the final landing will start a new session (and the same person will still be treated as two different people in your GA reports).
The situation I’ve described is not a very common issue, but it occurs from time to time.

88 COMMENTS
Hi:
Thanks for publishing a wonderful article on UTM passing across URLs. I have been looking for a solution for the problem defined below:
- I provide a link with UTM parameters in emails we send. Whenever a user clicks, he lands on the landing page along with UTM parameters
- From here on, when the user clicks on any of the links within the landing page, he goes to the main website. We want the UTM parameters to be passed on to the main website URLs and from there on, to all the URLs within the website visited by the visitor, ultimately leading to acquiring the UTM values when a form is submitted. This will give us an accurate attribution.
I thought the solution you provided here will work for me. The UTM parameters are not being passed on to the links clicked. Can you please advise how to fix this?
Thanks
RK
Hey, what you need is cookies.
1. Set cookies that contain UTM parameters https://www.analyticsmania.com/post/cookies-with-google-tag-manager/
2. Insert values of those cookies with some simple JavaScript https://www.analyticsmania.com/post/enrich-form-submission-data-with-google-tag-manager/
I also want to use this solution for attributing affiliate conversions in Google Ads. However, wouldn't I need to also have the Google Analytics code on the second domain (appstore.com)?
Hello,
Thank you for this great article! Do you know if this works for AMP containers as well?
Unfortunately, no. AMP GTM containers do not allow to add custom JavaScript (including this script).
Thanks for outlining this solution.
You most likely already addressed this question in a comment above, but I'm curious if this solution would work if you only have access to the final domain in the process?
For example, I'm working on a project where we will most likely have 10 digital media campaigns for 10 different products. Those campaigns will drive to a Product Page (productdomain1.com, productdomain2.com, etc.)
Then in order to purchase Product1 --> productdomain1-10.com will drive to -- > ecommercedomain.com where you can purchase any number of products 1-10.
If I only manage Google Tag Manager for ecommercedomain.com will I be able to apply this solution to determine the UTMs that began the campaign journey?
Thanks!
Rob
Hey, Robert. The answer is no. You won't be able to apply this method.
Hi Julius,
I was wondering if you could help please.
I've followed your steps but the UTM codes are not tracking onto the final website.
So this is the journey in three simple steps:
1) Facebook Ads and Google Ads containing relevant UTM codes
2) links through to a dedicated product landing page and the UTM codes to follow through
3) click a submit button on dedicated product landing page and it takes you to a different domain
Thanks,
Tom
This solution works with links, not forms (and I'm guessing you're working here with forms). In that case, you would need to contact the developer of the form and implement a similar solution in form's code.
Hi Julius, awesome solution. Does it work for payment gateway? If its so, should I check the utms parameters when I come back to order-received page or on the current PV payment gate?
thanks in advanced
It works for anything that is accessed via link click.
Hello Julius,
Thank you for this tutorial. Just wondering if this can work on ecomm process, say you direct a customer on a collection page with UTM, and they navigate through the website, then finally convert. Can I pass those parameters across all pages until they reach checkout and convert?
TA
You don't need that if this is happening on the same domain. GA will automatically keep the traffic source intact.
Hi Julius,
This article is a great find. Thanks for simplifying.
Just have a question as to whether this is best practice for tracking links that might cross multiple domains.
Example:
We are paying for media on a publisher's website, that link will drive to our owned social post, we then want to track whether we had any leads to our owned website from the original publisher's link.
Publisher > Facebook post (owned) > Website (owned) = will we be able to see that the referral came from Facebook but source was the publisher?
Hi, that is impossible to track because you would need to have some tracking code added to Facebook's interface.
Hi Julius
Thanks for the post. I've implemented the code but I'm having some troubles...
My goal is to transfer UTM parameters throughout the site in the following setup:
The visitors enter my website via this link:
mywebsite.com/test?utm_source=newsletter&utm_medium=mail&utm_campaign=062020
They than go to:
mywebsite.com/form/
The parameters aren't transferred from /test to /form when I've implemented the code.
Am I missing something?
Thanks in advance!
The parameters are only transferred if both conditions are met:
1. Link is decorated
2. The link is clicked
Regular navigation does not preserve the parameters. If one the page A, you see the parameters added to the link, then the redirect between the page A and page B is losing those parameters (and you should discuss the fix for that with you developers)
Hi Julius!
Great Post. Is there a way to transfer these UTM parameters from one url to other, in case of multiple redirections through tracker pages(when using third party trackers as well) between the source and the Landing Page?
Hi, no. Javascript in the browser (client-side) cannot help here.
If all the redirects were controlled by you, you could ask a developer/sysadmin to preserve those parameters somehow. But if the server-aide redirects happen and developer cannot help you, you are out of luck.
Ah ok! So I get this script needs to be part of each page that the UTM parameters needs to be transferred to, essentially like a passing the baton kind of situation.
Are there any other options?
Options for what? To overcome those redirects you mentioned? There are no javascript solutions for that (meaning that GTM cannot help). Talk this with your developers, maybe they can offer something on the backend.
First off - this is GREAT. I'm wondering how I address if one of the UTMs is missing? Right now, it will not move ANY over if they do not ALL Exist. I'm looking to pass over what I can vs an all or nothing situation.
Thanks!
I have just updated the code. Now it supports any number of parameters in the URL.
Hi thank you for posting this!
What I am doing is embedding a form into a landing page and using the main landing page to have the UTMS. But when I tried this code it still didnt seem to capture the UTMs. Any ideas?
Thank you!!
Hi, this solution is not built for iframes. Only links are supported.
I had to change one small thing to your script :
{ if (links[linkIndex].href.indexOf(domainsToDecorate[domainIndex]) > -1 && links[linkIndex].href.indexOf("#") === -1)
because it would decorate internal links in the page for example to activate the mobile menu
Good catch! I totally did not think about href with just #. I've updated the code.
Thanks!
Hi!
I need to pass the utm tags on to all the pages on the same domain, can this solution work for that?
Because i have a form that collects that data (via hidden field), so we can know wich constumer came from wich channel, but i still get a lot of "blanks" or direct conversions.
I'll appreciate the help, thanks!!
Yup! This will solve that problem for you. Just remember though, The form they fill out might not be the form / page they entered on. So you'll need to account for that in your reporting.
Hi Julius!
That's a great workaround. Here's one scenario I noticed where the script doesn't work:
User lands on a page with the UTM parameters > Clicks on an internal link on that page > on this second page clicks on a URL that is supposed to be decorated.
As UTMs don't get passed on internally in the URL that probably causes this. And I assume it wouldn't make any sense to implement it internally either?
Best regards,
Heiman
Hi, The script was never meant to persist the data across the pages. You will have to use cookies to enhance the solution by yourself.
Hi Julius.
I found your article very useful and I would like to share the following snippet that allowed me to dynamically obtain all the query parameters.
function getParams() {
var params = [],
searchParams = new URLSearchParams(window.location.search.slice(1));
for(var pair of searchParams.entries()) {
params.push(pair[0]);
}
return params;
}
Best regards,
Amer
First of all, i will like to thanks you for this post, I followed the steps and finally i thought can work, but it only work in preview and debug mode. I don't know the reason why it only works in preview and debug mode but not working in actual.
anyway, i found a quick solution by a wordpress plugin (UTMs Carry Pages)
it will only carry UMT, if other reference, you might need self edit the plugin
If something works only in tpreview mode, it means that you have to publish your changes
I was debugging the page in question with google tag manager and I can see the UTMs being appended to the link in the browser but when I get to the new page the information gets lost. Unfortunately, the checkout page that i'm directed to can't have GTM. Only the direct integration with GA...
Can you help?
Thank you,
Adam
Sounds like that website is losing the UTMs so my guess would be for you to talk with a developer of that website and ask to persist those UTMs in the URL.
Hi Julius,
This is very useful, thank you.
I noticed that when I leave the orignal landing page, UTM parameters get duplicated (i.e."?utm_source=referrer&utm_campaign=tony&utm_source=referrer&utm_campaign=tony&utm_source=referrer&utm_campaign=tony")
Why does this happen?
Hard to tell, maybe something is misconfigured or maybe there is some edge case you're dealing with
I found the problem. In the domain section of the script, I added different pages from the same website (not realizing that if it's the same domain, there's no need to add all the URLs there).
It now works perfectly.
Hi Julius, how are you? Thanks for sharing this code, it was very helpful.
In my case, we direct the users to a page where they need to click on a CTA that opens a lightbox and then select on this lightbox the products that they are looking for, summarising users have click in 2 elements in order to get to the final URL.
Do you have any tips to tweak the code in order to get this code to work on this condition?
This would require involving developers and asking them to build a similar solution tailored to your situation
Hi Julius,
Thank you for this code. It was just what I was needing. I implemented the code on https://www.cloud5.com and it's working if there are URL parameters -- utm_medium, utm_source, etc. -- but if there are no URL parameters, it's adding a '?' at the end of all links on the page.
I think I see how I can fix this in your code, but wondered if you had heard of this before and if you have a solution.
My fix would be to change the decorateUrl function to check if there are any URL params before adding a '?' or '#' to the URL:
function decorateUrl(urlToDecorate) {
var collectedQueryParams = [];
for (var queryIndex = 0; queryIndex 0) {
urlToDecorate = (urlToDecorate.indexOf('?') === -1) ? urlToDecorate + '?' : urlToDecorate + '&';
}
urlToDecorate = (urlToDecorate.indexOf('?') === -1) ? urlToDecorate + '?' : urlToDecorate + '&';
return urlToDecorate + collectedQueryParams.join('&');
}
Hi, that is because you implemented the trigger incorrectly. My code is not thinking of the missing URL parameters because the trigger is doing that. I fire the Custom HTML tag only if UTMs are in the URL.
Hi,
I need one answer from you if any one is aware of this please let me know. How can we pass the single custom query parameters in the url like www.domain.com/?site_refer=test&gclid=test like this.
The same way you do with UTM parameters. Instead of a UTM parameter (that I show in this blog post), include another parameter.
Hello Julius,
This is very helpful and very well detailed Thank you,
Only one question : does this work with subdomains ?
Thanks
GA handles UTMs between subdomains by default
Hey there!
Is it possible to insert this code on a Wordpress page?
Great content, by the way! Will definitely buy your course in the future.
Thanks!
Simple copy paste will probably not work because you need to wait for this code to be fired when the website DOM is loaded. And that requires customization. So use GTM.
Julius, first THANKS for the article. It helped a lot.
Second: I have a new use case that I believe something similar would help.
Problem: I got many article in my blog linking to mi site (example.com/blog/article >> example.com).
I would like to add massively UTM parameters to all this links so I know a certain lead came from the blog.
This UTM could be fixed for all links or maybe add the blog/article url
Do you you imagine something similar could be accomplished?
Thanks for your help
Everything you have belong to the *same domain*. You don't need to persist UTMs in the links. GA will properly track UTMs without this.
Hi Julius,
I implemented the tag and it seems to work only when I move forward to a different domain.
If I click on a link in the landing page which is directing to a page in the same domain, I do not see the UTM parameters in the URL.
Also, if I go to another page in the 2nd domain, it doesn;t forward the UTMs.
Is there a way to solve it?
Include both domains in the Custom HTML tag
Hi Julius, thanks for that :) It works but I've the issue that I get the same parameters twice in the destination URL. Looks like: websiteb.com&?utm_source=example&utm_source=example&utm_campaign=same%20example&utm_campaign=same%20example&utm_source=adwords&utm_source=adwords ... and so on. How can I fix this? Every parameter is appearing twice.
Thanks in advance!
Hi @Yusuf, did you manage to fix this? I have the same problem of all parameters being double on the second page.
This solution is designed to decorate links of external websites, not to preserve utms on the pages of the same website
Julius, something like this modification should work for people that use URL fragments. It basically selects the url without the fragment, decorates, and then re-adds the fragment.
// decorates the URL with query params
function decorateUrl(urlToDecorate) {
var fragment = "";
if (urlToDecorate.indexOf("#") > -1) {
fragment = urlToDecorate.substring(urlToDecorate.indexOf("#"));
urlToDecorate = urlToDecorate.substring(0, urlToDecorate.indexOf("#"));
}
urlToDecorate = (urlToDecorate.indexOf('?') === -1) ? urlToDecorate + '?' : urlToDecorate + '&';
var collectedQueryParams = [];
for (var queryIndex = 0; queryIndex < queryParams.length; queryIndex++) {
if (getQueryParam(queryParams[queryIndex])) {
collectedQueryParams.push(queryParams[queryIndex] + '=' + getQueryParam(queryParams[queryIndex]))
}
}
return urlToDecorate + collectedQueryParams.join('&') + fragment;
}
Thank you Julias, just an FYI - tested this out, and when no UTM's are within the UTL, all URL's thereafter seem to have '?' while others have '?&'. Is there a way to resolve this
Yes, don't fire the Custom HTML tag when there are no UTMs. This was mentioned in the blog post.
My sincere apologies for spelling your name incorrectly, Julius.
I have confirmed the trigger is set to 'Some DOM Ready Events' as per your instructions, while the 'matches regex (ignore case)' is also set, but the question mark still remains.
And you see that the tag does not fire? because if the tag does not fire and you still get the question mark, then the problem is somewhere else (unrelated to the tag).
When you test the setup initially, remove all query parameters from the address and see if that works. Again, it tag does not fire and you still the the "?", the problem is somewhere else
Hi Julius,
I have implemented the above solution and it seems to work on preview and debug mode, but once i published the container with the changes, the UTM parameters aren't getting passed on the actual website when i'm testing on the live version. I have also included the GTM scripts in the website, but for some reason my parameters are still not getting passed. Can you tell me why this could be happening?
Publish the container
Hey thanks for this walk through. Is there any way to exclude a specific link on a page from the initial script. I'd like all links, except to destination x or y, to be appended with the query parameters. For example.
The code is not designed to exclude a certain link. This would require rewriting the code and adding new features (I don't have plans for that at the moment).
Julius,
I have implemented your code on a website that I wish to decorate URLs with incoming UTMs and I have also set a cookie (also using your method) that fires before the decorate URL tag. When I preview the set-up in the Tag Assistant, I can see that if I click on a link, the UTMs follow that link and are appended to URL of the next page, but not the page after that, if I click on another link.
The issue is I want to be able to track form submissions from the footer of any page and have the UTMs be passed through the form at any point. (Obviously the form is on every page in the footer)
However, in the real world, this is not happening. Also strangely, in the Tag Assistant, it says that one certain pages, the GTM container (or any other tags) are not on the site at all.
This is not my website so I have no idea about the server set-up and whether this has anything to do with Tag Assistant's strange behavior.
Do you have ideas why this may be not working when not in Tag Assistant and have you seen Tag Assistant not see a GTM container on a page where the Developer assure me that it is present?
Any help would be appreciated.
Hi, difficult to say without troubleshooting the setup.
But in general, you don't need persist utms across all pages. Thr idea of this solution is to tranfer utms o the next domain, not persist across all pages of the same domain.
Why would I not need to persist UTMs across all pages? If someone fills out the form from a second page and we are collecting UTM through that form, they will be lost if UTMs don't persist. How are you suggesting I track that attribution? Purely through GA4? Thanks
Oh, you want to track that outside of the GA4. In that case, yes, you should persist them. But polluting the page URL with that does not sound like a good idea. Maybe it would be possible for you to store the UTMs in a cookie and then place them in hidden form fields? Like here https://www.analyticsmania.com/post/enrich-form-submission-data-with-google-tag-manager/
Hi Julius,
I have used your script multiple times before and it always worked. However it doesn't work on this URL:
de.insidehub.io/cdn/html/ford-kuga-campaign/ford-kuga-campaign.html?dealerid=10022
I have also tried the following URLs but it didn't work:
- de.insidehub.io
- insidehub.io
- de.insidehub.io/cdn/html/ford-kuga-campaign/ford-kuga-campaign
- insidehub.io/cdn/html/ford-kuga-campaign/ford-kuga-campaign
Thanks for your help,
Marc
There are no links that can be clicked on that page (except the one that is in the checkbox). If there are no links, nothing will be decorated.
Hi Julius,
How can this work on react?
Above script doesn't seem to work for fbclid as one of the query parameter...
Altered the script as below
queryParams = [
'utm_medium', //add or remove query parameters you want to transfer
'utm_source',
'utm_campaign',
'fbclid'
]
// do not edit anything below this line
var links = document.querySelectorAll('a');
Also once I land on another domain post which I proceed ahead with journey then from step 2 to step 3 again the UTM doesn't pass do i need to create trigger for journey 3 as well ?
You *always* have to edit the script and select the parameters that *you want* to transfer. Of course, it did not work with fbclid initially, because it was not included in the list. That's the whole point of the article :) Please pay attention to detail.
And yes, if you want to keep persisting it, your tag must keep firing
Sorry but fbclid is already included in altered query parameters
queryParams = [
'utm_medium', //add or remove query parameters you want to transfer
'utm_source',
'utm_campaign',
'fbclid'
OK, sorry, I misunderstood your initial comment. I just tried the code with the fbclid and it worked. Probably something else is interfering with it on your website. Difficult to say without auditing your setup.
Hi Julius,
and thank you for a great article!
I do however still have a few questions. Let's say that you have a website with a pricing table. When the user clicks on one of the pricing models, it gets sent to a signup page on an app, where you can login with your gmail/outlook account. By implementing this solution, will we be able to see the UTMs in Hubspot when a user has signed in to the app?
Thank you for the great content - I visit your website at least 5 times/ month :D
Hi, I implented this and it does work, but now I wonder what happens to my organic & direct traffic? Will these still be assigned under referral / first domain?
Hi, thanks for the sIn the case of links already with UTM parameters (utm_source & utm_medium), the script is appending UTM parameters along with the existing UTM parameters, ideally it should carry over either of the UTM parameters.
Example: ?utm_source=website&utm_medium=homepage&utm_medium=Try-this&utm_source=open-web.
Is it the expected behavior or something is wrong here?
Hi Julius,
Loved the post.
Do you have any explanation on how to do it for apps? We want to persist the UTMs during the session in the app but I'm unsure on how to do it.
Thank you!
Hi Julius,
Thank you for sharing this info, and really this website in general, it has been extremely helpful over the years!
I perused the comments and didn't see anyone else with this use case, so wondering your thoughts:
user clicks an email link taking them to siteA.com. The URL clicked on is siteA.com/user/login?utm_source=TEST&utm_medium=email&utm_campaign=Super_Sale
on this page is a link to a single-sign-on page hosted on siteB.com, the user can click the link on site A, and get to site B to complete login with the SSO (singe-sign-on). Upon doing this, user is returned to site A. So the path is - clicks email link > lands on site A with UTMs values > clicks link on site A that takes them to site B to sign in (no cross-domain tracking in place) > upon signing in, is returned to site A (without UTMs).
I have access to the GTM and GA for Site A. I think this solution could work for my use case, and I think the domainsToDecorate would be siteA.com, wondering if you could confirm?
To complicate matters, site A actually has links to two different SSO options, but if my assumptions are correct with the use case detail shared, then the solution would work coming back from either of the SSOs...just have a little confusion on whether the domainsToDecorate in the code should be the domain links back to Site A or if they should be the links to the SSOs (seems like it needs to be Site A), but let me know you thought...or you can just say this is way to confusing, and that is okay too ;).
Thanks, and have a great day ahead!
JC
Hi Julius,
Thanks for the excellent guide as always. I've a quick question about the suitability of this solution for adding to a large collection of outbound links.
I have a client who is looking to ensure that their site is getting credit for referrals, and is essentially looking to add source / medium to all outbound links on the site.
There are hundreds of domains being used here - so I'm wondering if there's a way to configure the domainsToDecorate array to cover a range (e.g. any outbound).
Many thanks for any help!
Conor
Hi Julius,
As always, this is incredibly helpful content. I am trying to persist UTM parameters between two domains, however each has a different GTM container installed on it. Is it possible to apply this solution in my case, and if so, which container should I add this tag too - the 'sending' site/container, or the 'receiving' site/container?
Thanks so much for sharing your wisdom!
Caitlin
Hi Julius,
On my client’s website, when a user goes from the checkout page to the payment gateway and then returns to the thank-you page, the purchase event fires. The problem is that in GA4 exploration reports, the purchase event shows the payment gateway domain as the source instead of the original source. How can I fix this so that the original attribution stays intact?