Reputation: 63
How can I keep google's ads gclid parameter when the visitor goes from one page to another?
E.g. The visitor comes from google with the paramenter and lands on page a (www.example.com/a/?gclid=abcd123) When he goes on a another page (www.example.com/b) the parameter should be kept as so (www.example.com/b/?gclid=abcd123)
ps on wordpress
Upvotes: 2
Views: 2096
Reputation: 1513
You can maintain query params across website using Google Tag Manager.
<script type="text/javascript">
(function() {
var utmInheritingDomain = "yourdomain.com", // REPLACE THIS DOMAIN
utmRegExp = /(\&|\?)utm_[A-Za-z]+=[A-Za-z0-9]+/gi,
links = document.getElementsByTagName("a"),
utms = [
"gclid={{URL - gclid}}" // IN GTM, CREATE A URL VARIABLE gclid
];
for (var index = 0; index < links.length; index += 1) {
var tempLink = links[index].href,
tempParts;
if (tempLink.indexOf(utmInheritingDomain) > 0) { // The script is looking for all links with the gclid
tempLink = tempLink.replace(utmRegExp, "");
tempParts = tempLink.split("#");
if (tempParts[0].indexOf("?") < 0) {
tempParts[0] += "?" + utms.join("&"); // The script adds gclid parameter to all links with the domain you've defined
} else {
tempParts[0] += "&" + utms.join("&");
}
tempLink = tempParts.join("#");
}
links[index].href = tempLink;
}
}());
</script>
You can find detailed steps here
Upvotes: 1