Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何使用GoogleApps脚本监控google站点的页面活动_Google Apps Script_Web Applications_Google Sites - Fatal编程技术网

Google apps script 如何使用GoogleApps脚本监控google站点的页面活动

Google apps script 如何使用GoogleApps脚本监控google站点的页面活动,google-apps-script,web-applications,google-sites,Google Apps Script,Web Applications,Google Sites,问题 我希望能够使用Apps脚本监控我的google站点上的用户活动,特别是用户正在访问的页面。我不能使用谷歌分析(这不在我与谷歌的合同范围内)。到目前为止,Apps脚本能够在访问页面时返回用户的用户ID(电子邮件地址),但是我无法确定如何返回该用户激活的页面 我到目前为止所做的事情 我已经创建了一个web应用程序,并将其部署/嵌入到一个测试google站点的2个页面中。它将值返回到链接的google sheets文件中的表中。以下是脚本: function doGet(event) { r

问题 我希望能够使用Apps脚本监控我的google站点上的用户活动,特别是用户正在访问的页面。我不能使用谷歌分析(这不在我与谷歌的合同范围内)。到目前为止,Apps脚本能够在访问页面时返回用户的用户ID(电子邮件地址),但是我无法确定如何返回该用户激活的页面

我到目前为止所做的事情 我已经创建了一个web应用程序,并将其部署/嵌入到一个测试google站点的2个页面中。它将值返回到链接的google sheets文件中的表中。以下是脚本:

function doGet(event) {
  return HtmlService.createHtmlOutputFromFile('UserLog.html');
}

function getPage(pageTitle) {
  var user = Session.getActiveUser();
  var ss = SpreadsheetApp.getActive();
  var db = "Webapp Log";
  var db_ss = ss.getSheetByName(db);
  var now = new Date();
  var page = pageTitle;
  var values = [now,user,page,"User activated webapp",Session.getTemporaryActiveUserKey()];
  db_ss.getRange(db_ss.getLastRow()+1, 1, 1, 5).setValues([values]);
};
“UserLog.html”代码如下:

<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <script>
       var page = [Solution]
       google.script.run.getPage(page);
    </script>
  </body>
  </html>

变量页=[解决方案]
google.script.run.getPage(第页);
到目前为止,返回值如下所示(地址匿名):

如您所见,“页面”字段为空

我需要什么 使用嵌入式web应用程序返回激活的页面URL或返回激活页面的另一个唯一方面,例如页面标题或“第1页”、“第2页”等(网站上的所有页面都有唯一标题)

如何做到这一点?这可能吗?

你可以用
  • 例如,在WebApp URL末尾添加一个参数
    页面

  • 在每个页面中嵌入WebApp URL时,为页面指定一个唯一的值,如
    https://script.google.com/a/XXX/macros/s/XXX/exec?page=1
    https://script.google.com/a/XXX/macros/s/XXX/exec?page=2

现在,在应用程序脚本中,只需稍微修改
doGet()
函数即可检索页面:

function doGet(event) {
  var page = event.parameter.page;
  return HtmlService.createHtmlOutputFromFile('UserLog.html');
}
  • 其余的取决于你的喜好。最简单的方法是直接将
    page
    的值从
    doGet()
    函数粘贴到电子表格中-这将避免将参数传递到
    html
    文件,然后使用
    google.script.run
    返回到.gs函数

如何将WebApp嵌入您的网站?你使用新网站还是经典网站?我发布>部署为web应用>复制当前web应用URL。然后,我使用embed by URL函数将此URL粘贴到站点中的嵌入元素中。我正在使用新版本的站点。您使用的是
站点
还是
经典站点
?我正在使用站点