如果要在加载页面时为用户存在某个Cookie(ab_test = true),则我想使用Google跟踪代码管理器向页面URL添加参数(?test)。
我想我需要一些自定义的javascript。
有什么想法吗?谢谢!
答案 0 :(得分:0)
嗨,我已经测试了以下代码,看来这就是您想要的。
<script>
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
var cookieValue = getCookie("ab_test");
if(cookieValue === "true"){
window.history.pushState('page', 'Title', '?test');
}
</script>