Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main() {
- // Spreadsheet details
- var spreadsheetUrl = 'YOUR_SPREADSHEETS_HERE';
- var sheetName = 'GSC: examplewebsite.com'; // Sheet name
- var startRow = 3; // Starting row for search terms
- var endRow = null; // Optional, specify the end row or leave as null to read till the last data row
- // Visit MarcCornelius.com for more productivity & automation hacks for marketers!
- // Access the spreadsheet
- var spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl);
- var sheet = spreadsheet.getSheetByName(sheetName);
- // If endRow is not specified, use the last row with data in column A
- if (!endRow) {
- endRow = sheet.getLastRow();
- }
- var range = sheet.getRange('A' + startRow + ':A' + endRow);
- var searchTerms = range.getValues();
- // AdWords campaign and ad group details
- var campaignName = 'Your Campaign Name';
- var adGroupName = 'Search Console Goldmine';
- // Retrieve the campaign and ad group
- var campaignIterator = AdsApp.campaigns()
- .withCondition('Name = "' + campaignName + '"')
- .get();
- if (campaignIterator.hasNext()) {
- var campaign = campaignIterator.next();
- var adGroupIterator = campaign.adGroups()
- .withCondition('Name = "' + adGroupName + '"')
- .get();
- if (adGroupIterator.hasNext()) {
- var adGroup = adGroupIterator.next();
- // Add each search term as an exact match keyword
- for (var i = 0; i < searchTerms.length; i++) {
- var term = searchTerms[i][0]; // Assuming search terms are in the first column
- if (term != "") {
- adGroup.newKeywordBuilder()
- .withText('[' + term + ']') // Enclose the term in brackets for exact match
- .build();
- }
- }
- } else {
- Logger.log('Ad group with the name "' + adGroupName + '" does not exist.');
- }
- } else {
- Logger.log('Campaign with the name "' + campaignName + '" does not exist.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement