这是一个可以执行您想要的操作的脚本(它使用稍微不同的电子表格,请查看)。此外,该脚本仅读取电子表格中的前 365 行,因此它会在一年内中断。
将来,您可能需要查看https://developers.google.com/adwords/scripts以获取面向脚本的资源和社区
function main() {
var sheet = SpreadsheetApp.openByUrl(
"https://docs.google.com/spreadsheet/ccc?key=0Aj_Bw31w9s7LdEdLMllQMnZfbW52c3BvcTh0ekVBQ3c#gid=0").getActiveSheet();
var emptyRow = findEmptyRow(sheet);
var yesterday = new Date(new Date().getTime() - (24 * 3600 * 1000));
var range = sheet.getRange(emptyRow + 1, 1, 1, 10);
var row = range.getValues();
row[0][0] = yesterday;
row[0][1] = MONTHS[yesterday.getMonth()];
row[0][2] = DAYS_OF_WEEK[yesterday.getDay()];
var stats = AdWordsApp.report("SELECT Clicks, Impressions, Cost, Conversions " +
"FROM ACCOUNT_PERFORMANCE_REPORT DURING YESTERDAY")
.rows()
.next();
row[0][3] = stats["Clicks"];
row[0][4] = stats["Impressions"];
row[0][7] = stats["Cost"];
row[0][8] = stats["Conversions"];
range.setValues(row);
}
function findEmptyRow(sheet) {
var dates = sheet.getRange(1, 1, 365, 1).getValues();
for (var emptyDate = 0; emptyDate < dates.length; emptyDate ++) {
if (dates[emptyDate][0].length == 0) {
return emptyDate;
}
}
}