문제

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?

도움이 되었습니까?

해결책 2

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>

다른 팁

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 ...
    }
})();

One thing i don't like about social sharing buttons is There javascript manipulation & the waste speed

So almost every time when i use Static Button so you should also use static one

Otherwise : a work around for this problem is to unset the Cookies after the page loaded

using onLoad() & unset it

what do you thnik ?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top