Not receiving any data to Google Analytics, debugger extension shows no information in console
I made the following wrapper component to enable google analytics in my react app. However it doesn't appear to work at all. Google Analytics isn't detecting any page views or anything. There is nothing in the Chrome inspector logs even when I activate the Google Analytics Debugger extension. What am I doing wrong?
import { useEffect } from "react";
import ReactGA from "react-ga4";
import { useLocation } from "react-router-dom";
ReactGA.initialize("G-__MYCODEHERE___", { debug: true });
export default function GoogleAnalytics({ children }) {
const location = useLocation();
useEffect(() => {
const currentPath = location.pathname + location.search;
ReactGA.send({ hitType: "pageview", page: currentPath });
}, [location]);
return <>{children}</>;
}
I have same problem adding react-ga4 to my project. It's say sending to undefined.
Also experiencing the same issue
You need to install the Google Analytics Debugger Chrome Extension to see logs.
There is nothing in the Chrome inspector logs even when I activate the Google Analytics Debugger extension.
Experiencing same issue
experiencing the same thing even after using the now maintained version: https://github.com/codler/react-ga4/