Google Trends PHP API for Hourly Updates

We are all aware of the importance of relevant meta data for SEO hence we are constantly on the look out for the most researched keywords in search engines primarily Google. Google also provides Google Trends tool which gives insights into broad search patterns.

Google trends can be accessed here: http://www.google.com/trends

Here you can find the complete information with graphical representation on a  scale based on the average worldwide traffic of Keywords you entered in all years.

Google trends also has its PHP API which fetches top 20 hot trends. Google has restricted the access to 20 keywords. These can be fetched date wise or hourly. The sample code to fetch hourly hot trends of Google is as follows:

<?
// Fetches google hot hourly 20 trends
$trends = new GoogleHotrends();
$keywords = $trends->fetch_trends();
print_r($keywords);

class GoogleHotrends {
private $trendsurl = “http://www.google.com/trends/hottrends/atom/hourly”;

public function fetch_trends()
{
$c = curl_init($this->trendsurl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$responsedata = curl_exec($c);
curl_close($c);
return $this->parse_trend_feed( $responsedata );
}

private function parse_trend_feed( $data )
{
preg_match_all(‘/.+?<a href=”.+?”>(.+?)<\/a>.+?/’,$data,$matches);
return $matches[1];
}
}
?>

The above code returns the array of 20 keywords that people are searching on Google today. This can be very useful to track  the sudden change (increase or decrease in popularity of a particular keyword) and get updates hourly.

This entry was posted in PHP, Search Engine Optimization and tagged , , , , , . Bookmark the permalink.

Leave a Reply