首页 > 解决方案 > 有没有办法获取谷歌文档的查看活动?

问题描述

我的团队正在寻找一些在组织范围内共享的谷歌文档的查看活动数据。最终,我们想要这些文档的使用统计信息。能够计算这些文档副本的视图也很好,但我们会很高兴仅从原始文档的视图开始。

我试图在文档方法中的某处找到查看详细信息,但无济于事(我找到了 getViewers,但这对我没有帮助)。

我还研究了将脚本绑定到文档以计算用户打开它的时间,但 onOpen 仅触发具有编辑访问权限的用户——大多数打开这些文档的人将以只读访问权限打开。

有什么建议么?

标签: google-apps-scriptgoogle-drive-apigoogle-docs-api

解决方案


您可以使用Reports API中的activity.list来访问 Drive 审核日志,其中包含查看日志活动和其他事件。有关可用事件的列表,请参阅Drive Audit Activity Events

使用管理控制台的示例:

在此处输入图像描述

示例activity.list请求参数:

userKey: all
applicationName: drive
eventName: view
filters: doc_id==13NgKy87BggedOXnmkymygTyEh0xxxxxxxx

示例响应:(删除了一些敏感信息)

{
  "kind": "admin#reports#activities",
  "etag": "\"gwJsVSTi6OzvUGrf7ei0V53d9qZWZz_Kvb9LYWitNI4/sGVnptbK063qxxxxxx\"",
  "items": [
    {
      "kind": "admin#reports#activity",
      "id": {
        "time": "2021-03-24T18:49:24.579Z",
        .....
      },
      "actor": {
        "email": "user1@domain.com",
        "profileId": "1043405157872289xxxxx"
      },
      "events": [
        {
          "type": "access",
          "name": "view",
          ......
        }
      ]
    },
    {
      "kind": "admin#reports#activity",
      "id": {
        "time": "2021-03-24T18:49:01.942Z",
        .....
      },

      "actor": {
        "email": "rm@domain.com",
        "profileId": "1146312647848028xxxxx"
      },
      "ipAddress": "110.54.238.28",
      "events": [
        {
          "type": "access",
          "name": "view",
          ......
        }
      ]
    },
    {
      "kind": "admin#reports#activity",
      "id": {
        "time": "2021-03-24T18:48:29.751Z",
        .....
      },
      "actor": {
        "email": "",
        "profileId": "1052505060979797xxxxx"
      },
      "events": [
        {
          "type": "access",
          "name": "view",
          ......
        }
      ]
    },
    {
      "kind": "admin#reports#activity",
      "id": {
        "time": "2021-03-24T18:47:30.288Z",
        .....
      },
      "actor": {
        "email": "rm@domain.com",
        "profileId": "1146312647848028xxxxx"
      },
      "ipAddress": "110.54.238.28",
      "events": [
        {
          "type": "access",
          "name": "view",
          ......
        }
      ]
    },
    {
      "kind": "admin#reports#activity",
      "id": {
        "time": "2021-03-22T21:17:35.009Z",
        .....
      },
      "actor": {
        "email": "rm@domain.com",
        "profileId": "114631264784802xxxxx"
      },
      "events": [
        {
          "type": "access",
          "name": "view",
          ......
        }
      ]
    }
  ]
}

笔记:

  • 如果文件被组织外部的用户查看,则电子邮件地址将不可用(用户是匿名的)
  • 云端硬盘审核日志的数据保留时间为 6 个月。您可以在此之前访问云端硬盘审核日志数据。您可能需要考虑每月保存一次数据计数,这样即使以前的驱动器审核日志被删除,您仍然可以拥有这些数据。

参考:


推荐阅读