javascript Google Analytics设置尊重navigator.doNotTrack。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Google Analytics设置尊重navigator.doNotTrack。相关的知识,希望对你有一定的参考价值。

// Setup Google Analytics, but not if user has specified that they don't want to be tracked.
(function (dnt, cookieDomain) {
    var scriptTag, hostRe = new RegExp(cookieDomain.replace(".", "\\.") + "$");
    if (dnt !== "yes" && dnt !== "1") {
        window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments) }; ga.l = +new Date;
        ga('create', 'YOUR-ID-HERE', hostRe.test(location.host) ? cookieDomain : "auto");
        ga(function (tracker) {
            tracker.set("appName", "Your app name here");
            tracker.send('pageview');
        });

        // Add the script tag.
        scriptTag = document.createElement("script");
        scriptTag.src = "//www.google-analytics.com/analytics.js";
        scriptTag.async = true;
        document.head.appendChild(scriptTag);
    }
}(navigator.doNotTrack || navigator.msDoNotTrack || null, "wsdot.wa.gov"));

以上是关于javascript Google Analytics设置尊重navigator.doNotTrack。的主要内容,如果未能解决你的问题,请参考以下文章

Javascript - GA 和 Adwords

整合谷歌分析功能

javascript Javascript:Google Analytics Snipper + Google Analytics JS日志记录

Google 跟踪代码管理器使用沙盒 JavaScript?

javascript Google Analytics事件跟踪Javascript

javascript [userscript] [Google]修复Google搜索标签的顺序