篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Google Analytics跟踪代码相关的知识,希望对你有一定的参考价值。
/*
Opt-out link for google anayltics
Source: http://webgilde.com/en/analytics-opt-out/
Add opt-out link to your page
<a href="javascript:gaOptout()">Click here to opt-out of Google Analytics</a>
*/
<script>
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXX-Y';
// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}
// Opt-out function
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
}
</script>
<!--
Read: http://www.datenschutzbeauftragter-info.de/fachbeitraege/google-analytics-datenschutzkonform-einsetzen/
1. Add anonymize_ip parameter to tracking code:
-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'example.com');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
<!--
change the settings in "create" for each individual account.
2. Set option for opt-out cookie on your privacy/datenschutz page.
-->
<script>
var gaProperty = ‘UA-XXXXXX-Y’;
var disableStr = ‘ga-disable-’ + gaProperty;
if (document.cookie.indexOf(disableStr + ‘=true’) > -1) {
window[disableStr] = true;
}
function gaOptout() {
document.cookie = disableStr + ‘=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/’;
window[disableStr] = true;
}
</script>
<!--
Read about the opt-out code: https://developers.google.com/analytics/devguides/collection/gajs/?hl=de#disable
-->
以上是关于html Google Analytics跟踪代码的主要内容,如果未能解决你的问题,请参考以下文章