next-ga4
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

next-ga4

Google Analytics 4 for Next.js

Install

npm install next-ga4

or

yarn add next-ga4

Usage

Add <NextGA /> to _app.tsx.

import type { AppProps } from 'next/app'
import { NextGA } from 'next-ga4'

const App = ({ Component, pageProps }: AppProps) => {
  return (
    <>
      <NextGA measurementId="G-XXXXXXXXXX" />

      <Component {...pageProps} />
    </>
  )
}

export default App

Options

Property Description Type Required Default
measurementId Measurement ID. string Yes
initialConsentParams Parameters for consent on initial execute. object No undefined
initialSetParams Parameters for set on initial execute. object No undefined
initialConfigParams Parameters for config on initial execute. object No undefined
isListenRouterEvents Whether to detect pushState, popState, and replaceState and send page_view

If true, disable Page changes based on browser history events in Enhanced measurement.
boolean No true

Hints

How do i debug?

  1. Add Google Analytics Debugger to Google Chrome and enable it
  2. Click Configure -> DebugView in the left navigation
  3. Reload the website you want to debug

More details: [GA4] Monitor events in debug mode

References

Author

@p-chan

License

MIT

Package Sidebar

Install

npm i next-ga4

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

17.4 kB

Total Files

8

Last publish

Collaborators

  • p-chan