Hi Katrin,
I am happy to know that the previous issue has been fixed.
Moving forward, you may refer to the modified script below wherein necessary updates are applied. First, the array variable
header will be passed to the
sheet.appendRow() so that the script will add the column header to spreadsheet. Then, as for adding more keywords, I converted the
keywordPhrase variable into an array and used it in a for loop statement. You may set 3 or more keywords in the
keywordPhrase array.
var SPREADSHEET_URL = 'My URL';
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = spreadsheet.getActiveSheet();
function main() {
var keywordPhrase = ['keyword phrase 1', 'keyword phrase 2', 'keyword phrase 3'];
var header = [
'AccountDescriptiveName',
'KeywordMatchType',
'Impressions',
'SearchTopImpressionShare',
'SearchImpressionShare',
];
sheet.appendRow(header);
var accounts = AdsManagerApp.accounts().get();
while(accounts.hasNext()) {
var account = accounts.next();
AdsManagerApp.select(account);
for(var x=0 ; x<keywordPhrase.length ; x++)
var report = AdsApp.report(
'SELECT AccountDescriptiveName, KeywordMatchType, Impressions, SearchTopImpressionShare, SearchImpressionShare ' +
'FROM KEYWORDS_PERFORMANCE_REPORT ' +
'WHERE Criteria = "' + keywordPhrase[x] + '" ' +
'DURING LAST_MONTH '
);
var rows = report.rows();
while(rows.hasNext()) {
var row = rows.next();
sheet.appendRow([row['AccountDescriptiveName'],row['KeywordMatchType'],row['Impressions'], row['SearchTopImpressionShare'], row['SearchImpressionShare']]);
}
}
}
Let me know if you have further questions.
Regards,
Ejay