cookiessettingscookieless

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?


Solution

  • I have coded up a permissions based workaround but I still find it far from ideal because I have to bug the user for permission when they click, but it's better than nothing.

    I still need a way to stop google from dropping unwanted cookies. There is no need to track users with so many cookies or any cookies at all in my opinion.

    This code makes an user click the link, when they click it they get asked if they want to show the button and what the consequenses are of that descision.

    My example code: http://jsfiddle.net/CADjN/3/

    Live demo https://www.ortho.nl/orthomoleculaire-bibliotheek/artikel/8091/Langer-leven-met-vitamine-D

    <script type="text/javascript"> 
    // Function to set the cookie plusone.
    function setCookie()
        {
        domain = "www.mysite.com";
        c_name="plusone";
        value="yes";
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + 365);
        var c_value=escape(value) + "; expires="+exdate.toUTCString()+';domain='+domain+';path=/';
        document.cookie=c_name + "=" + c_value;
        }
    // Function to see if our plusone cookie exists and has value yes
    // Returns true when the cookie is set, false if isn't set.
    function getCookie()
        {
        var i,x,y,ARRcookies=document.cookie.split(";");
        for (i=0;i<ARRcookies.length;i++)
            {
            x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
            y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
            x=x.replace(/^\s+|\s+$/g,"");
    
            if (x.indexOf("plusone") != -1)
                {
            if(unescape(y)=="yes")
            {
            return true;
            }
        else
            {
            return false;
            }
            }
        }
    }
    // Load the plusone module but first ask permission
    function loadplusone(thelink) 
        {   
        // Cookie hasn't been set
        if(!getCookie())
            {
                // Get permission
            if(window.confirm("If you wish to 'plusone' this page we need to load a special button from Google.com.\n\nWith this button Google will place some cookies on your computer. Google uses these cookies for statistics and maintaing your login status if you have logged in with Google.\n\nDo you consent to loading the button and the placement of cookies by Google?\n\nIf you agree this website will place a cookie with a year lifetime on your computer to remember this and the plusone button will be loaded on every page where the plusone button is present on this site."))
                {
                        // set cookie, load button
                setCookie();
                var jsnode = document.createElement('script');   
                jsnode.setAttribute('type','text/javascript');   
                jsnode.setAttribute('src','https://apis.google.com/js/plusone.js');   
                document.getElementsByTagName('head')[0].appendChild(jsnode);   
                document.getElementById(thelink).innerHTML = ''; 
                }
            }
        // cookie has already been set, just load button.
        else
            {
            var jsnode = document.createElement('script');   
            jsnode.setAttribute('type','text/javascript');   
            jsnode.setAttribute('src','https://apis.google.com/js/plusone.js');   
            document.getElementsByTagName('head')[0].appendChild(jsnode);   
            document.getElementById(thelink).innerHTML = ''; 
            }
        }
        </script>
        <!-- Where the plusone button should go this piece of code should be placed -->
        <a id="plus1" href="javascript:loadplusone('plus1')">Show Google +1</a><g:plusone></g:plusone>
        <!-- This should be placed below the above code or in the onload event of the document -->
        <script type="text/javascript">
        if(getCookie())
            {
            var jsnode = document.createElement('script');   
            jsnode.setAttribute('type','text/javascript');   
            jsnode.setAttribute('src','https://apis.google.com/js/plusone.js');   
            document.getElementsByTagName('head')[0].appendChild(jsnode);   
            document.getElementById('plus1').innerHTML = ''; 
            }
        </script>