logo logo

Google SERP checker using Google AJAX Search API‏

A warning before you proceed: Google hate you when you are using its API for automated position tracking

So.. Google provide us Google AJAX Search API which we can use to fetch Google search result. The bad news is that it only provide maximum 64 search result.
More info about this API, read here: http://code.google.com/apis/ajaxsearch/documentation/reference.html

We’ll use this API to track our domain position on Google SERP for certain keywords, it’s useful to track your SEO progress.

Full main function source code here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
error_reporting(E_ALL^E_NOTICE);
 
//helper function -- file_get_contents using curl
function file_get_contents_curl($url, $referer='', $ua='')
    {
    $ch=curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    if ($referer!='') {
        curl_setopt($ch, CURLOPT_REFERER, $referer);
    }
 
    if ($ua!='') {
		curl_setopt($ch, CURLOPT_USERAGENT, $ua);
	}
 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $data=curl_exec($ch);
    curl_close ($ch);
 
    return $data;
    }
 
//this is the main function
function g_serp($keyword, $url, $lang='en')
{
	$g_url='http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='.urlencode($keyword).
			'&rsz=large&userip='.$_SERVER['REMOTE_DDR'].'&hl='.$lang;
 
	for ($i = 0; $i < 64; $i+=8)
	{
		$start=$i;
 
		$referer='http://localhost/'; //change this into your real domain
		$rawdata=file_get_contents_curl($g_url.'&start='.$start, $referer, $_SERVER['HTTP_USER_AGENT']);
		$decoded=json_decode($rawdata, TRUE); //decode as assoc array
 
 
		if (is_array($decoded['responseData']['results']))
		{
 
			$pos = $start;
			foreach ($decoded['responseData']['results'] as $result) {
				if (substr_count(strtolower ($result['url']), $url))
				{
					$res['position']=$pos+1;
					$res['title']=$result['titleNoFormatting'];
					$res['url']=$result['unescapedUrl'];
 
					return $res;
				}
 
				$pos++;
			}
		}
	}
}

The main function is g_serp() and I create one function helper file_get_contents_curl(). The main function use json_decode(), so, your PHP version must be at minimum 5.2. The function designed to stop at first domain match. You can modified yourself so the function continue to search until 64 results (maybe you want to check whether your domain shown more than one on Google SERP).

Parameters explanation

  • $keyword –> the keyword that you want to check. Example: ‘how to upload mp3 to youtube
  • $url –> your domain name (without ‘http://’). Example: www.mp32u.net
  • $lang –> target language, different language target might cause different position result. Example (choose one): en, de, fr, id    

Usage example

1
2
3
4
5
6
7
require_once "gserp.php";
 
$keyword='how to upload mp3 to youtube';
$url='www.mp32u.net';
$lang='en';
 
print_r(g_serp($keyword, $url, $lang));

Example output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Array(
    [0] => Array
        (
            [position] => 7
        )
    [1] => Array
        (
            [title] => MP32U.NET - Create simple video from your MP3 and a JPG image
        )
    [2] => Array
        (
            [url] => http://www.mp32u.net/
        )
)

So, as you can see, at this time of writing, mp32u.net rank #7 on Google English (Google.com) on keyword: how to upload mp3 to Youtube

Fully working demo can be tested here: http://demo.ahowto.net/gserp/

bottom

22 Responses to “Google SERP checker using Google AJAX Search API‏”

  1. Cam says:

    Hi ! Big thanks for this :)
    I’m from France and have got a little problem. There is $lan fr but when i search some keyword without “lyon” for exemple, hav got no results. Even with a &pwd=0 in my serp url, i’m in 5 positions but still no results ! I’m puzzle :)

    Thanks again

  2. Cam says:

    Is there no other function to specified to place the research in a specific serp ?
    Thanks for the answer

  3. setia says:

    mas, sampeyan karo indovision opo aora ?, nek aora jarene gambare ilang nek udan ?

  4. tanya says:

    pak, kalau musim kemarau kayak sekarang ini apa Aora stabil terus atau ada gangguan juga ? LOST signal…

    • admin says:

      Di sini stabil2 saja tuh. Klo ndak ada hujan deres yg dtg tiba2, smua baik2 saja. Klo cmn hujan biasa(yg ndak disrtai petir), sinyal jg masih oke.

  5. soerya says:

    mas, ahowto.net baru januari kemaren di daftarin domainnya…sekarang udah PR 3, gimana mas tips& triknya biar bisa demikian…thanks

    • admin says:

      entahlah,
      ndak bisa SEO aku.. tulisan yg berkualitas saja mungkin.
      ini saja sdh jarang nulis2 lagi.. penginnya sih aktif lg di dunia per-online-an.. tp sibuk mlulu.

      • soerya says:

        kerja offline/konvensional juga ya mas…ta kira cuman murni online dari situs2 video

        • admin says:

          Malah ndak aktif lg di online, plg cmn ngecek sesekali doang. Kerja offline jd programmer freelance banyak menyita waktu.

  6. andry says:

    nice share bro…
    btw ada demo website SERP Script yg udah jadi belum?
    tx ya

  7. Ahmad Herbal says:

    Izin menyimak pak

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

bottom