Solved! Go to Solution.
Hi,
I have used this code in Marketo Landing Page. It capture's the UTM parameters and carries to next page successfully.
Their is one challenge with this code. In my Landing Page, I have a Tel Link <a href="tel: + 56-3121-9090">Call + 5-3121-9090</a>
The code also puts UTM after this Telephone Link.
How can I ignore this link?
Regards
Raj
That code is far too verbose for this task, in addition to being buggy.
Switch to this (it has zero dependencies on other scripts):
(function(){
const arrayify = getSelection.call.bind([].slice);
const appendableSearch = document.location.search.substring(1);
if(appendableSearch){
arrayify(document.links)
.filter(function(link){
return /https?/.test(link.protocol) && !/^#/.test(link.getAttribute("href"));
})
.forEach(function(httpLink){
httpLink.search += (httpLink.search ? "&" : "") + appendableSearch;
});
}
})();
By filtering non-http(s) links and local jump links, it ensures only http links will be decorated.
Hi Sanford,
Your this script worked very well for us. Thank you for sharing.
Based on your below script, I made a small tweak to fit this on mailto links, but the problem is, it is not copying all utms but just the first utm and leaving all other utm parameters.
The change made by me in your code is highlighted in bold commented inline.
Can you please help to fix the code so it can carry all utm's to body of mailto:
<span style="color: #00a4de;"><a href="mailto:${SectionSupportContact2}?subject= Please do not Modify the First line in Email Body&body=" style="font-weight: 600;color:rgb(0,164,222);">${SectionSupportContact2}</a></span>
<!-- Carrying UTM's Code in Mailto links -->
<script>
(function() {
const arrayify = getSelection.call.bind([].slice);
const appendableSearch = document.location.search.substring(1);
if (appendableSearch) {
arrayify(document.links)
.filter(function(link) {
// changed “https?” to “mailto?”
return /mailto?/.test(link.protocol) & !/^#/.test(link.getAttribute("href"));
})
.forEach(function(httpLink) {
httpLink.search += (httpLink.search ? "&" : "") + appendableSearch;
});
}
})();
</script>
<!-- End Carrying UTM's Code -->
We place email ids on our PPC landing pages. When user clicks on email, he lands up on email client. User posts the email to us, but we do not know from which PPC campaign the request has come. So we want to capture the campaign name from UTM parameters and post in body content.
Thank you very much Sanford.
This code worked, it removed UTM's from Tel link and applied to rest of HREF links.