restore google analytics feature

This commit is contained in:
Athou
2023-05-03 20:29:12 +02:00
parent cfc07764b4
commit 4828c03bbf
3 changed files with 1811 additions and 8354 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -40,6 +40,7 @@
"react-async-hook": "^4.0.0", "react-async-hook": "^4.0.0",
"react-contexify": "^6.0.0", "react-contexify": "^6.0.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-ga4": "^2.1.0",
"react-icons": "^4.7.1", "react-icons": "^4.7.1",
"react-infinite-scroller": "^1.2.6", "react-infinite-scroller": "^1.2.6",
"react-redux": "^8.0.5", "react-redux": "^8.0.5",

View File

@@ -2,7 +2,6 @@ import { i18n } from "@lingui/core"
import { I18nProvider } from "@lingui/react" import { I18nProvider } from "@lingui/react"
import { ColorScheme, ColorSchemeProvider, MantineProvider } from "@mantine/core" import { ColorScheme, ColorSchemeProvider, MantineProvider } from "@mantine/core"
import { useColorScheme } from "@mantine/hooks" import { useColorScheme } from "@mantine/hooks"
import useLocalStorage from "use-local-storage"
import { ModalsProvider } from "@mantine/modals" import { ModalsProvider } from "@mantine/modals"
import { NotificationsProvider } from "@mantine/notifications" import { NotificationsProvider } from "@mantine/notifications"
import { Constants } from "app/constants" import { Constants } from "app/constants"
@@ -28,8 +27,10 @@ import { LoginPage } from "pages/auth/LoginPage"
import { PasswordRecoveryPage } from "pages/auth/PasswordRecoveryPage" import { PasswordRecoveryPage } from "pages/auth/PasswordRecoveryPage"
import { RegistrationPage } from "pages/auth/RegistrationPage" import { RegistrationPage } from "pages/auth/RegistrationPage"
import React, { useEffect } from "react" import React, { useEffect } from "react"
import { HashRouter, Navigate, Route, Routes, useNavigate } from "react-router-dom" import ReactGA from "react-ga4"
import { HashRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom"
import Tinycon from "tinycon" import Tinycon from "tinycon"
import useLocalStorage from "use-local-storage"
function Providers(props: { children: React.ReactNode }) { function Providers(props: { children: React.ReactNode }) {
const preferredColorScheme = useColorScheme() const preferredColorScheme = useColorScheme()
@@ -111,6 +112,21 @@ function RedirectHandler() {
return null return null
} }
function GoogleAnalyticsHandler() {
const location = useLocation()
const googleAnalyticsCode = useAppSelector(state => state.server.serverInfos?.googleAnalyticsCode)
useEffect(() => {
if (googleAnalyticsCode) ReactGA.initialize(googleAnalyticsCode)
}, [googleAnalyticsCode])
useEffect(() => {
ReactGA.send({ hitType: "pageview", page: location.pathname })
}, [location])
return null
}
function FaviconHandler() { function FaviconHandler() {
const root = useAppSelector(state => state.tree.rootCategory) const root = useAppSelector(state => state.tree.rootCategory)
useEffect(() => { useEffect(() => {
@@ -135,6 +151,7 @@ export function App() {
<> <>
<FaviconHandler /> <FaviconHandler />
<HashRouter> <HashRouter>
<GoogleAnalyticsHandler />
<RedirectHandler /> <RedirectHandler />
<AppRoutes /> <AppRoutes />
</HashRouter> </HashRouter>