开始使用

请按照以下步骤启动您的第一个脚本。

  1. 登录您的 Google Ads 帐号。
  2. 点击工具图标 带有白色扳手的灰色框,然后选择批量操作下的脚本
  3. 按 + 图标 带白色加号的蓝色圆圈 添加脚本。
  4. 复制以下代码并将其粘贴到主函数内的编辑器区域:

    function main() {
       let keywords = AdsApp.keywords()
             .orderBy("metrics.impressions DESC")
             .forDateRange("YESTERDAY")
             .withLimit(10)
             .get();
    
       console.log("The 10 keywords with the most impressions yesterday:");
       for (const keyword of keywords) {
           console.log(`${keyword.getText()}: ${keyword.getStatsFor("YESTERDAY")
                                                       .getImpressions()}`);
         }
    }
    
  5. 出现提示时,点击授权,以便脚本可以代表您访问该帐号。您需要对每个脚本执行一次此操作。

  6. 点击预览,以在预览模式下运行脚本。结果将显示在更改 / 日志面板中。

经理账号

您必须先拥有 Google Ads 经理帐号才能运行 Google Ads 管理器脚本。

  1. 登录您的 Google Ads 经理账号。
  2. 点击工具图标 带有白色扳手的灰色框,然后选择批量操作下的脚本
  3. 按 + 图标 带白色加号的蓝色圆圈 添加脚本。
  4. 复制以下代码并将其粘贴到主函数内的编辑器区域:

    function main() {
      // Retrieve all children accounts.
        const accountIterator = AdsManagerApp.accounts().get();
    
      // Iterate through the account list.
      for (const account of accountIterator) {
        // Get stats for the child account.
        const stats = account.getStatsFor("THIS_MONTH");
        // And log it.
        console.log(`${account.getCustomerId()},${stats.getClicks()},` +
          `${stats.getImpressions()},${stats.getCost()}`);
      }
    }
    
  5. 出现提示时,点击授权,以便脚本可以代表您访问该帐号。您需要对每个脚本执行一次此操作。

  6. 点击预览,以在预览模式下运行脚本。结果将显示在更改 / 日志面板中。

如需查看更多脚本代码段示例,请参阅我们的示例页面