• my lawer said i need to add this code, so the visitors can opt-out.
    do you also support this code? i have premium better-analytics.

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    <script>
    // Set to the same value as the web property used on the site
    var gaProperty = 'UA-gdsjdfjhsgdjlf';
    
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', gaProperty]);
    _gaq.push(['_gat._anonymizeIp']);
    _gaq.push(['_trackPageview']);
    
    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
    
    // 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>
    <script>
    jQuery(document).ready(function(){
    
    jQuery('#GAOptOut').click(function() {
        gaOptout();
        GAOptOutFeedback ();
    })
    
    if (document.cookie.indexOf(disableStr + '=true') > -1) {
        GAOptOutFeedback ();
    }
    
    function GAOptOutFeedback () {
        jQuery('#GAOptOutBr').before(navigator.appName+'-');
        jQuery('#GAOptOutDom').after(': <a href="'+window.location.origin+'">'+window.location.origin+'</a>');
        jQuery('#GAOptOutFeedback').remove();
        jQuery('#GAOptOut').after('<span id="GAOptOutFeedback" style="color:#FF0000"> (Stand: Opt-Out-Cookie ist gesetzt)</span>');
    };
    
    });
    </script>

    https://ww.wp.xz.cn/plugins/better-analytics/

Viewing 1 replies (of 1 total)
  • Plugin Author digitalpoint

    (@digitalpoint)

    That code is for the deprecated/legacy Google Analytics library… but the general idea is still the same. Ultimately you want to set the variable like so on a page where the user has opted out:

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

    You can find details about it here: https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out

    Assuming that the rest of the code is working for your site (it’s going to be specific to your site), you probably could just remove the part that attempted to insert the Google Analytics tracking code and it should still work as long as it’s in your page header. Something like so:

    <script>
    // 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>
    <script>
    jQuery(document).ready(function(){
    
    jQuery('#GAOptOut').click(function() {
        gaOptout();
        GAOptOutFeedback ();
    })
    
    if (document.cookie.indexOf(disableStr + '=true') > -1) {
        GAOptOutFeedback ();
    }
    
    function GAOptOutFeedback () {
        jQuery('#GAOptOutBr').before(navigator.appName+'-');
        jQuery('#GAOptOutDom').after(': <a href="'+window.location.origin+'">'+window.location.origin+'</a>');
        jQuery('#GAOptOutFeedback').remove();
        jQuery('#GAOptOut').after('<span id="GAOptOutFeedback" style="color:#FF0000"> (Stand: Opt-Out-Cookie ist gesetzt)</span>');
    };
    
    });
    </script>

    Either way, the goal is for your site to have the the window[‘ga-disable-UA-XXXXX-Y’] variable set to true for people that opted out. But how that’s implemented (as far as a prompt for the user) it ultimately up to the site owner.

Viewing 1 replies (of 1 total)

The topic ‘opt out for EU implementation please’ is closed to new replies.