Installations
npm install ga-4-react
Releases
Unable to fetch releases
Developer
unrealmanu
Developer Guide
Module System
CommonJS
Min. Node Version
>=10
Typescript Support
No
Node Version
NPM Version
Statistics
122 Stars
103 Commits
19 Forks
2 Watching
2 Branches
8 Contributors
Updated on 06 Feb 2024
Languages
HTML (67.13%)
TypeScript (22.68%)
JavaScript (6.04%)
CSS (4.15%)
Total Downloads
Cumulative downloads
Total Downloads
2,332,015
Last day
-0.4%
1,204
Compared to previous day
Last week
2.4%
5,819
Compared to previous week
Last month
-3.2%
24,626
Compared to previous month
Last year
-17.2%
674,176
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
GA4React - Google Analytics 4 React
Simple wrapper of ga4 scripts for React: https://developers.google.com/analytics/devguides/collection/ga4
Google Analytics 4 React
Example without components
1 2const ga4react = new GA4React( 3'YOUR GA CODE', 4{ /* ga custom config, optional */ }, 5[ /* additional code, optional */ ], 65000 /* timeout, optional, defaults is 5000 */, 7options /* { nonce: ['first-script-is-async','second-script'] } */ 8); 9 10ga4react.initialize().then((ga4) => { 11 ga4.pageview('path') 12 ga4.gtag('event','pageview','path') // or your custom gtag event 13},(err) => { 14 console.error(err) 15}) 16
Inject GA4React function in props of childrens
Example with custom components 'GA4R'
1const Test: React.FC<any> = ({ ga4 }) => { 2 return <>{ga4 && console.log(ga4)}</>; 3}; 4 5 6<GA4R code="YOUR GA CODE"> 7 <Test></Test> 8</GA4R>
RENDER:
console.log results:
{pageview: Æ’, gtag: Æ’, event: Æ’}
Components withTracker
Pass pageview data to the path
prop:
1const Tracker = withTracker(props => <>{JSON.stringify(props)}</>); 2... 3 <Tracker path="myCustomPath" gaCode="GA-CODE"></Tracker> 4
useGA4React Hook
1const Example = () => { 2 const ga4React = useGA4React(); // GA CODE, optional, if empty try to get from globals 3 return <>{JSON.stringify(ga4React)}</>; 4}; 5
"Manual start"
1import React from "react"; 2import ReactDOM from "react-dom"; 3import GA4React, { useGA4React } from "ga-4-react"; 4 5const ga4react = new GA4React("G-1JXXXXX"); 6 7function MyApp() { 8 const ga = useGA4React(); 9 console.log(ga); 10 11 return <div className="App">hi!</div>; 12} 13 14(async () => { 15 await ga4react.initialize(); 16 17 ReactDOM.render( 18 <React.StrictMode> 19 <MyApp /> 20 </React.StrictMode>, 21 document.getElementById("root") 22 ); 23})();
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 5/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
61 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-7r28-3m3f-r2pr
- Warn: Project is vulnerable to: GHSA-r8j5-h5cx-65gg
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More