如何使用AdWords脚本在Google文档电子表格的特定单元格中填充AdWords数据? [英] How to populate adwords data in specific cells of a google docs spreadsheet using AdWords Scripts?

查看:85
本文介绍了如何使用AdWords脚本在Google文档电子表格的特定单元格中填充AdWords数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有编程背景,只是开始学习JavaScript基础知识,所以我可以流利地创建自定义Google AdWords脚本来帮助我自动化客户报告。我花了好几个小时的试验和错误,并没有想出这个问题(这可能是超级简单的程序员):

I don’t have a programming background and just started learning JavaScript basics so I can become fluent at creating custom Google AdWords scripts to help me automate client reporting. I’ve spent many hours with trial and error and haven’t figured out to this problem (which is probably super easy for programmers):

我试图填充我制作的电子表格(这里是缩写链接: http://goo.gl/wLAAx ),包含帐户级别数据,所以我可以计算一个帐户的运行率。我所要做的就是运行一个脚本,每天早上将运行一个脚本,并在电子表格中添加一行,并在昨天的日期填充各自的数据,如点击次数,展示次数,费用和转化次数。

I’m trying to populate a spreadsheet that I have made (here’s the shortened link: http://goo.gl/wLAAx) with account level data so I can calculate the run rate of an account. All I’m trying to do is run a script that will run every morning that will append a new row in the spreadsheet with yesterday’s date and populate its respective data, like clicks, impressions, cost, and conversions.

感谢您提供任何帮助和信息!

Thanks in advance for any help and information!

推荐答案

这是一个脚本,你想要什么(它使用一个稍微不同的电子表格,检查出来)。另外,该脚本仅在电子表格的前365行中读取,因此它将在一年内中断。

Here's a script that'd do what you want (it uses a slightly different spreadsheet, check it out). Also, the script is only reading in the first 365 rows in the spreadsheet, so it'll break in a year.

将来,您可能需要检查针对面向脚本的资源和社区 https://developers.google.com/adwords/scripts

In the future, you may want to check with https://developers.google.com/adwords/scripts for resources and community oriented towards 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;
    }
  }
}

这篇关于如何使用AdWords脚本在Google文档电子表格的特定单元格中填充AdWords数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆