我设置了一个 Google 标签来检查我的用户正在搜索的邮政编码。我使用 Custom Javascript 变量类型来设置这个变量。
function() {
var url = new URL({{Page URL}});
var zip = url.searchParams.get("zip");
return (zip);
}
当用户转到包含“locations.aspx?term”的地址时,我触发了标记。这是一个示例网址:
https://www.example.com/locations.aspx?term=64544&zip=64160&lat=43.3414758&lng=-0.1509269000000586
我应该寻找什么来调试为什么 50% 的返回在 Google Analytics 中(未设置)?另一半的返回只是很好。
谢谢!
最佳答案
你的JS有两个问题:
- Internet Explorer 不支持
- 如果 url 没有带有
zip
参数的 querstring,它将返回null
。会导致(not set)
最好的方法是:
function () {
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || "";
}
var zip = getURLParameter('zip');
return zip;
}
关于javascript - Google 跟踪代码管理器 - 有时未在自定义 Javascript 上设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45378562/