← All Apps Scripts templates
/
Auto-suggest keywords based on a keyword

Auto-suggest keywords based on a keyword

  1. Create a new Google Sheets file
  2. Go to Extensions → Apps Script
  3. Remove all the code and copy-paste the following instead
  4. Save your project and go back to your sheet
  5. Enter main keywords in column
  6. Create a drawing button an assign the script keywordSuggestions and name it "Run"
  7. Click the run button to get the suggestions in column
  8. When you run, it requires app script permission
  9. Once you grant access the result will show in column B

The code to paste in Apps Script inside Google Sheets:


function keywordSuggestions() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var keywords = sheet.getRange("A2:A").getValues();
  
  for (var i = 0; i < keywords.length; i++) {
    if (keywords[i][0] == "") {
      continue;
    }
    
    var suggestions = getGoogleSuggestions(keywords[i][0]);
    sheet.getRange(i + 2, 2).setValue(suggestions.join(", "));
  }
}

function getGoogleSuggestions(keyword) {
  var suggestions = [];
  var url = "http://suggestqueries.google.com/complete/search?client=firefox&q=" + keyword;
  var response = UrlFetchApp.fetch(url);
  var json = JSON.parse(response.getContentText());
  
  for (var i = 0; i < json[1].length; i++) {
    suggestions.push(json[1][i]);
  }
  
  return suggestions;
}

Reach us if the process is unclear or if the script is outdated
Apps Scripts template
Free
SEO
Auto-suggest keywords based on a keyword

Auto-suggest keywords based on a keyword

Last updated
3/4/2023
Built by
Avatar Placeholder
internal