Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

react-ga4-rc

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Issues
File Explorer

Advanced tools

react-ga4-rc

React Google Analytics 4

    1.4.1latest

Version published
Maintainers
1
Weekly downloads
229
increased by397.83%

Weekly downloads

Changelog

Source

Fix #24 gtagOptions

Readme

Source

React Google Analytics 4

Migrate from old react-ga

// Simply replace `react-ga` with `react-ga4` // import ReactGA from "react-ga"; import ReactGA from "react-ga4";

Install

npm i react-ga4

Usage

import ReactGA from "react-ga4"; ReactGA.initialize("your GA measurement id"); ReactGA.send("pageview");

Example

More example can be found in test suite

// 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" }); // 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)
ParameterNotes
GA_MEASUREMENT_IDstring Required
options.noncestring Optional Used for Content Security Policy (CSP) more
options.testModeboolean Default false
options.gaOptionsobject Optional Reference
options.gtagOptionsobject Optional
options.legacyDimensionMetricboolean Default true
ReactGA.set(fieldsObject)
ParameterNotes
fieldsObjectobject Required
ReactGA.event(name, params)

This method signature are NOT for UA-XXX

ParameterNotes
namestring Required A recommended event or a custom event
paramsobject Optional
ReactGA.event(options)
ParameterNotes
optionsobject Required
options.actionstring Required
options.categorystring Required
options.labelstring Optional
options.valuenumber Optional
options.nonInteractionboolean Optional
options.transport'beacon'|'xhr'|'image' Optional
options.dimension{1...200}any Optional
options.metric{1...200}any Optional
ReactGA.send(fieldsObject)
ParameterNotes
fieldsObjectobject Required
ReactGA.gtag(...args)
ReactGA.ga(...args)
ReactGA.pageview(path, _, title)

Deprecated Use .send("pageview") instead

ReactGA.outboundLink({ label }, hitCallback)

Deprecated Use enhanced measurement feature in Google Analytics.

Extending

import { ReactGAImplementation } from "react-ga4"; class MyCustomOverriddenClass extends ReactGAImplementation {} export default new MyCustomOverriddenClass();

Debugging

Use Google Analytics Debugger Chrome Extension to see logs

Maintainer

Han Lin Yap

License

MIT

Keywords

FAQs

What is react-ga4-rc?

React Google Analytics 4

Is react-ga4-rc popular?

The npm package react-ga4-rc receives a total of 170 weekly downloads. As such, react-ga4-rc popularity was classified as not popular.

Is react-ga4-rc well maintained?

We found that react-ga4-rc demonstrated a healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 19 Jun 2022
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc