Open hstarorg opened 6 years ago
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
}
```
Empty
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
}]
```
Empty
目前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'
});
@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
@watermoonlx 建议把category做为第三个参数,并设置默认值,这样,api如下:ga.track(action: string, payload: any, category = 'default')
另外,更建议使用 trackEvent
trackPageView(path: string, payload: any)
category放在第三个参数感觉不太好欸,它毕竟和action关联更近。
@watermoonlx 可选参数放最后。类似重载的感觉。
客户端收集
基础浏览器数据
${screen.width}*${screen.height}
页面加载性能数据
服务端收集
请求数据
API定义