Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hstarorg opened this issue May 16, 2018 · 8 comments
Open

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

hstarorg opened this issue May 16, 2018 · 8 comments
Labels
question Further information is requested

Comments

@hstarorg
Copy link
Contributor

hstarorg commented May 16, 2018

客户端收集

基础浏览器数据

数据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)
@hstarorg hstarorg added the question Further information is requested label May 16, 2018
@Lession711
Copy link

Lession711 commented May 17, 2018

Rest API

PageView

POST /api/report

  • Request Body

    {
        "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
    }
  • Response Body
    Empty

Event

PUT /api/report

  • Request Body

    [{
        "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
    }]
  • Response Body
    Empty

@watermoonlx
Copy link

目前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'
        });

@NESC-Graviton NESC-Graviton deleted a comment from Lession711 May 18, 2018
@watermoonlx
Copy link

watermoonlx commented May 22, 2018

@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 定义的接口也些许不同。

  • category简写做c。不太明白为什么@Lession711定义g
  • 增加了url,代表当前页面的url。
  • uid保持为uid,与url相区别。
    另外,由于d属性本身是一个对象,那么在使用图片形式往后端发送数据时,我会将d先序列化为一个JSON字符串,然后再将其作为一个查询参数进行发送。那么后端可能需要手动调用一次反序列化,来将d还原。

一个示例请求如下:

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
Copy link
Contributor Author

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

@hstarorg
Copy link
Contributor Author

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

@watermoonlx
Copy link

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

@hstarorg
Copy link
Contributor Author

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

@watermoonlx
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants