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