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
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/
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
no idea, maybe it’s because the Google datacenter near your place
Is there no other function to specified to place the research in a specific serp ?
Thanks for the answer
I’m afraid that’s all I got from reading the Google API documentation.
Me again
, what’s diffence between $url and $referer ?
$url is the website address that you want to check the position on google search.
$referer is not mandatory but very encouraged by Google API. This variable is used to notify Google about where the script that called the API from.
All right. Thanks guy !
mas, sampeyan karo indovision opo aora ?, nek aora jarene gambare ilang nek udan ?
Pake Aora. Klo ujannya deres bgt, sinyal Aora ilang.. tp kan skrg musim kemarau, jarang ujan..
ambil paket yg 99rb/bln ya…ambil HBO ga mas ?
Iya, ambil yg paket itu. Aq ndak langganan HBO, sdh cukup dg fox movie premium. Lgian yg sering nonton anak2 sih.
hi this is nice one.but how to find position for multiple keyword for same url?
Do it one by one
pak, kalau musim kemarau kayak sekarang ini apa Aora stabil terus atau ada gangguan juga ? LOST signal…
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.
mas, ahowto.net baru januari kemaren di daftarin domainnya…sekarang udah PR 3, gimana mas tips& triknya biar bisa demikian…thanks
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.
kerja offline/konvensional juga ya mas…ta kira cuman murni online dari situs2 video
Malah ndak aktif lg di online, plg cmn ngecek sesekali doang. Kerja offline jd programmer freelance banyak menyita waktu.
nice share bro…
btw ada demo website SERP Script yg udah jadi belum?
tx ya
ndka ada mas bro..
ini cmn buat maen2 saja kok