当访问者从一页转到另一页时,如何保留google的ads gclid参数?
例如访客来自Google,带有参数项,并登陆到页面a(www.example.com/a/?gclid=abcd123) 当他进入另一页(www.example.com/b)时,应保持原样(www.example.com/b/?gclid=abcd123)
wordpress上的ps
答案 0 :(得分:0)
您可以使用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>
您可以找到详细的步骤here