Advertisement
Marc_Cornelius

Google Ads Script: Search Console Goldmine

Jul 23rd, 2024
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. function main() {
  2. // Spreadsheet details
  3. var spreadsheetUrl = 'YOUR_SPREADSHEETS_HERE';
  4. var sheetName = 'GSC: examplewebsite.com'; // Sheet name
  5. var startRow = 3; // Starting row for search terms
  6. var endRow = null; // Optional, specify the end row or leave as null to read till the last data row
  7.  
  8. // Visit MarcCornelius.com for more productivity & automation hacks for marketers!
  9.  
  10. // Access the spreadsheet
  11. var spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl);
  12. var sheet = spreadsheet.getSheetByName(sheetName);
  13.  
  14. // If endRow is not specified, use the last row with data in column A
  15. if (!endRow) {
  16. endRow = sheet.getLastRow();
  17. }
  18.  
  19. var range = sheet.getRange('A' + startRow + ':A' + endRow);
  20. var searchTerms = range.getValues();
  21.  
  22. // AdWords campaign and ad group details
  23. var campaignName = 'Your Campaign Name';
  24. var adGroupName = 'Search Console Goldmine';
  25.  
  26. // Retrieve the campaign and ad group
  27. var campaignIterator = AdsApp.campaigns()
  28. .withCondition('Name = "' + campaignName + '"')
  29. .get();
  30.  
  31. if (campaignIterator.hasNext()) {
  32. var campaign = campaignIterator.next();
  33.  
  34. var adGroupIterator = campaign.adGroups()
  35. .withCondition('Name = "' + adGroupName + '"')
  36. .get();
  37.  
  38. if (adGroupIterator.hasNext()) {
  39. var adGroup = adGroupIterator.next();
  40.  
  41. // Add each search term as an exact match keyword
  42. for (var i = 0; i < searchTerms.length; i++) {
  43. var term = searchTerms[i][0]; // Assuming search terms are in the first column
  44. if (term != "") {
  45. adGroup.newKeywordBuilder()
  46. .withText('[' + term + ']') // Enclose the term in brackets for exact match
  47. .build();
  48. }
  49. }
  50. } else {
  51. Logger.log('Ad group with the name "' + adGroupName + '" does not exist.');
  52. }
  53. } else {
  54. Logger.log('Campaign with the name "' + campaignName + '" does not exist.');
  55. }
  56. }
  57.  
  58.  
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement