Pass current UTM parameters to the next page
Hi all! We've seen this question come up a few times: is it possible to make UTM parameters persist across page views? UTM parameters by design are only displayed on the first page that a contact visits – however, if you link from one Act-On Landing Page to another, or from a Landing Page to your corporate website, it may be helpful to push this data to the next page that your visitor goes to.
Please note that since this falls into the realm of custom code, our support team can't troubleshoot issues with this solution. However, if you have questions or comments about it you can feel free to comment here!
If you paste this code into the Javascript section of your Landing Page, all links should be updated to carry over any existing UTM parameters:
var currentURL = window.location.href;
if (currentURL.includes("?")) {
var currentUTMs = currentURL.split('?').pop();
var allLinks = document.getElementsByTagName("a");
for (var i = 0; i < allLinks.length; i++) {
if (allLinks[i].href.includes("?")) {
allLinks[i].href += "&" + currentUTMs;
}
else {
allLinks[i].href += "?" + currentUTMs;
}
}
}
Comments
1 comment
Awesome hack Chris!
Please sign in to leave a comment.