@@ -23,6 +23,14 @@ const WIDTH_19_INCH = Math.round(19 * PIXELS_PER_INCH);
2323const WIDTH_10_INCH = Math . round ( 10 * PIXELS_PER_INCH ) ;
2424const RAIL_WIDTH = Math . round ( 0.625 * PIXELS_PER_INCH ) ;
2525
26+ // Add window augmentation for Google Analytics
27+ declare global {
28+ interface Window {
29+ dataLayer : any [ ] ;
30+ gtag : ( ...args : any [ ] ) => void ;
31+ }
32+ }
33+
2634export default function RackPlanner ( ) {
2735 // --- State ---
2836 const [ isDarkMode , setIsDarkMode ] = useState ( ( ) => {
@@ -97,6 +105,31 @@ export default function RackPlanner() {
97105 localStorage . setItem ( 'animationsEnabled' , String ( areAnimationsEnabled ) ) ;
98106 } , [ areAnimationsEnabled ] ) ;
99107
108+ // Handle Google Analytics
109+ useEffect ( ( ) => {
110+ const gaId = import . meta. env . VITE_GOOGLE_ANALYTICS_ID ;
111+
112+ if ( gaId && typeof window !== 'undefined' ) {
113+ // Load the script
114+ const script = document . createElement ( 'script' ) ;
115+ script . async = true ;
116+ script . src = `https://www.googletagmanager.com/gtag/js?id=${ gaId } ` ;
117+ document . head . appendChild ( script ) ;
118+
119+ // Initialize dataLayer
120+ window . dataLayer = window . dataLayer || [ ] ;
121+ function gtag ( ...args : any [ ] ) {
122+ window . dataLayer . push ( args ) ;
123+ }
124+ window . gtag = gtag ;
125+
126+ gtag ( 'js' , new Date ( ) ) ;
127+ gtag ( 'config' , gaId ) ;
128+
129+ console . log ( 'Google Analytics initialized with ID:' , gaId ) ;
130+ }
131+ } , [ ] ) ;
132+
100133 // Handle Responsive Scaling
101134 useEffect ( ( ) => {
102135 const handleResize = ( ) => {
0 commit comments