NESC-Graviton / galaxy

Galaxy is the analytics system for user behavior
https://nesc-graviton.github.io/galaxy/
Apache License 2.0
21 stars 0 forks source link

[Discus] 需要搜集的数据 #4

Open hstarorg opened 6 years ago

hstarorg commented 6 years ago

客户端收集

基础浏览器数据

数据key 获取方式 备注
nl navigator.language 浏览器语言
np navigator.platform 浏览器平台
nje navigator.javaEnabled() 是否启用了Java环境
nmtp navigator.maxTouchPoints 最大的触控点
nce navigator.cookieEnabled 是否启用了Cookie
nd navigator.doNotTrack 是否禁用追踪
ndm navigator.deviceMemory 设备内存
ndc navigator.hardwareConcurrency 并发数
sr ${screen.width}*${screen.height} 屏幕宽高
scd screen.colorDepth 屏幕颜色深度
dc document.charset || document.characterSet 文档编码
dr document.referrer 文档的Referrer
t Date.now() 客户端时间戳

页面加载性能数据

数据key 获取方式 备注

服务端收集

请求数据

数据key 数据类型 备注
Path String 读取Request.Headers["Referer"]中的数据
IP String 读取Request.Headers["X-Source-IP"]或RemoteIpAddress
UserAgent String 读取Request.Headers["User-Agent"]
Cookie Object 提取UserId等标识信息
Time DateTime 获取当前时间

API定义

ga.setUid(); // 设置业务层的用户ID
ga.pageView(url, payload);
ga.trackEvent(category, event, payload)
Lession711 commented 6 years ago

Rest API

PageView

POST /api/report

  • Request Body
``` javascript
{
    "nl": "zh-CN", // navigator.language
    "np": "Win32", // navigator.platform
    "nje": false, // navigator.javaEnabled()
    "nmtp": 0, // navigator.maxTouchPoints
    "nce": true, // navigator.cookieEnabled
    "nd": null, // navigator.doNotTrack
    "ndm": 8, // navigator.deviceMemory
    "ndc": 8, // navigator.hardwareConcurrency
    "sr": "1920*1080", //  `${screen.width}*${screen.height}`
    "scd": 24, // screen.colorDepth
    "dc": "UTF-8", // document.charset || document.characterSet
    "dr": "http://host:port/path?query#hash", // document.referrer
    "t": 1526629426139 // (new Date().getTime())+diff
}
```

Event

PUT /api/report

  • Request Body
``` javascript
[{
    "g": "default", // [optional] category, default is "default"
    "a": "action name", // [require] action name
    "u": "logic user id", // [optional] setting from setUid(uid)
    "t": 1526629426139, // (new Date().getTime())+diff
    "d": {} //[optional] dictionary, action custom data --> payload
}]
```
watermoonlx commented 6 years ago

目前pageView事件中已收集的数据

    if (document) {
        data.domain = document.domain || '';
        data.url = document.URL || '';
        data.title = document.title || '';
        data.referrer = document.referrer || '';
    }

    if (window && window.screen) {
        data.sh = window.screen.height || 0;
        data.sw = window.screen.width || 0;
        data.scd = window.screen.colorDepth || 0;
    }

    if (navigator) {
        data.lang = navigator.language || '';
        data.cookieEnabled = navigator.cookieEnabled;
        data.userAgent = navigator.userAgent;
        data.platform = navigator.platform;
    }

定义的事件类型接口:

export interface EventDescriptor {
    category?: 'global' | 'default' | string;
    action: string;
    userId?: string;
    time?: number;
    pageUrl?: string;
    payload?: any;
}

调用方式示例:

        var _gaq = _gaq || [];

        _gaq.push({
            category: 'global',
            action: 'pageView'
        });
watermoonlx commented 6 years ago

@hstarorg @Lession711 SDK第一阶段内容已基本完成。 目前定义了如下API:

ga.setUid(uid:string); //设置uid

ga.pageView(data?:any); //记录当前页面基本信息。data参数可选,用于覆盖默认的记录值。

ga.track(action:string,payload:any); //若不设置category,则默认category为'default'。
ga.track(action:string,category:string,payload:any);

参考了神策数据的API,将trackEvent简化为了track。

发送给后台的数据结构如下:

export interface EventDescriptor {
    /** category */
    c: 'global' | 'default' | string;
    /** action */
    a: string;
    /** uid */
    uid?: string;
    /** time */
    t: number;
    /** page url */
    url: string;
    /** payload */
    d?: any;
}

与@Lession711 定义的接口也些许不同。

一个示例请求如下:

http://localhost:3000/ga.gif?a=pageView&c=global&d=%7B%22nl%22%3A%22zh-CN%22%2C%22np%22%3A%22Win32%22%2C%22nce%22%3Atrue%2C%22nje%22%3Afalse%2C%22nmtp%22%3A0%2C%22nd%22%3Anull%2C%22ndm%22%3A8%2C%22ndc%22%3A8%2C%22sr%22%3A%221920%2A1080%22%2C%22scd%22%3A24%2C%22dc%22%3A%22UTF-8%22%2C%22dr%22%3A%22http%3A%2F%2Flocalhost%3A3000%2F%22%2C%22dt%22%3A%22Galaxy%20Client%22%7D&t=1526996701299&uid=jx02&url=http%3A%2F%2Flocalhost%3A3000%2F
hstarorg commented 6 years ago

@watermoonlx 建议把category做为第三个参数,并设置默认值,这样,api如下:ga.track(action: string, payload: any, category = 'default')

hstarorg commented 6 years ago

另外,更建议使用 trackEvent trackPageView(path: string, payload: any)

watermoonlx commented 6 years ago

category放在第三个参数感觉不太好欸,它毕竟和action关联更近。

hstarorg commented 6 years ago

@watermoonlx 可选参数放最后。类似重载的感觉。

watermoonlx commented 6 years ago

已修改API: https://github.com/NESC-Graviton/galaxy/tree/master/packages/galaxy-sdk