react-ga4
react-ga4 copied to clipboard
is this library dead?
Can anyone confirm if this library is still alive? For the comments that I'm reading here make me think that this doesn't work very well?
does not work with GA4 for me. Debug sent work with every kind of GA Account ID even fake one. And does not firing any errors.
Works for me!
NOTE: TURN OFF YOUR ADBLOCK WHEN TESTING
In your App.js
import ReactGA4 from 'react-ga4';
ReactGA4.initialize("G-XXXXXX");
Create a usePageTracking.js
// usePageTracking.js
import { useEffect} from "react";
import { useLocation } from "react-router-dom";
const usePageTracking = () => {
const location = useLocation();
useEffect(() => {
// track pageview with gtag / react-ga / react-ga4, for example:
window.gtag("event", "page_view", {
page_path: location.pathname + location.search,
});
}, [location]);
};
export default usePageTracking;
Make sure you add this inside your Router, mine is in my Navbar component.
//Navbar.js
const Navbar = () => {
usePageTracking();
return (...);
};
Yeah, this library is dead. We should all be moving to firebase analytics.
Well maintained and implements GA4.
@wmonecke I'm not quite sure I understand: do firebase analytics work for other tech stacks? Or are you recommending anyone using ReactJS who wants GA support use Firebase?
@boxabirds I say that for any tech stack
Works for me!
const usePageTracking = () => { const location = useLocation();
useEffect(() => { // track pageview with gtag / react-ga / react-ga4, for example: window.gtag("event", "page_view", { page_path: location.pathname + location.search, }); }, [location]); };
Hello! do you mean the following ReactGA.gtag
? (Not window.gtag
)
ReactGA.gtag("event", "page_view", {
page_path: location.pathname + location.search,
});
Actually should be this now?
useEffect(() => {
// track pageview with gtag / react-ga / react-ga4, for example:
ReactGA.send({ hitType: "pageview", page: location.pathname + location.search });
}, [location]);
@echan00 why do you downvote my comment? The fact that it works doesn't mean it's being maintained. Do you know what that means?
@echan00 why do you downvote my comment? The fact that it works doesn't mean it's being maintained. Do you know what that means?
I don't mean anything personal but it seemed blanketing to use firebase (regardless of stack) seemed like a very opinionated comment.
Firebase is a Google Product. I am not promoting a third party service or wrapper.
Stumbled on this. Should be an easy drop in if using nextjs https://github.com/MauricioRobayo/nextjs-google-analytics
thank you for your work on this @codler, works great when you need a simple upgrade path, and maintain the quality of the original library https://github.com/react-ga/react-ga
Moved to https://github.com/codler/react-ga4