EventTrackingController.ts
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { AxiosStatic } from "axios";
/** 扩展参数:`paramValue` 以 JSON 可序列化形式提交 */
export type EventTrackingParamType =
| "STRING"
| "NUMBER"
| "BOOLEAN"
| "ARRAY"
| "OBJECT";
export interface EventTrackingBusinessKeyVO {
businessType: string;
businessKey: string;
}
export interface EventTrackingParamVO {
paramKey: string;
paramValue: string | number | boolean | null;
paramType?: EventTrackingParamType;
}
export interface EventTrackingBatchItem {
eventCode: string;
eventTime?: string;
duration?: number;
remark?: string;
businessKeys?: EventTrackingBusinessKeyVO[];
params?: EventTrackingParamVO[];
}
export interface EventTrackingBatchSaveBody {
events: EventTrackingBatchItem[];
}
function defaultBatchSavePath(): string {
const p = import.meta.env.VITE_APP_EVENT_TRACKING_PATH;
return (typeof p === "string" && p.trim().length > 0
? p.trim()
: "eventTracking/batchSave") as string;
}
/**
* POST 业务埋点批量上报(与其它 Controller 一致走全局 axios / Token)
*/
export class EventTrackingController {
static batchSave(
axios: AxiosStatic,
body: EventTrackingBatchSaveBody,
path?: string
): Promise<unknown> {
return axios
.post(path ?? defaultBatchSavePath(), body)
.then((r) => r.data);
}
}