Javascript:如何阻止谷歌分析? [英] Javascript: How to block google analytics?

查看:21
本文介绍了Javascript:如何阻止谷歌分析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Open Web Analytics 构建一个网站.

I'm building an website with Open Web Analytics.

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

My host is an free host and automatically insert Google Analytics.

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

I want remove Google Analytics because it forces to track users.

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

I inserted jQuery based node remove code before ga but it still gets loaded.

像这样:

<!-- 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();
        }
    });
});

是否有任何解决方案可以实现这一目标?

Is there any solution to achieve this?

推荐答案

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

You can disable their Google Analytics account from tracking your website by defining the following global variable:

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

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

Change UA-XXXXXX-Y for the Account number they use.

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

这篇关于Javascript:如何阻止谷歌分析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆