Feature(custom): add tk analytic

This commit is contained in:
Kuingsmile
2023-10-13 10:11:49 +08:00
parent 567af4588b
commit e8ea905a94
7 changed files with 94 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
/* eslint-disable camelcase */
import {
TALKING_DATA_APPID, TALKING_DATA_EVENT
} from '~/universal/events/constants'
import pkg from 'root/package.json'
import { ipcRenderer } from 'electron'
import { handleTalkingDataEvent } from './common'
const { version } = pkg
export const initTalkingData = () => {
setTimeout(() => {
const talkingDataScript = document.createElement('script')
talkingDataScript.src = `http://sdk.talkingdata.com/app/h5/v1?appid=${TALKING_DATA_APPID}&vn=${version}&vc=${version}`
const head = document.getElementsByTagName('head')[0]
head.appendChild(talkingDataScript)
}, 0)
}
ipcRenderer.on(TALKING_DATA_EVENT, (_, data: ITalkingDataOptions) => {
handleTalkingDataEvent(data)
})

View File

@@ -2,6 +2,16 @@ import { isReactive, isRef, toRaw, unref } from 'vue'
import { ipcRenderer } from 'electron'
import { OPEN_URL } from '~/universal/events/constants'
const isDevelopment = process.env.NODE_ENV !== 'production'
export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
const { EventId, Label = '', MapKv = {} } = data
MapKv.from = window.location.href
window.TDAPP.onEvent(EventId, Label, MapKv)
if (isDevelopment) {
console.log('talkingData', data)
}
}
/**
* get raw data from reactive or ref
*/