react-ga4 icon indicating copy to clipboard operation
react-ga4 copied to clipboard

[Help] ReactGA.Send command doesn't work

Open felipe-ff opened this issue 3 years ago • 3 comments

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?

felipe-ff avatar Jul 28 '22 02:07 felipe-ff

Have u found any solution or other packages for this?

Amethystafyy282 avatar Aug 25 '22 08:08 Amethystafyy282

Try to use the param legacyDimensionMetric: false. Got the solution from here: https://github.com/PriceRunner/react-ga4/issues/27#issue-1080536622

martinspenkevics avatar Sep 13 '22 15:09 martinspenkevics

I got the issue fixed by adding hitType property ..

lithika-damnod avatar May 14 '23 15:05 lithika-damnod