File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -10,13 +10,15 @@ import GitHubRibbon from './components/GitHubRibbon'
10
10
import PageTitle from './components/PageTitle'
11
11
import './gh-fork-ribbon.css' ;
12
12
import './styles/github-ribbon-fix.css' ;
13
+ import BaiduAnalytics from './components/BaiduAnalytics'
13
14
14
15
const App = ( ) => {
15
16
return (
16
17
< Router >
17
18
< div className = "App" >
18
19
< PageTitle />
19
20
< GitHubRibbon repositoryUrl = "https://github.com/JSREP/crawler-leetcode" />
21
+ < BaiduAnalytics siteId = "b4fcc22834ded2c9864e661e6a5a634d" />
20
22
< NavBar />
21
23
< div className = "content-wrapper" style = { { padding : '20px 0' } } >
22
24
< Routes >
Original file line number Diff line number Diff line change
1
+ import { useEffect } from 'react' ;
2
+
3
+ declare global {
4
+ interface Window {
5
+ _hmt : any [ ] ;
6
+ }
7
+ }
8
+
9
+ interface BaiduAnalyticsProps {
10
+ siteId : string ;
11
+ }
12
+
13
+ const BaiduAnalytics : React . FC < BaiduAnalyticsProps > = ( { siteId } ) => {
14
+ useEffect ( ( ) => {
15
+ // 初始化_hmt数组
16
+ window . _hmt = window . _hmt || [ ] ;
17
+
18
+ // 创建百度统计脚本
19
+ const script = document . createElement ( 'script' ) ;
20
+ script . async = true ;
21
+ script . src = `https://hm.baidu.com/hm.js?${ siteId } ` ;
22
+
23
+ // 添加脚本到页面
24
+ document . head . appendChild ( script ) ;
25
+
26
+ // 清理函数
27
+ return ( ) => {
28
+ document . head . removeChild ( script ) ;
29
+ } ;
30
+ } , [ siteId ] ) ;
31
+
32
+ return null ;
33
+ } ;
34
+
35
+ export default BaiduAnalytics ;
You can’t perform that action at this time.
0 commit comments