UNPKG

miniprogram-logger

Version:

It is used to log and gather statistics of users' behavior.

29 lines (28 loc) 812 B
import { Reporter } from "../common/reporter"; import { guid } from "../common/guid"; /** * 默认 Telemetry对象转换函数 * 字段中注入`id`和`extension.timestamp` * @param data LogObject */ export function TelemetryTransformFunction(data) { if (typeof data === "object") { if (!data.id) { data.id = guid(); } if (!data.extension) { data.extension = {}; } data.extension.timestamp = new Date().toISOString(); } return data; } export class ReportAnalytics extends Reporter { constructor(tableName, context) { super(tableName, ['action', 'param', 'extension', 'user'], context); this.TransformFunction = TelemetryTransformFunction; } record() { this.report.apply(this, arguments); } }