0

我刚刚开始学习 Google Ads 脚本。我在 google 中找到了一个示例,如何使用脚本将 Google Ads 数据导出到 Google 表格,但是在指定我的列时遇到了问题。

代码的第 2 步包含我需要提取的所有列。现在我需要在 Step4 中指定他们的方法名称,并在 Step3 中将“Campaign Type”(列)更改为 Google Ads 报告中的正确名称。

我应该在哪里看这个?谢谢你的建议!

所以入门代码如下所示:

function main() {
 
  //Step 1: Connect Google Ads to the Google Sheet
  var spreadsheetUrl = 'link here';
  var spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl);
  var ss = spreadsheet.getSheetByName('Sheet1');
  ss.clear();
 
  //Step 2: Create an array to store the data
  var sheetarray = [['Day', 'Account', 'Customer ID', 'Campaign', 'Ad Group', 'Campaign Type', 'Campaign Subtype', 'Image ad name', 'Currency', 'Clicks', 'Impressions', 'Cost', 'Conversions', 'Video-through conv.', 'Video played to 25%', 'Video played to 50%', 'Video played to 75%', 'Video played to 100%', 'Views']];
 
  //Step 3: Collect the data you need from Google Ads
  var keywords = AdsApp.keywords()
      .withCondition("Campaign Type = 'Video'")
      .forDateRange("LAST_30_DAYS")
      .get();
 
  //Step 4: Add the data you got from Google Ads into the array
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    sheetarray.push([
        keyword.getText(),
        keyword.getStatsFor("LAST_30_DAYS").getClicks(),
        keyword.getStatsFor("LAST_30_DAYS").getConversions()
      ]);
  }
   
  //Step 5: Display the contents of the array
  Logger.log(sheetarray);
 
  if (sheetarray.length > 0) {
     
    // Step 6: Send the array's data to the Google Sheet
    ss.getRange(1, 1, sheetarray.length, sheetarray[0].length).setValues(sheetarray);
     
    // Step 7: Send email with link to Google Sheet
    MailApp.sendEmail("a@gmail.com", "Keywords with 'Video' Campaign Type", "Here's the link: "+spreadsheetUrl);
  }
   
}
4

1 回答 1

0

您可以使用 appendRow

ss.appendRow(sheetarray);
于 2021-11-07T00:48:21.943 回答