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

is this library dead?

Open marioGMIT opened this issue 1 year ago • 13 comments

Can anyone confirm if this library is still alive? For the comments that I'm reading here make me think that this doesn't work very well?

marioGMIT avatar Aug 23 '22 13:08 marioGMIT

does not work with GA4 for me. Debug sent work with every kind of GA Account ID even fake one. And does not firing any errors.

Amethystafyy282 avatar Aug 25 '22 08:08 Amethystafyy282

Works for me!

NOTE: TURN OFF YOUR ADBLOCK WHEN TESTING

In your App.js

import ReactGA4 from 'react-ga4';

ReactGA4.initialize("G-XXXXXX");

Create a usePageTracking.js

// usePageTracking.js
import { useEffect} from "react";
import { useLocation } from "react-router-dom";

const usePageTracking = () => {
  const location = useLocation();

  useEffect(() => {
    // track pageview with gtag / react-ga / react-ga4, for example:
    window.gtag("event", "page_view", {
      page_path: location.pathname + location.search,
    });
  }, [location]);
};

export default usePageTracking;

Make sure you add this inside your Router, mine is in my Navbar component.

//Navbar.js
const Navbar = () => {
  usePageTracking();

  return (...);
};

johnnytomcat avatar Oct 08 '22 17:10 johnnytomcat

Yeah, this library is dead. We should all be moving to firebase analytics.

Well maintained and implements GA4.

wmonecke avatar Oct 20 '22 13:10 wmonecke

@wmonecke I'm not quite sure I understand: do firebase analytics work for other tech stacks? Or are you recommending anyone using ReactJS who wants GA support use Firebase?

boxabirds avatar Nov 08 '22 19:11 boxabirds

@boxabirds I say that for any tech stack

wmonecke avatar Nov 08 '22 19:11 wmonecke

Works for me!

const usePageTracking = () => { const location = useLocation();

useEffect(() => { // track pageview with gtag / react-ga / react-ga4, for example: window.gtag("event", "page_view", { page_path: location.pathname + location.search, }); }, [location]); };

Hello! do you mean the following ReactGA.gtag? (Not window.gtag)

ReactGA.gtag("event", "page_view", {
  page_path: location.pathname + location.search,
});

echan00 avatar Nov 12 '22 21:11 echan00

Actually should be this now?


  useEffect(() => {
    // track pageview with gtag / react-ga / react-ga4, for example:
    ReactGA.send({ hitType: "pageview", page: location.pathname + location.search });
  }, [location]);

echan00 avatar Nov 12 '22 21:11 echan00

@echan00 why do you downvote my comment? The fact that it works doesn't mean it's being maintained. Do you know what that means?

wmonecke avatar Nov 12 '22 23:11 wmonecke

@echan00 why do you downvote my comment? The fact that it works doesn't mean it's being maintained. Do you know what that means?

I don't mean anything personal but it seemed blanketing to use firebase (regardless of stack) seemed like a very opinionated comment.

echan00 avatar Nov 13 '22 00:11 echan00

Firebase is a Google Product. I am not promoting a third party service or wrapper.

wmonecke avatar Nov 13 '22 00:11 wmonecke

Stumbled on this. Should be an easy drop in if using nextjs https://github.com/MauricioRobayo/nextjs-google-analytics

RayHughes avatar Dec 13 '22 05:12 RayHughes

thank you for your work on this @codler, works great when you need a simple upgrade path, and maintain the quality of the original library https://github.com/react-ga/react-ga

rawpixel-vincent avatar Jan 02 '23 23:01 rawpixel-vincent

Moved to https://github.com/codler/react-ga4

codler avatar Jan 19 '23 19:01 codler