Adding Google Anyltics code and adding option to disable it:
<!-- Google Analytics -->
<script async src='//www.google-analytics.com/analytics.js'></script>
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-xxxxxx-x', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
//HTML LINK
<a class="ga-disable" href="#">Link</a>
<a href="javascript:gaOptout()">Link</a>
// Set to the same value as the web property used on the site
var gaProperty = 'UA-xxxxxx-x';
// 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;
alert('Das Tracking durch Google Analytics wurde in Ihrem Browser für diese Website deaktiviert.');
}
jQuery(document).ready(function($) {
$(".ga-disable").click(function(event) {
event.preventDefault();
gaOptout();
});
});