0.5.4 • Published 1 year ago

@lshay/next-ga v0.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@lshay/next-ga

Adds Google Analytics to your Next.js application. For it to work, you need the environment variable NEXT_PUBLIC_GOOGLE_ANALYTICS_ID to be set.

To set up, you need <GoogleAnalytics /> to be added to your document component in the Head. Then add useAppInit() in your app component. To record web vitals, you can export reportWebVitals from your app component.

Example

pages/_document.js:

import Document, { Html, Head, Main, NextScript } from 'next/document';
import { GoogleAnalytics } from '@lshay/next-ga';

class MyDocument extends Document {
  render() {
    return (
      <Html>
        <Head>
          <GoogleAnalytics />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

pages/_app.js:

import { useAppInit, reportWebVitals } from '@lshay/next-ga';

export default function MyApp() {
  GoogleAnalytics.useAppInit();
  ...
};

export reportWebVitals;
0.5.4

1 year ago

0.5.3

1 year ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago