For a company looking to improve its online presence, the keywords they rank for online, and their position, are crucial. Knowing which keywords to target can be difficult, especially for a smaller business that may not yet rank for many, or established businesses looking to find additional terms they may be overlooking. One basic tool to hunt for new keywords to rank for is Google autocomplete – the process of simply beginning to type in the Google search box and letting Google suggests possible search terms based on what you’ve input. These suggested terms are based on what other people are searching for using your input term and therefore may provide useful keyword suggestions. What is the Google Suggest API? While useful for highlighting a keyword or two, the process of inputting individual terms into Google’s search box to determine suggestions, can get quite tedious. Enter the Google Suggest API. The suggest API utilises Google autocomplete and returns suggested terms from an input seed keyword. The API doesn’t require an API key and the data is accessed via a simple HTTP request. http://suggestqueries.google.com/complete/search?&output=toolbar&hl=LANG&q=EXAMPLE_QUERY&gl=COUNTRY_CODE The above snippet is an example request where: LANG is the language of the returned queries. EXAMPLE_QUERY is the input seed query to base suggestions from. COUNTRY_CODE is the country to return results from E.G. uk. The response is an XML file with 10 suggestions. The format of this file has <toplevel> as the root element of the XML, <CompleteSuggestion> are then the children of this root element and finally <suggestion> as the child of the <CompleteSuggestion> elements. Using the API in Google Sheets Lets set up a basic Google sheet with a single seed keyword. Now we need to enter the script editor in the tools tab of Google Sheets and start to build our suggestions function. We first need to access our “Autocomplete” sheet and access the value contained in the cell “A2”. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Autocomplete"); var seed_kw = sheet.getRange("A2").getValue(); We then need to feed the seed keyword into our request and then parse the returned XML. var response = UrlFetchApp.fetch("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=en&q="+seed_kw+"&gl=uk"); var xml = response.getContentText(); var document = XmlService.parse(xml); Now we need to access the suggestion bearing in mind the structure of the XML so first, we need to get the children of the root element. The <CompleteSuggestion> elements. var root = document.getRootElement(); var suggestions = root.getChildren('CompleteSuggestion'); We now need to loop through each element in the suggestions variable to then access their child element which is the <suggestion> element. The suggestion is the attribute of this element and we push this suggestion to a suggest_list array. var suggest_list = []; for(var x = 0 ;x < suggestions.length ; x++){ var suggestion = suggestions[x]; var data = suggestion.getChild('suggestion').getAttribute('data').getValue(); suggest_list.push([data]); } With our query suggestions now gathered all that’s left to do is to spit them into our sheet. sheet.getRange(2,2,suggest_list.length,1).setValues(suggest_list) Here is our final suggestions function. function suggestions(){ var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Autocomplete"); var seed_kw = sheet.getRange("A2").getValue(); var response = UrlFetchApp.fetch("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=en&q="+seed_kw+"&gl=uk"); var xml = response.getContentText(); var document = XmlService.parse(xml); var root = document.getRootElement(); var suggestions = root.getChildren('CompleteSuggestion'); var suggest_list = []; for(var x = 0 ;x < suggestions.length ; x++){ var suggestion = suggestions[x]; var data = suggestion.getChild('suggestion').getAttribute('data').getValue(); suggest_list.push([data]); } sheet.getRange(2,2,suggest_list.length,1).setValues(suggest_list) } Once this function is run our sheet will now look like this. Final Thoughts The scripting presented in this blog is only a base for a more developed tool and could be expanded further. For example, at Blueclaw we’ve developed a tool that allows us to enter a list of seed keywords, where each word has an outputted results column, discards a list of negative match keywords from the results, and returns with the suggested keywords alongside their search volume and we can squeeze out over 100 results for each seed keyword to obtain more detailed keyword suggestions. All of these improvements are achieved through GAS (with a little help from the SEMrush API to acquire search volume) and use the script presented here as a basis. To discuss the ways in which we can help develop a strong keyword strategy for your business, get in touch.

Blog

Keyword Suggestions using the Google Suggest API and Google Apps Script

For a company looking to improve its online presence, the keywords they rank for online, and their position, are crucial. Knowing which keywords to target can be difficult, especially for a smaller business that may not yet rank for many, or established businesses looking to find additional terms they may be overlooking.

One basic tool to hunt for new keywords to rank for is Google autocomplete – the process of simply beginning to type in the Google search box and letting Google suggests possible search terms based on what you’ve input. These suggested terms are based on what other people are searching for using your input term and therefore may provide useful keyword suggestions.

What is the Google Suggest API?

While useful for highlighting a keyword or two, the process of inputting individual terms into Google’s search box to determine suggestions, can get quite tedious. Enter the Google Suggest API. The suggest API utilises Google autocomplete and returns suggested terms from an input seed keyword. The API doesn’t require an API key and the data is accessed via a simple HTTP request.

http://suggestqueries.google.com/complete/search?&output=toolbar&hl=LANG&q=EXAMPLE_QUERY&gl=COUNTRY_CODE

The above snippet is an example request where:

  • LANG is the language of the returned queries.
  • EXAMPLE_QUERY is the input seed query to base suggestions from.
  • COUNTRY_CODE is the country to return results from E.G. uk.

The response is an XML file with 10 suggestions. The format of this file has <toplevel> as the root element of the XML, <CompleteSuggestion> are then the children of this root element and finally <suggestion> as the child of the <CompleteSuggestion> elements.

Using the API in Google Sheets

Lets set up a basic Google sheet with a single seed keyword.

Picture1 3 20200130090008

Now we need to enter the script editor in the tools tab of Google Sheets and start to build our suggestions function. We first need to access our “Autocomplete” sheet and access the value contained in the cell “A2”.

var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Autocomplete");
var seed_kw = sheet.getRange("A2").getValue();

We then need to feed the seed keyword into our request and then parse the returned XML.

var response = UrlFetchApp.fetch("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=en&q="+seed_kw+"&gl=uk");
var xml = response.getContentText();  
var document = XmlService.parse(xml);

Now we need to access the suggestion bearing in mind the structure of the XML so first, we need to get the children of the root element. The <CompleteSuggestion> elements.

var root = document.getRootElement();
var suggestions = root.getChildren('CompleteSuggestion');

We now need to loop through each element in the suggestions variable to then access their child element which is the <suggestion> element. The suggestion is the attribute of this element and we push this suggestion to a suggest_list array.

var suggest_list = [];
for(var x = 0 ;x < suggestions.length ; x++){
  var suggestion = suggestions[x];
  var data = suggestion.getChild('suggestion').getAttribute('data').getValue();
  suggest_list.push([data]);
}

With our query suggestions now gathered all that’s left to do is to spit them into our sheet.

sheet.getRange(2,2,suggest_list.length,1).setValues(suggest_list)

Here is our final suggestions function.

function suggestions(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Autocomplete");
  var seed_kw = sheet.getRange("A2").getValue();
  
  var response = UrlFetchApp.fetch("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=en&q="+seed_kw+"&gl=uk");
  var xml = response.getContentText();  
  var document = XmlService.parse(xml);
  
  var root = document.getRootElement();
  var suggestions = root.getChildren('CompleteSuggestion');
  
  var suggest_list = [];
  for(var x = 0 ;x < suggestions.length ; x++){
    var suggestion = suggestions[x];
    var data = suggestion.getChild('suggestion').getAttribute('data').getValue();
    suggest_list.push([data]);
  }
  sheet.getRange(2,2,suggest_list.length,1).setValues(suggest_list)
}

Once this function is run our sheet will now look like this.

Picture2 3 20200130090029

Final Thoughts

The scripting presented in this blog is only a base for a more developed tool and could be expanded further.

For example, at Blueclaw we’ve developed a tool that allows us to enter a list of seed keywords, where each word has an outputted results column, discards a list of negative match keywords from the results, and returns with the suggested keywords alongside their search volume and we can squeeze out over 100 results for each seed keyword to obtain more detailed keyword suggestions.

All of these improvements are achieved through GAS (with a little help from the SEMrush API to acquire search volume) and use the script presented here as a basis.

To discuss the ways in which we can help develop a strong keyword strategy for your business, get in touch.

Written by

Simran Gill

Latest posts.

Contact.

We’re always keen to talk search marketing.

We’d love to chat with you about your next project and goals, or simply share some additional insight into the industry and how we could potentially work together to drive growth.