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'
1010import PageTitle from './components/PageTitle'
1111import './gh-fork-ribbon.css' ;
1212import './styles/github-ribbon-fix.css' ;
13+ import BaiduAnalytics from './components/BaiduAnalytics'
1314
1415const App = ( ) => {
1516 return (
1617 < Router >
1718 < div className = "App" >
1819 < PageTitle />
1920 < GitHubRibbon repositoryUrl = "https://github.com/JSREP/crawler-leetcode" />
21+ < BaiduAnalytics siteId = "b4fcc22834ded2c9864e661e6a5a634d" />
2022 < NavBar />
2123 < div className = "content-wrapper" style = { { padding : '20px 0' } } >
2224 < 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