Google API -PHP & Keyword Anaysis

Status
Not open for further replies.

digga121

ajaxking
Jul 25, 2008
745
6
0
socialsnipe.com
Google API & PHP & Keyword Anaysis


Just started looking into this ..

I need a tool the client can log into and get stats on

What keywords brought them to the site from google
Estimated search for last month for that KW.
Daily Traffic to Pages listed on.


It would be nice if there was also a clickthrough link to put on there buttons and banners, to add that in the report. Ive done this before, but this time I need to communicate with google, and I want to use PHP, since there may already be a script out there..I have minimal funds, so I'd rather program this myself but if they have a free one, I'm all for it. ..so I'm pretty much looking either for a public free script ,or some code hints or posts on this.

Thanks in advance.
 


Cookie Created by Google

Still working on this ..so far I've found out that Google puts a Cookie on your PC saying what kw brought you to the site, so I'm gonna try to capture that cookie, that will at least get the long tail, next is finding out approx search volume ..Thanks.
 
Okay, the cookie google leaves cannot be used by a third part =/ however ...there is a way to do this using $_SERVER['HTTP_REFERER']. It should bring back your H1 Title, Meta and kw ...like this ..

HD News is your only source for anything


HD News

hd news - Google Search=

so ...q= is the kw, maybe some regular expression can help grabbing this info ..something to remember:

http_referer can be blanked or spoofed

Does anyone have an alternative to this? Thanks.
 
A little function that takes the keywords out of the referring url. Currently works for big 4 but can be hacked to include more.

PHP:
$se=seReferer();

echo $se['Se'] ; // prints out referring engine
echo $se['Query'] ; // prints out keyword used
echo $se['Referer'] ; // prints out click through link

function seReferer($ref = false){
    $SeReferer = (is_string($ref) ? $ref : $_SERVER['HTTP_REFERER']);
    if( //Check against Google, Yahoo, MSN, Ask and others
        preg_match(
        "/[&\?](q|p|w|searchfor|as_q|as_epq|s|query|sTerm|Keywords)=([^&]+)/i",
        $SeReferer,$pcs)
    ){
        if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){
            $SeDomain    = trim(strtolower($SeDomain[1]));
            $SeQuery    = $pcs[2];
            if(preg_match("/[&\?](start|b|first|stq)=([0-9]*)/i",$SeReferer,$pcs)){
                $SePos    = (int)trim($pcs[2]);
            }
        }
    }
    
    if(!isset($SeQuery)){
        if( //Check against DogPile
            preg_match(
            "/\/search\/web\/([^\/]+)\//i",
            $SeReferer,$pcs)
        ){
            if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){
                $SeDomain    = trim(strtolower($SeDomain[1]));
                $SeQuery    = $pcs[1];
            }
        }
    }
    // We Do Not have a query
    if(!isset($SeQuery)){ return false; }
    $OldQ=$SeQuery;
    $SeQuery=urldecode($SeQuery);
    // The Multiple URLDecode Trick to fix DogPile %XXXX Encodes
    while($SeQuery != $OldQ){
        $OldQ=$SeQuery; $SeQuery=urldecode($SeQuery);
    }
    //-- We have a query
    return array(
        "Se"=>$SeDomain,
        "Query"=>$SeQuery,
        "Pos"=>(int)$SePos,
        "Referer"=>$SeReferer
    );
}
Now for getting approx. search volume for these words ... you are on your own (though I'm all ears!!!!).

The adwords tool is the only real resource to give good approximates on volume. The biggest problem would be the captcha you have to enter the first time you research a word ... after that, the rest could potentially be cURL'd setting cookies and posting words.

I think the suggestions/volume data is displayed using ajax so you might be able to find a shortcut scraping from that specific url, much like how you would scrape google suggest.

Good luck, sounds like a very cool & useful project
 
  • Like
Reactions: fm1234
Status
Not open for further replies.