aiAssistantTrack.js
1.59 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { storageApi } from '@/utils/cache'
const EVENT = {
BALL_CLICK: 'app_ai_ball_click',
THINKING_TRIGGER: 'app_ai_thinking_trigger',
QUESTION_SELECT: 'app_ai_question_select',
ANSWER_RENDER: 'app_ai_answer_render',
ERROR: 'app_ai_error'
}
function getUserId() {
const { uuid } = storageApi.getUserInfo() || {}
return uuid || ''
}
function getSessionId() {
return storageApi.getSessionId() || ''
}
function getPageContext() {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
return currentPage?.route || '/'
}
function track(eventCode, businessParam = {}) {
if (!uni.$track) return
uni.$track.add({
eventCode,
businessParam: {
user_id: getUserId(),
session_id: getSessionId(),
...businessParam
}
})
}
export function trackAiBallClick() {
track(EVENT.BALL_CLICK, {
timestamp: Date.now(),
page_context: getPageContext()
})
}
export function trackAiThinkingTrigger(audioDuration) {
track(EVENT.THINKING_TRIGGER, {
audio_duration: audioDuration
})
}
export function trackAiQuestionSelect(intentId, intentText) {
track(EVENT.QUESTION_SELECT, {
intent_id: intentId,
intent_text: intentText
})
}
export function trackAiAnswerRender(intentId, renderTime) {
track(EVENT.ANSWER_RENDER, {
intent_id: intentId,
render_time: renderTime
})
}
export function trackAiError(errorType) {
track(EVENT.ERROR, {
error_type: errorType,
timestamp: Date.now()
})
}
export const AI_ERROR_TYPE = {
TIMEOUT: 'timeout',
NETWORK: 'network_disconnect',
NO_ANSWER: 'no_answer',
OTHER: 'other'
}