最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Javascript: How to block google analytics? - Stack Overflow

programmeradmin0浏览0评论

I'm building an website with Open Web Analytics.

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

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

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

Like this:

<!-- 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?

I'm building an website with Open Web Analytics.

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

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

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

Like this:

<!-- 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?

Share Improve this question edited Nov 4, 2018 at 2:51 Tatsuyuki Ishi asked Dec 2, 2013 at 8:38 Tatsuyuki IshiTatsuyuki Ishi 4,0414 gold badges30 silver badges42 bronze badges 2
  • 4 Best solution: switch hosts. (It's likely that the TOS prevents you from messing with their GA code.) – JJJ Commented Dec 2, 2013 at 8:56
  • Check out why your hosts integrate Analytics, maybe they want to provide analytics data to you, not for themselves - which would not be all that different from using owa. Plus you could place a link to the opt-out tool prominently on your homepage (tools.google./dlpage/gaoptout). All in all I'd agree with Juahana that switching hosts is the best option. – Eike Pierstorff Commented Dec 2, 2013 at 10:00
Add a ment  | 

1 Answer 1

Reset to default 5

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

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

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

Source: https://developers.google./analytics/devguides/collection/gajs/#disable

发布评论

评论列表(0)

  1. 暂无评论