React-ga Events Are Firing Off In Debug Console But Not Showing Up In Ga
I have been trying to make this work for a few days, and nothing is working. The events are simply not being captured no matter what I do. I import ReactGA at the top import ReactG
Solution 1:
Putting this into index.js fixed the problem.
(function initAnalytics() {
initGA("Tracking ID");
})();
The initGA function is manually created and is as such (this file is called index.js)
importReactGA from"react-ga";
exportconstinitGA = trackingID => {
ReactGA.initialize(trackingID);
};
exportconstPageView = () => {
ReactGA.pageview(window.location.pathname + window.location.search);
};
exportconstEvent = (category, action, label) => {
ReactGA.event({
category,
action,
label
});
};
I have also removed all the scripts that I had in public/index.html. I only have react-ga init.
It also seems you must put
ReactGA events
into a useEffect hook if youre using functional components.
Post a Comment for "React-ga Events Are Firing Off In Debug Console But Not Showing Up In Ga"