Commit 608115ae by 岑成威

fix: 埋点

1 parent 2d017eb1
......@@ -236,6 +236,14 @@ import {
import { storageApi } from '@/utils/cache'
import RecordService from '@/utils/recordManager/RecordService.js'
import { getAiStreamSession } from '@/utils/aiAssistant/aiStreamSession.js'
import {
trackAiBallClick,
trackAiThinkingTrigger,
trackAiQuestionSelect,
trackAiAnswerRender,
trackAiError,
AI_ERROR_TYPE
} from '@/utils/aiAssistant/aiAssistantTrack.js'
import { TransportType } from '@/utils/socket'
const DEMO_CAPTURE_SECONDS = 60
const HELP_ANSWER_REQUEST_TIMEOUT = 90000
......@@ -397,6 +405,7 @@ export default {
// #ifdef APP-PLUS
if (this.uiState === 'thinking') return
if (this.menuVisible || this.questionMenuVisible || this.introVisible) return
trackAiBallClick()
if (this.abnormalBubbleVisible) {
this.abnormalBubbleVisible = false
this._pendingBallTap = true
......@@ -500,6 +509,7 @@ export default {
this.qaList = []
this.selectedQaIndex = -1
trackAiThinkingTrigger(DEMO_CAPTURE_SECONDS)
this._logAi('info', `startThinking session=${sessionId}`)
await this.$nextTick()
......@@ -522,6 +532,7 @@ export default {
return
}
this._logAi('error', `startThinking failed: ${(e && e.message) || e}`)
trackAiError(this._resolveAiErrorType(e))
this.streamStatus = 'error'
this.uiState = 'idle'
this.resultVisible = false
......@@ -534,11 +545,18 @@ export default {
// #endif
},
selectQa(idx) {
const item = this.qaList[idx]
if (item) {
trackAiQuestionSelect(idx, item.query || '')
}
this.selectedQaIndex = idx
if (this.questionMenuVisible) {
this.questionMenuVisible = false
this.resultVisible = true
}
if (item && item.answer) {
this._trackAnswerRenderForIntent(idx)
}
},
/** 打开面板即开始监听/模拟流式 markdown,边收边渲染 */
beginStreamSession() {
......@@ -705,6 +723,7 @@ export default {
if (!this.qaList.length) {
this._logAi('info', 'response empty, no questions to show')
trackAiError(AI_ERROR_TYPE.NO_ANSWER)
return
}
if (isCancelled()) {
......@@ -720,9 +739,26 @@ export default {
this.questionMenuVisible = false
this.selectedQaIndex = 0
this.resultVisible = true
if (this.qaList[0] && this.qaList[0].answer) {
this._trackAnswerRenderForIntent(0)
}
}
// #endif
},
_trackAnswerRenderForIntent(intentId) {
const renderStart = Date.now()
this.$nextTick(() => {
trackAiAnswerRender(intentId, Date.now() - renderStart)
})
},
_resolveAiErrorType(err) {
const msg = String((err && (err.errMsg || err.message)) || '')
if (/timeout/i.test(msg)) return AI_ERROR_TYPE.TIMEOUT
if (this._isHelpAnswerNetworkError(err) || /连接失败|network/i.test(msg)) {
return AI_ERROR_TYPE.NETWORK
}
return AI_ERROR_TYPE.OTHER
},
_logAi(level, msg) {
// #ifdef APP-PLUS
const text = `[AiAssistant] ${msg}`
......
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'
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!