0.1.0 • Published 2 years ago

next-ga4 v0.1.0

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

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

PropertyDescriptionTypeRequiredDefault
measurementIdMeasurement ID.stringYes
initialConsentParamsParameters for consent on initial execute.objectNoundefined
initialSetParamsParameters for set on initial execute.objectNoundefined
initialConfigParamsParameters for config on initial execute.objectNoundefined
isListenRouterEventsWhether to detect pushState, popState, and replaceState and send page_viewIf true, disable Page changes based on browser history events in Enhanced measurement.booleanNotrue

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