Link to home
Start Free TrialLog in
Avatar of Dean OBrien
Dean OBrienFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Google position checker

Experts,

I have a web design / development company based in the uk, and as such was hoping to add a tool to our site that would allow our visitors to check the current position of there website within Google. I believe this would be of great interest to users and would also add value to our site.

I have seen a number of scripts about the web that claim to give accurate results, however upon closer inspection they dont appear to be that accurate.

I was wondering if anyone could recommend a reliable and accurate PHP based script that would perform this operation? The last one i tried was:

http://bohuco.net/blog/2011/01/new-google-ranking-checker-with-locale-support/

But this fails on a few searches which i know to be accurate.

Any advice would be greatly appreciated.

Regards
Easynow
Avatar of DrDamnit
DrDamnit
Flag of United States of America image

While I know you want to add value to your site, there is only one, accurate, way to do this as far as I know: use google webmaster tools. Webmaster tools will give you a list of all the queries that someone uses to get to a site, and then tell you the number of impressions in search you get, the click through rate, and a whole boatload of data to help you optimize your site and your pages.

You could, conceivably, access this through their API with a script, but the other site would need to have webmaster tools enabled.

Otherwise, you would need a script that scraped the Google search results, and went page by page to show the current placement. That would look cool on a site, but (unfortunately) would not give accurate results because your placement will change by the hour as Google updates the SERPs. So, the only real, true data that you can count on comes from Webmaster Tools.
Avatar of Dean OBrien

ASKER

Hey DrDamnit,

Thanks for the reply.

I think you slightly misunderstood my meaning. I use webmaster tool extensively to monitor the performance of my own site against various keywords. What i am after is the functionality for a user to enter a keyword and their own website to see where there own site currently ranks.

I have found one site which appears to do this accurately (correctly ranks my site www.suremedia.co.uk #56 for "website design"):
http://www.yellowcircle.co.uk/position/google-position-checker.php

The function for the above is hidden behind the php files.

I have tried two different approaches:

The first appears to scrape googleapi.com and has changable results:
http://www.suremedia.co.uk/google-position-checker.php

The second appears to check the correct www.google.co.uk and gives a very accurate result, but only flags if the result is in page 1,2,3 etc rather than the actual position. Each time this returns the full page to parse. So i guess it could be extended to parse the page for the position within.
http://www.suremedia.co.uk/google/index.php

I guess i could email the owner of the site, but not sure how likely they are to share :)

Cheers
Easynow
OK. Figured it out. By mistake.

When I went to the site that you gave me, I accidentally put your website in and searched for "web design" instead of "website design".

The error it gave me said that I was not listed in the top 100 results. That clued me into what they are using:

They are using this:
http://code.google.com/apis/customsearch/v1/overview.html

It returns the search results in JSON / ATOM formats, which is notoriously easy to parse.
Hey DrDamnit,

Thanks again for looking. I tried the google groups code but got numerous errors:
http://www.suremedia.co.uk/google-group.php

I have also seen alot of threads about the json/atom approach and the consensus is that they return significantly different results to normal google result pages.

I have a working script that is almost perfect... there is just one very peculiar thing happening that i wondered if you could comment on?

The attached code below sits at:
http://www.suremedia.co.uk/google.php

The script works well for terms i know we rank well for i.e. "newcastle website design" #1 :). However, when i do the search mentioned for "website design"  it fails.

Now that would be fine and i would put it down to regions etc, however, if i explicitly set the search page to page 5 of google (see code), rather than allow the code to dynamically create the EXACT same string, then the script works and returns TRUE and the correct result!

Its bizzare, because the code obviously works as it returns correct results for the other keywords.

Any suggestions on this would be greatly appreciated.
Regards
Easynow
<html><body><form action="google.php" method="GET"><input type="text" id="thequery"  name="thequery" size="100"><input type="submit"></form>

<?php
function google_position ($searchquery) {
	$searchurl = "www.suremedia.co.uk";
	if(!empty($searchquery) && !empty($searchurl))
	{
		$query = str_replace(" ","+",$searchquery);
		$query = str_replace("%26","&amp;",$query);

		$total_to_search = 100;

		$hits_per_page   = 10;

		$position      = 0;

		for($i=0;$i<$total_to_search;$i+=$hits_per_page)
		{
			$filename = "http://www.google.co.uk/search?q=".$query."&amp;hl=en&amp;start=".$i."";

				// THIS RETURNS TRUE IF SET, BUT NOT IF BUILT USING ABOVE CONCATENATION ->> 
				//$filename = "http://www.google.co.uk/search?q=website+design&hl=en&start=50";
			
// ADDITIONAL (JUST CHECK IF IN THE PAGE)//
echo "<p>".$filename."</p>";
$domain= "www.suremedia.co.uk";
$page = file_get_contents($filename);
//echo "<iframe width='300' height='300'>".$page."</iframe>";
if (preg_match("/$domain/i", $page)) {
			echo "<p>TRUE</p>";
} else {
			echo "<p>FALSE</p>";
}
///////////////////////////////////////////


					$var = file_get_contents($filename);
					// split the page code by "<h3 class" which tops each result
					$fileparts = explode("<h3 class=", $var);
					for ($f=1; $f<sizeof($fileparts); $f++) {
						//echo $position;
						$position++;
						if (strpos($fileparts[$f], $searchurl)) {
							return $position;
						}
					}
		}
	}

}

$thesearchquery = $_GET['thequery'];
echo $thesearchquery;
$result = "100";
$result = google_position($thesearchquery);
echo "RESULT = ".$result;
?>

</body></html>

Open in new window

What you're probably seeing is the difference between the code performing a basic search, and what the other code does with a location based search. When you search or scrape, Google knows where you are. When you go via the API, it no longer has that information, which will affect search results.
Both methods i mention use the exact same method to pull the page data:

$page = file_get_contents($filename);

The only difference between the two is that the first is a set of concatenated variables to form a string, and in the second instance the string is defined exactly.

option 1) $filename = "http://www.google.co.uk/search?q=".$query."&amp;hl=en&amp;start=".$i."";

option 2) $filename = "http://www.google.co.uk/search?q=website+design&hl=en&start=50";

Surely they should return the same result?
ASKER CERTIFIED SOLUTION
Avatar of DrDamnit
DrDamnit
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for looking.
Easynow