Use Google Suggest as a helper for keyword research

UPDATE: This code is outdated and not working anymore. See my new article for an actual working version.

Since April 2009 Google offers some nice feature in web search called Suggest, which is the  list of search queries you see,when you type in some search query into Google. I think everyone knows and uses it…

In addition to this nice helper on the website itself, Google also provides the same results as a feed or javascript code, which made me think of some way to utilize it and it seems to be a perfect helper for keyword research issues. The magical URL  is: with its parameters.

Parameters are:

  1. hl: string value which determines the language (e.g. ‘de’, ‘en’, ‘jp’…)
  2. The format to fetch. For my code I use the XML output, but possible values are:
    • xml=true

      Returns the results in XML format.

    • js=true

      Returns some javascript code with the results to embed.

    • json=true

      Returns the results in JSON format

  3. qu: the query to look for.

A valid complete URL would look like:

So, how to use this in keyword reasearch? Well, the point is, that users often take the suggestions Google gives, so it could be worth to rank hight for that keyword combinations.

I wrote come simple class in PHP, that let’s you easily utilize the suggestion feed:

< ?php
  define('SUGGEST_URL', '');
     * A simple class, that only contains one function to fetch the 10 
     * suggestions for a specific query and language from google and return them 
     * in a two dimensional array.
     * The structure of the array is:
     *     (string) $Element['suggestion']
     *     (int)    $Element['results']
     * The first element contains the the suggestion string, the second one
     * holds the count of search results for that query.
     * On error this function returns a negative error code.
     * Error codes are:
     *    (-1): Parameter not set
     *    (-2): Cannot load data from query url
     *    (-3): XML loading failed
  class gSuggest {
    public function getSuggestData($lang=null, $query=null) {
      // Check parameters 
      if( $lang === null || $query === null ) {
        return -1;
      // Create query url
      $queryUrl = str_replace(array('@COUNTRY@', '@QUERY@'), 
                              array($lang, $query), SUGGEST_URL);       
      // Fetch XML from google
      $suggestFeed = file_get_contents($queryUrl);
      if( $suggestFeed === false ) {
        return -2;
      // Load XML data into object
      $xmlData = simplexml_load_string($suggestFeed);
      if( $xmlData === false ) {
        return -3;
      // Process the XML object
      $returnData = array();
      $index = 0;
      foreach($xmlData->CompleteSuggestion as $element) {
        $s_data = $element->suggestion->attributes();
        $n_data = $element->num_queries->attributes();        
        $returnData[$index]['suggestion'] = (string) $s_data['data'];
        $returnData[$index]['results'] = (int) $n_data['int'];
      return $returnData;

The class only contains one public function and no constructor, so as an usage example:

< ?php   
  $data = gSuggest::getSuggestData($_SERVER['argv'][1], 'abnehmen');
  foreach($data as $i => $v) {
    printf("(%d) %s => %d\n", ($i+1), $v['suggestion'], $v['results']);

This would look for the term “javacoffee” in english (en) language and print the resulting array.

Similar Posts:

  • Danke für den guten Hinweis.

  • This was very helpful for my site aboz Hochzeitsmusik and Bands. The Suggest Tool will pimp this a lot.
    Thank you

  • Christian Meyer

    Sehr interessabnt