Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable cookies set by the google plus one button

When I place the following code on my site for a nice standard +1

<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone"></div>

<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
  window.___gcfg = {lang: 'nl'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>

It does something I do not want.

Without this code I only have my own phpsessid which is needed to have my site functioning.

With this code the following cookies are dropped from the domain plusone.google.com

Google Plus one drops a lot of cookies!

Now, when looking at the expiration date, somewhere in 2014, 2022, 2013... they will live a very long long time.

Point is, nowhere is documentation readily accessible how to disable the placement of cookies by google+1 button, i've done my best to look, even read a lot of stack overflow posts in the hope to find something related.

I did however find how to disable cookies for analytics in my quest(hurray!) but now I need to find a way, javascript option or something to tell plusone not to drop cookies(long live dutch/european cookielaw)

The Question: Has anyone ever encountered the documentation/option to tell +1 button not to drop cookies?

like image 991
Tschallacka Avatar asked Oct 18 '12 13:10

Tschallacka


People also ask

What are cookies in Google?

Cookies are small pieces of text sent to your browser by a website you visit. They help that website remember information about your visit, which can both make it easier to visit the site again and make the site more useful to you.


1 Answers

It seems the EU cookie law is far more unwieldy than it seemed at first glance :\

There does not seem to be a way to block the cookies set by Google's +1 button. The user might block third-party cookies in their preferences, but you as a site developer cannot indicate that your specific site disallows cookies from third parties, and the actual cookies are set on a different domain, so your Javascript cannot interfere with that either.

The directive allows you to keep essential cookies, so you can store a cookie for the purpose of recording the visitor's acceptance or rejection of cookies. You could ask for permission once if that cookie is not set. You should proceed with initializing the +1 buttons only when the visitor gives you permission to track third-party cookies or you already have their permission recorded in the cookie; otherwise you should skip the +1 button initialization code.

Rough incomplete example (actual cookie manipulation left out):

(function() {
    var allowed = getCookie('allowCookies');
    if (allowed === undefined) {
        allowed = confirm('Allow cookies?');
        setCookie('allowCookies', allowed? 1: 0);
    }
    if (allowed) {
        // initialize +1 buttons:
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);

        // initialize any other third-party tools that might set cookies ...
    }
})();
like image 120
lanzz Avatar answered Sep 30 '22 18:09

lanzz