Javascript:如何阻止谷歌分析?

时间:2013-12-02 08:38:07

标签: javascript jquery google-analytics

我正在使用Open Web Analytics建立一个网站。

我的主机是免费主机,会自动插入Google Analytics。

我想删除Google Analytics,因为它会强制跟踪用户。

我在ga之前插入了基于jQuery的节点删除代码,但它仍然被加载。

像这样:

<!-- Remove Google Anaylitics and include OWA. -->
<script src="js/RemoveGA.js"></script>
<script src="js/OWA.js"></script>

//RemoveGA.js
$(document).ready(function () {
    $("script").each(function () {
        if (this.innerHTML.length > 0) {
            var googleScriptRegExp = new RegExp("var gaJsHost|var pageTracker");
            if (this.innerHTML.match(googleScriptRegExp) && this.innerHTML.indexOf("innerHTML") == -1)
                $(this).remove();
        }
    });
});

有没有解决办法来实现这个目标?

1 个答案:

答案 0 :(得分:2)

您可以通过定义以下全局变量来禁用其Google Analytics帐户跟踪您的网站:

window['ga-disable-UA-XXXXXX-Y'] = true;

将UA-XXXXXX-Y更改为他们使用的帐号。

来源:https://developers.google.com/analytics/devguides/collection/gajs/#disable