-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feature: add baidu tongji for analytics
- Loading branch information
1 parent
3fd6e4e
commit f536391
Showing
8 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export const SHOW_INPUT_BOX = 'SHOW_INPUT_BOX' | ||
export const SHOW_INPUT_BOX_RESPONSE = 'SHOW_INPUT_BOX_RESPONSE' | ||
export const TOGGLE_SHORTKEY_MODIFIED_MODE = 'TOGGLE_SHORTKEY_MODIFIED_MODE' | ||
export const BAIDU_TONGJI_INIT = 'BAIDU_TONDJI_INIT' | ||
export const BAIDU_TONGJI_INIT_RES = 'BAIDU_TONDJI_INIT_RES' | ||
export const BAIDU_TONGJI_CODE = '19a7ebdbb87f2403773c7ab0cae16d21' | ||
export const BAIDU_TONGJI_EVENT = 'BAIDU_TONGJI_EVENT' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,8 @@ declare global { | |
[elem: string]: any | ||
} | ||
} | ||
|
||
interface Window { | ||
_hmt: any[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters