Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-ga4-forked

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-ga4-forked

React Google Analytics 4 - forked

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
decreased by-53.66%
Maintainers
1
Weekly downloads
 
Created
Source

React Google Analytics 4 - forked

Migrate from old react-ga

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

Install

npm i react-ga4-forked

Usage

import ReactGA from "react-ga4-forked";

ReactGA.initialize("your GA measurement id");

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", 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)
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.scriptSrcstring Default https://www.googletagmanager.com/gtag/js
options.scriptLoadingMode'async'|'defer'\ Default async
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
ReactGA.send(fieldsObject)
ParameterNotes
fieldsObjectobject Required
ReactGA.gtag(...args)
ReactGA.ga(...args)

Extending

import { ReactGAImplementation } from "react-ga4-forked";

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

Package last updated on 01 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc