Skip to content

Commit a7e98e5

Browse files
committed
fix: google analytics tracking issue fixed
1 parent ec27354 commit a7e98e5

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

index.html

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525
<meta name="twitter:title" content="ZENUI LIBRARY - Open-Source Free Templates & Components Library">
2626
<meta name="twitter:description" content="Elevate your project with free UI components, customizable icons, and a color palette. No dependencies required">
2727

28-
<!-- Google tag (gtag.js) -->
29-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-V0DX4Z7PRF"></script>
30-
<script>
31-
window.dataLayer = window.dataLayer || [];
32-
function gtag(){dataLayer.push(arguments);}
33-
gtag('js', new Date());
34-
35-
gtag('config', 'G-V0DX4Z7PRF');
36-
</script>
37-
3828
<title>ZENUI LIBRARY - Open-Source Free Templates & Components Library</title>
3929
</head>
4030
<body class="light">

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"react": "^18.2.0",
2020
"react-countup": "^6.5.3",
2121
"react-dom": "^18.2.0",
22+
"react-ga4": "^2.1.0",
2223
"react-helmet": "^6.1.0",
2324
"react-icons": "^4.12.0",
2425
"react-parallax-tilt": "^1.7.228",

src/App.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ import { MenuProvider } from "./Context/MenuContext.jsx";
130130
import GithubActivityGraphPage from "./Pages/Components/Data Display/GithubActivityGraphPage.jsx";
131131
import ComparisonCardPage from "./Pages/Components/Surfaces/ComparisonCardPage.jsx";
132132
import LazyImagePackagePlaygroundPage from "./Pages/LazyImagePackagePlaygroundPage.jsx";
133+
import usePageTracking from "./CustomHooks/usePageTracking.js";
133134

134135

135136
const App = () => {
136137
const [isCookie, setIsCookie] = useState(false)
137138

139+
usePageTracking()
140+
138141
let Title = document.title;
139142
window.addEventListener('blur', () => {
140143
document.title = 'Get more components 😍';

src/CustomHooks/usePageTracking.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useLocation } from "react-router-dom";
2+
import { useEffect } from "react";
3+
import ReactGA from "react-ga4";
4+
5+
const usePageTracking = () => {
6+
const location = useLocation();
7+
8+
useEffect(() => {
9+
ReactGA.send({ hitType: "pageview", page: location.pathname + location.search });
10+
}, [location]);
11+
};
12+
13+
export default usePageTracking;

src/main.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import ReactDOM from "react-dom/client";
33
import App from "./App";
44
import "./index.css";
55
import { BrowserRouter } from "react-router-dom";
6+
import ReactGA from 'react-ga4';
7+
8+
ReactGA.initialize('G-V0DX4Z7PRF');
9+
ReactGA.send('pageview');
610

711
ReactDOM.createRoot(document.getElementById("root")).render(
812
<React.StrictMode>

0 commit comments

Comments
 (0)