File tree Expand file tree Collapse file tree 2 files changed +20
-19
lines changed
Expand file tree Collapse file tree 2 files changed +20
-19
lines changed Original file line number Diff line number Diff line change 11import { useMediaQuery } from '@chakra-ui/react' ;
2- import { useEffect , useState } from 'react' ;
3- import ReactGA from 'react-ga4' ;
4- import { useLocation } from 'react-router-dom' ;
2+
53import MobileHeader from './MobileHeader' ;
64import PcHeader from './PcHeader' ;
75import { devices } from '@/styles/theme' ;
86
97const Header = ( ) => {
108 const [ isLargerThanTablet ] = useMediaQuery ( devices . tablet ) ;
11- const [ initialized , setInitialized ] = useState ( false ) ;
12- const location = useLocation ( ) ;
13-
14- useEffect ( ( ) => {
15- if ( ! window . location . href . includes ( 'localhost' ) ) {
16- ReactGA . initialize ( import . meta. env . VITE_GOOGLE_ANALYTICS_TRAKING_ID ) ;
17- setInitialized ( true ) ;
18- }
19- } , [ ] ) ;
20-
21- useEffect ( ( ) => {
22- if ( initialized ) {
23- ReactGA . set ( { page : location . pathname } ) ;
24- ReactGA . send ( 'pageview' ) ;
25- }
26- } , [ initialized , location ] ) ;
279
2810 return (
2911 < header > { isLargerThanTablet ? < PcHeader /> : < MobileHeader /> } </ header >
Original file line number Diff line number Diff line change 11import { Box } from '@chakra-ui/react' ;
2+ import { useEffect , useState } from 'react' ;
3+ import ReactGA from 'react-ga4' ;
4+ import { useLocation } from 'react-router-dom' ;
25import { Outlet } from 'react-router-dom' ;
36import { Header } from '@/components' ;
47import { HEADER_HEIGHT } from '@/components/Header/constants' ;
58import UserFeedbackFab from '@/components/UserFeedbackFab/UserFeedbackFab' ;
69
710const Layout = ( ) => {
11+ const [ initialized , setInitialized ] = useState ( false ) ;
12+ const location = useLocation ( ) ;
13+ useEffect ( ( ) => {
14+ if ( ! window . location . href . includes ( 'localhost' ) ) {
15+ ReactGA . initialize ( import . meta. env . VITE_GOOGLE_ANALYTICS_TRAKING_ID ) ;
16+ setInitialized ( true ) ;
17+ }
18+ } , [ ] ) ;
19+
20+ useEffect ( ( ) => {
21+ if ( initialized ) {
22+ ReactGA . set ( { page : location . pathname } ) ;
23+ ReactGA . send ( 'pageview' ) ;
24+ }
25+ } , [ initialized , location ] ) ;
26+
827 return (
928 < >
1029 < Header />
You can’t perform that action at this time.
0 commit comments