Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 like to present a thank you on all the viewers visit if they've 1+ the page.

like image 943
Some Guy Trying To Do Math Avatar asked Oct 10 '22 14:10

Some Guy Trying To Do Math


1 Answers

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");
  }
}
like image 101
Mridul Kashatria Avatar answered Oct 14 '22 01:10

Mridul Kashatria