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 🙏

© 2026 – Pkg Stats / Ryan Hefner

usegtag

v1.4.0

Published

<a name="readmemd"></a>

Downloads

58

Readme

useGtag

Connect your React app to Google Analytics 4 and/or Universal Analytics with a simple hook

usegtag - v1.4.0

usegtag - v1.4.0

Table of contents

References

Functions

References

default

Renames and exports: useGtag

Functions

Gtag

Gtag(__namedParameters: { children?: ReactNode ; sendPageView?: boolean ; trackingId: string ; transportUrl?: string }): Element

React component for setting the tracking ID and triggering the GA (gtag.js) initialization. Can be anywhere in the tree

Parameters:

Name | Type | Description | :------ | :------ | :------ | __namedParameters | object | - | __namedParameters.children? | ReactNode | Children of the component (if any). Note that this component works where-ever you put it in the node tree | __namedParameters.sendPageView? | boolean | Whether to send initial page view on load (default: true) | __namedParameters.trackingId | string | Google Analytics ID: G-XXXXXX or UA-XXXXXX | __namedParameters.transportUrl? | string | URL to send events to, if you are running a custom server setup. (Defaults to the googla analytics server) |

Returns: Element

React <Gtag /> component

Defined in: index.tsx:16


install

install(trackingId?: string, params?: { send_page_view?: boolean ; transport_url?: string } & Gtag.CustomParams): void

Install the GA tracking code (gtag.js) on your page. (Imperative alternative to using the GA4 component)

Parameters:

Name | Type | Description | :------ | :------ | :------ | trackingId? | string | Code for identifying the data stream/property in Google Analytics (G-XXXXXX or UA-XXXXXXX) | params | { send_page_view?: boolean ; transport_url?: string } & Gtag.CustomParams | - |

Returns: void

Defined in: index.tsx:45


setTrackingId

setTrackingId(trackingId: string): void

Initialize the tracking code for later use by install or useGtag. Facilitates easy initializastion and lazy loading

Parameters:

Name | Type | :------ | :------ | trackingId | string |

Returns: void

Defined in: index.tsx:97


useGtag

useGtag(trackingId?: string): object

Fetch the gtag function, and install it if not already set up.

Parameters:

Name | Type | :------ | :------ | trackingId? | string |

Returns: object

Name | Type | :------ | :------ | builtInEvent | (action: Gtag.EventNames, params?: Gtag.EventParams) => void | customEvent | (action: string, params?: { [key: string]: string | number | boolean; }) => void | gtag | Gtag | pageview | (path?: string | Location, location?: string | Location, title?: string) => any |

New gtag function, runs when gtag is loaded if not ready, will die silently if in error situation

Defined in: index.tsx:105


useGtagBuiltInEvent

useGtagBuiltInEvent(action: Gtag.EventNames, params: Gtag.EventParams, deps?: any[]): void

Parameters:

Name | Type | :------ | :------ | action | Gtag.EventNames | params | Gtag.EventParams | deps? | any[] |

Returns: void

Defined in: index.tsx:170


useGtagCustomEvent

useGtagCustomEvent(action: string, params: { [key: string]: string | boolean | number; }, deps?: any[]): void

Parameters:

Name | Type | :------ | :------ | action | string | params | object | deps? | any[] |

Returns: void

Defined in: index.tsx:180


usePageview

usePageview(pathname?: string, deps?: any[], trackingId?: string): void

Parameters:

Name | Type | :------ | :------ | pathname? | string | deps? | any[] | trackingId? | string |

Returns: void

Defined in: index.tsx:190