2017-06-28 11 views
0

私のコードでは、Googleアナリティクスへのオプトインは許可されません。 GoogleアナリティクスのCookieを再度オプトインに設定する方法や、オプトアウトの状態を解除して再度オプトインする方法は何ですか?Googleアナリティクスのオプトインはオプトアウトを維持します

Googleアナリティクスデバッガ

Initializing Google Analytics. 
Running command: ga("create", "UA-XXXXXXX-2", "electronics.semaf.at") 
Creating new tracker: t0 
Aborting cookie write: User has opted out of tracking. 
Aborting cookie write: User has opted out of tracking. 
Running command: ga("set", "anonymizeIp", true) 
Running command: ga("set", "forceSSL", true) 
Running command: ga("send", "pageview") 
User has opted out of tracking. Aborting hit. 
Registered new plugin: ga(provide, "render", Function) 

私のJavascriptのコードは、オプトインとオプトアウトするには:

<script> 
     var gaProperty = 'UA-XXXXXXX-2'; 
     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; 
     location.reload(true); 
     } 
     // Opt-in function 
     function gaOptin() { 
     document.cookie = disableStr + '=false; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; 
     window[disableStr] = false; 
     location.reload(true); 
     } 
</script> 
<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','https://www.google-analytics.com/analytics.js','ga'); 
    ga('create', 'UA-XXXXXXX-2', 'auto'); 
    ga('set', 'anonymizeIp', true); 
    ga('set', 'forceSSL', true); 
    ga('send', 'pageview'); 
</script> 

これはオプトインする部分を、それかopt-アウト

答えて

1

これを試してみてください:

// Opt-in function 
    function gaOptin() { 
    document.cookie = disableStr + '=false; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; 
    window[disableStr] = false; 
    location.reload(true); 
    } 

あなたがこれを読んで削除するクッキーについての詳細情報が必要な場合: w3schools Cookies

関連する問題