Is there a easy way to tell if a user has google 1+ a URL

前端 未结 1 2043
抹茶落季
抹茶落季 2021-02-10 04:48

Let\'s say I have a webpage and I have added the 1+ button.

Is there a good way to tell if the user has already pressed the 1+ button on a previous visit.

I\'d

相关标签:
1条回答
  • 2021-02-10 05:48

    In the +1 API there is a callback method which you can use to trap +1's

    A strategy would be to trap these calls and store a cookie on the browser. Next time the user comes, you can check the cookie and show the thanks message.

    From the docs

    callback The identifier for a function in the global namespace

    Called after the user has clicked the +1 button. The callback function may accept a JSON object which will be of the form, {"href": "http://www.example.com/", "state": "on"}. Where href is the URL of the +1 and state is on for a +1 and off for the removal of a +1.

    A quick example:

    function plus1Callback(params)
    {
      if(params.state == "on"){
        setCookie("hasplus1", "true");
      }
    }
    
    function checkHasPlus1()
    {
      var hasplus1=getCookie("hasplus1");
    
      if (hasplus1!=null && hasplus1!=""){
        alert("Thanks for your +1");
      }
    }
    
    0 讨论(0)
提交回复
热议问题