0

Me need send traffic only from one page of the site. I'm using React v17 and React Router v5.

I used Universal Analytics, but it no longer supports it, and Google Analytics 4 sends traffic to all pages. I tried react-ga4 and react-gtm-hook but it doesn't work.

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Sep 16, 2023 at 16:29

1 Answer 1

1

You can check the current pathname(for example in history.listen) and only send a "pageview" event when the user is on the necessary page.

  if (window.location.pathname === '/') { // instead of '/' use necessary pathname
    GoogleAnalytics.send('pageview');
  }

or call GoogleAnalytics.send('pageview'); once in useEffect in your page component

const HomePage = () => {
  useEffect(() => {
    GoogleAnalytics.send('pageview');
  }, []);
};
1
  • Thanks for the answer, but that's not it. Universal Analytics sends data from all pages, but I need only the chosen ones. I didn't find such settings
    – Datorik
    Commented Sep 27, 2023 at 10:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.