gpt4 book ai didi

regex - 从Google Analytics(分析)中删除空查询字符串参数

转载 作者:行者123 更新时间:2023-12-03 16:00:57 25 4
gpt4 key购买 nike

我想知道是否有人知道如何从Google Analytics(分析)中删除一个空的查询字符串参数?

URL的示例为:http://www.domain.com/index.asp?a=test&b=test&c=&d=test

在此示例中,我希望Google Analytics(分析)过滤掉“ c”,因为它为空。

感谢您提供的任何帮助!

最佳答案

花费@ user1494396;重构您的异步跟踪代码以通过正则表达式传递页面名称,如下所示:

(function (window) {
function cleanQs() {
if (!window.location.search) {
return window.location.pathname;
}
var locSearchArr = window.location.search.match(/[^\=\&\?]+=[^\=\&\?]+/g);
var locPathName = window.location.pathname;
if (locSearchArr && locSearchArr.length > 0) {
locPathName += "?" + locSearchArr.join("&");
}
return locPathName;
}

var _gaq = window._gaq || (window._gaq = []);
window._gaq.push(['_setAccount', 'UA-XXXXX-X']);
window._gaq.push(['_trackPageview', cleanQs()]);
})(this);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


看到:


Google's Async Tracking Code Documentation有关基于代码的更多信息
JSFiddle Demo of this code

关于regex - 从Google Analytics(分析)中删除空查询字符串参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12860769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com