was tring to update GA to GA4 for my React project, I am using this package, which gives me some errors as you can see from the title.
//import ReactGA from 'react-ga';
import ReactGA from "react-ga4";
function init() {
// Enable debug mode on the local development environment
const isDev = false; // !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
// ReactGA.initialize(process.env.GOOGLE_ANALYTICS_TRACKING_ID, { debug: isDev });
ReactGA.initialize(process.env.GOOGLE_ANALYTICS_TRACKING_ID, { debug: isDev });
}
function sendEvent(payload) {
ReactGA.event(payload);
}
function sendPageview(path) {
ReactGA.set({ page: path });
ReactGA.pageview(path);
}
export default {
init,
sendEvent,
sendPageview,
};

had npm installed the package. checked the syntax
According to react-ga4 you have to remove ReactGA.pageview() , because it's Deprecated You should Use .send("pageview") instead .
To Send pageview with a custom path :
ReactGA.send({ hitType: "pageview", page: "/my-path" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With