1.4.0 • Published 3 years ago

usegtag v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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:

NameTypeDescription
__namedParametersobject-
__namedParameters.children?ReactNodeChildren of the component (if any). Note that this component works where-ever you put it in the node tree
__namedParameters.sendPageView?booleanWhether to send initial page view on load (default: true)
__namedParameters.trackingIdstringGoogle Analytics ID: G-XXXXXX or UA-XXXXXX
__namedParameters.transportUrl?stringURL 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:

NameTypeDescription
trackingId?stringCode 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:

NameType
trackingIdstring

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:

NameType
trackingId?string

Returns: object

NameType
builtInEvent(action: Gtag.EventNames, params?: Gtag.EventParams) => void
customEvent(action: string, params?: { key: string: string | number | boolean; }) => void
gtagGtag
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:

NameType
actionGtag.EventNames
paramsGtag.EventParams
deps?any[]

Returns: void

Defined in: index.tsx:170


useGtagCustomEvent

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

Parameters:

NameType
actionstring
paramsobject
deps?any[]

Returns: void

Defined in: index.tsx:180


usePageview

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

Parameters:

NameType
pathname?string
deps?any[]
trackingId?string

Returns: void

Defined in: index.tsx:190

1.4.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago