File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 5
5
< link rel ="icon " type ="image/svg+xml " href ="/vite.svg " />
6
6
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7
7
< title > E-Bikes Portal</ title >
8
+
9
+ <!-- Google Analytics -->
10
+ < script async src ="https://www.googletagmanager.com/gtag/js?id=%VITE_GA_MEASUREMENT_ID% "> </ script >
11
+ < script >
12
+ window . dataLayer = window . dataLayer || [ ] ;
13
+ function gtag ( ) { dataLayer . push ( arguments ) ; }
14
+ gtag ( 'js' , new Date ( ) ) ;
15
+ gtag ( 'config' , '%VITE_GA_MEASUREMENT_ID%' ) ;
16
+ </ script >
8
17
</ head >
9
18
< body >
10
19
< div id ="root "> </ div >
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ import { LicenseType, User } from '../db/users';
11
11
import Analyze from './components/analytics/Analyze' ;
12
12
import AIAssistent from './components/analytics/AIAssistent' ;
13
13
import DemoScript from './components/auth/DemoScript' ;
14
- import { useMobile } from './hooks/useMobile' ;
15
14
import MobileRouteGuard from './components/MobileRouteGuard' ;
15
+ import { useGA } from './hooks/useGA' ;
16
16
17
17
interface AppContextType {
18
18
notifications : NotificationItem [ ] ;
@@ -76,6 +76,8 @@ export const UserProvider = ({ children }: { children: ReactNode }) => {
76
76
}
77
77
78
78
function App ( ) {
79
+ // Initialize Google Analytics tracking
80
+ useGA ( ) ;
79
81
80
82
return (
81
83
< div className = { styles . root } >
Original file line number Diff line number Diff line change
1
+ import { useEffect } from 'react' ;
2
+ import { useLocation } from 'react-router-dom' ;
3
+
4
+ declare global {
5
+ interface Window {
6
+ gtag : ( command : string , targetId : string , config ?: any ) => void ;
7
+ }
8
+ }
9
+
10
+ export const useGA = ( ) => {
11
+ const location = useLocation ( ) ;
12
+
13
+ useEffect ( ( ) => {
14
+ // Track page view when location changes
15
+ if ( window . gtag && import . meta. env . VITE_GA_MEASUREMENT_ID ) {
16
+ window . gtag ( 'config' , import . meta. env . VITE_GA_MEASUREMENT_ID , {
17
+ page_path : location . pathname + location . search ,
18
+ } ) ;
19
+ }
20
+ } , [ location ] ) ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments