Google文档每日访问者列表

时间:2014-08-01 21:42:12

标签: google-apps-script

我希望有一个脚本可以让我跟踪访问者(通过gmail用户名或相关的RL名称)到某些Google文档,并每天通过电子邮件向我发送一个列表。我是相关文档的所有者,我只与某些用户共享这些文档,但由于某些原因,匿名用户不断出现。我希望能够跟踪问题(我不能整天盯着开放文档来查看访问者)所以我可以向Google展示这是一个持续存在的问题,如果它继续下去的话。这里的任何人都可以帮我这个吗?我真的很感激。先感谢您。 :)

1 个答案:

答案 0 :(得分:0)

如果用户使用Google帐户登录,则此代码可放入附加脚本中:

/**
 * The onOpen function runs automatically when the Google Docs document is
 * opened. Use it to add custom menus to Google Docs that allow the user to run
 * custom scripts. For more information, please consult the following two
 * resources.
 *
 * Extending Google Docs developer guide:
 *     https://developers.google.com/apps-script/guides/docs
 *
 * Document service reference documentation:
 *     https://developers.google.com/apps-script/reference/document/
 */
function onOpen() {
  // Log the email address of the person running the script.
  var email = Session.getActiveUser().getEmail();
  Logger.log(email);
  // The code below creates a new spreadsheet "People" and logs the URL for it
  var ssNew = SpreadsheetApp.create("People");
  // The code below opens a spreadsheet using its ID and logs the name for it.
  // Note that the spreadsheet is NOT physically opened on the client side.
  // It is opened on the server only (for modification by the script).
  var ss = SpreadsheetApp.openById("abc1234567");
  Logger.log(ss.getName());
  // Appends a new row with 1 column to the bottom of the
  // spreadsheet containing the values in the array
  ss.appendRow([email]);
}