react-ga4
react-ga4 copied to clipboard
[Help] ReactGA.Send command doesn't work
I have the following code in my React app:
import { useEffect} from "react";
import { useLocation } from "react-router-dom";
import ReactGA from "react-ga4";
const usePageTracking = () => {
const location = useLocation();
useEffect(() => {
ReactGA.initialize("G-XXXXXXXXX");
const path = location.pathname + location.search;
console.log(path);
ReactGA.send({ hitType: "pageview", page: path});
}, [location]);
};
export default usePageTracking;
The console.log prints correctly (/home) but nothing logs on firebase events panel, the only events I see are: first_visit and session_start.
The Live users in the last 30 minutes works fine.
Am I missing something?
Have u found any solution or other packages for this?
Try to use the param legacyDimensionMetric: false.
Got the solution from here: https://github.com/PriceRunner/react-ga4/issues/27#issue-1080536622
I got the issue fixed by adding hitType property ..