npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-ga-neo

v2.2.0

Published

Google Analytics 4 in React

Downloads

500

Readme

React GA Neo GitHub Actions npm version

A fork of react-ga4 with a few more features sprinkled on top.

Install

This package is available at npm as react-ga-neo.

npm install react-ga-neo

Usage

import ReactGA from "react-ga-neo";

ReactGA.initialize("G-XXXXXXXXXX"); // Your GA4 measurement id

Migrating from old react-ga

Simply replace react-ga with react-ga-neo and remove ReactGA.pageview() calls.

// import ReactGA from "react-ga";
import ReactGA from "react-ga-neo";

A few old methods may not be available. You may use ReactGA.gtag() or React.ga() as last resort to call gtag/ga directly. Alternatively, you can extend the library. Pull requests with improvements are welcome! :)

Example

Check out the tests for more examples.

// Multiple products (previously known as trackers)
ReactGA.initialize([
  {
    trackingId: "your GA measurement id",
    gaOptions: {...}, // optional
    gtagOptions: {...}, // optional
  },
  {
    trackingId: "your second GA measurement id",
  },
]);

// Send pageview with a custom path
ReactGA.send({ hitType: "pageview", page: "/my-path", title: "Custom Title" });

// Send a custom event
ReactGA.event({
  category: "your category",
  action: "your action",
  label: "your label", // optional
  value: 99, // optional, must be a number
  nonInteraction: true, // optional, true/false
  transport: "xhr", // optional, beacon/xhr/image
});

Reference

ReactGA.initialize(GA_MEASUREMENT_ID, [options])

| Parameter | Notes | | ------------------- | ----------------------------------------------------------------------------------------------------------------------- | | GA_MEASUREMENT_ID | string Required | | options.nonce | string Optional Used for Content Security Policy (CSP) more | | options.testMode | boolean Default false | | options.titleCase | boolean Default true | | options.gtagUrl | string Default https://www.googletagmanager.com/gtag/js | | options.gaOptions | object Optional Reference | | options.gtagOptions | object Optional |

ReactGA.set(fieldsObject)

| Parameter | Notes | | ------------ | ----------------- | | fieldsObject | object Required |

ReactGA.event(name, params)

This method signature is NOT for UA-XXX

| Parameter | Notes | | --------- | ----------------------------------------------------------------------------------------------------------------------------- | | name | string Required A recommended event or a custom event | | params | object Optional |

ReactGA.event(options)

| Parameter | Notes | | ---------------------- | ----------------------------------- | | options | object Required | | options.action | string Required | | options.category | string Required | | options.label | string Optional | | options.value | number Optional | | options.nonInteraction | boolean Optional | | options.transport | 'beacon'\|'xhr'\|'image' Optional |

ReactGA.send(fieldsObject)

| Parameter | Notes | | ------------ | ----------------- | | fieldsObject | object Required |

ReactGA.exception([details])

| Parameter | Notes | | ------------------- | ----------------- | | details.description | string | | details.fatal | string |

ReactGA.timing(timingObject)

| Parameter | Notes | | --------------------- | ----------------- | | timingObject.category | string Required | | timingObject.variable | string Required | | timingObject.value | number Required | | timingObject.label | string Optional |

ReactGA.gtag(...args)

Used to call gtag() directly (see official documentation for details).

ReactGA.ga(...args)

DEPRECATED.

Extending

import { ReactGAImplementation } from "react-ga-neo";

class MyCustomOverriddenClass extends ReactGAImplementation {}

export default new MyCustomOverriddenClass();

License

MIT