Javascript: How to block google analytics?

天涯浪子 提交于 2019-12-11 19:03:44

问题


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?


回答1:


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.com/analytics/devguides/collection/gajs/#disable



来源:https://stackoverflow.com/questions/20323931/javascript-how-to-block-google-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!