|
@@ -1,5 +1,7 @@
|
|
import ls from '@livesession/sdk'
|
|
import ls from '@livesession/sdk'
|
|
import { FC, useCallback, useEffect } from 'react'
|
|
import { FC, useCallback, useEffect } from 'react'
|
|
|
|
+import ReactGA from 'react-ga'
|
|
|
|
+import { useLocation } from 'react-router-dom'
|
|
|
|
|
|
import { atlasConfig } from '@/config'
|
|
import { atlasConfig } from '@/config'
|
|
import { BUILD_ENV } from '@/config/env'
|
|
import { BUILD_ENV } from '@/config/env'
|
|
@@ -8,6 +10,7 @@ import { usePersonalDataStore } from '@/providers/personalData'
|
|
export const AnalyticsManager: FC = () => {
|
|
export const AnalyticsManager: FC = () => {
|
|
const cookiesAccepted = usePersonalDataStore((state) => state.cookiesAccepted)
|
|
const cookiesAccepted = usePersonalDataStore((state) => state.cookiesAccepted)
|
|
const analyticsEnabled = BUILD_ENV === 'production' && cookiesAccepted
|
|
const analyticsEnabled = BUILD_ENV === 'production' && cookiesAccepted
|
|
|
|
+ const location = useLocation()
|
|
|
|
|
|
const initUsersnap = useCallback(() => {
|
|
const initUsersnap = useCallback(() => {
|
|
if (!atlasConfig.analytics.usersnap?.id) return
|
|
if (!atlasConfig.analytics.usersnap?.id) return
|
|
@@ -36,6 +39,12 @@ export const AnalyticsManager: FC = () => {
|
|
ls.newPageView()
|
|
ls.newPageView()
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
+ const initGA = useCallback(() => {
|
|
|
|
+ if (!atlasConfig.analytics.GA?.id) return
|
|
|
|
+
|
|
|
|
+ ReactGA.initialize(atlasConfig.analytics.GA.id)
|
|
|
|
+ }, [])
|
|
|
|
+
|
|
// initialize livesession
|
|
// initialize livesession
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (!analyticsEnabled) return
|
|
if (!analyticsEnabled) return
|
|
@@ -50,5 +59,20 @@ export const AnalyticsManager: FC = () => {
|
|
initUsersnap()
|
|
initUsersnap()
|
|
}, [analyticsEnabled, initUsersnap])
|
|
}, [analyticsEnabled, initUsersnap])
|
|
|
|
|
|
|
|
+ //initialize Google Analytics
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (!analyticsEnabled) return
|
|
|
|
+
|
|
|
|
+ initGA()
|
|
|
|
+ }, [analyticsEnabled, initGA])
|
|
|
|
+
|
|
|
|
+ //track pageview in GA
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (!analyticsEnabled || !atlasConfig.analytics.GA?.id) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ ReactGA.pageview(location.pathname)
|
|
|
|
+ }, [location.pathname, analyticsEnabled])
|
|
|
|
+
|
|
return null
|
|
return null
|
|
}
|
|
}
|