1- import React from 'react' ;
2- import { Routes , Route } from 'react-router-dom' ;
1+ import React , { useEffect } from 'react' ;
2+ import { Routes , Route , useLocation } from 'react-router-dom' ;
33import Home from './pages/Home' ;
44import Plugin from './pages/Plugin' ;
55import EnhancedPlugin from './pages/EnhancedPlugin' ;
@@ -11,8 +11,48 @@ import Navbar from './components/Navbar';
1111import Footer from './components/Footer' ;
1212import FloatingActionButton from './components/FloatingActionButton' ;
1313import ErrorBoundary from './components/ErrorBoundary' ;
14+ import analytics from './services/analytics' ;
1415
1516function App ( ) {
17+ const location = useLocation ( ) ;
18+
19+ // Initialize Google Analytics
20+ useEffect ( ( ) => {
21+ analytics . initialize ( ) ;
22+ } , [ ] ) ;
23+
24+ // Track page views on route changes
25+ useEffect ( ( ) => {
26+ const getPageTitle = ( pathname ) => {
27+ const routes = {
28+ '/' : 'Home - Quantum Field Kit' ,
29+ '/glossary' : 'Glossary - Quantum Field Kit' ,
30+ '/circuit-designer' : 'Circuit Designer - Quantum Field Kit'
31+ } ;
32+
33+ // Handle dynamic routes
34+ if ( pathname . startsWith ( '/plugin/' ) ) {
35+ const pluginKey = pathname . split ( '/' ) [ 2 ] ;
36+ return `${ pluginKey } Plugin - Quantum Field Kit` ;
37+ }
38+
39+ if ( pathname . startsWith ( '/legacy-plugin/' ) ) {
40+ const pluginKey = pathname . split ( '/' ) [ 2 ] ;
41+ return `${ pluginKey } Legacy Plugin - Quantum Field Kit` ;
42+ }
43+
44+ if ( pathname . startsWith ( '/category/' ) ) {
45+ const category = pathname . split ( '/' ) [ 2 ] ;
46+ return `${ category } Category - Quantum Field Kit` ;
47+ }
48+
49+ return routes [ pathname ] || 'Quantum Field Kit' ;
50+ } ;
51+
52+ const title = getPageTitle ( location . pathname ) ;
53+ analytics . trackPageView ( location . pathname , title ) ;
54+ } , [ location ] ) ;
55+
1656 return (
1757 < ErrorBoundary >
1858 < div className = "App app-shell min-h-screen bg-base-100 text-base-content" >
0 commit comments