mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-05 15:37:21 +08:00
✨ Feature: add baidu tongji for analytics
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/* eslint-disable camelcase */
|
||||
import { ipcRenderer } from 'electron'
|
||||
import {
|
||||
BAIDU_TONGJI_INIT,
|
||||
BAIDU_TONGJI_INIT_RES,
|
||||
BAIDU_TONGJI_EVENT
|
||||
} from '~/universal/events/constants'
|
||||
import { handleBaiduTongJiEvent } from './common'
|
||||
|
||||
ipcRenderer.on(BAIDU_TONGJI_INIT_RES, (_, scriptContent) => {
|
||||
window._hmt = window._hmt || []
|
||||
const hm = document.createElement('script')
|
||||
hm.text = scriptContent
|
||||
const head = document.getElementsByTagName('head')[0]
|
||||
head.appendChild(hm)
|
||||
})
|
||||
|
||||
ipcRenderer.on(BAIDU_TONGJI_EVENT, (_, data: IBaiduTongJiOptions) => {
|
||||
handleBaiduTongJiEvent(data)
|
||||
})
|
||||
|
||||
export const initBaiduTongJi = () => {
|
||||
setTimeout(() => {
|
||||
ipcRenderer.send(BAIDU_TONGJI_INIT)
|
||||
}, 0)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
/* eslint-disable camelcase */
|
||||
export const handleBaiduTongJiEvent = (data: IBaiduTongJiOptions) => {
|
||||
const { category, action, opt_label = '', opt_value = Date.now() } = data
|
||||
window._hmt.push(['_trackEvent', category, action, opt_label, opt_value])
|
||||
if (isDevelopment) {
|
||||
console.log('baidu tongji', data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user