0.2.2 • Published 7 months ago

@blackbox-vision/next-google-analytics v0.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Next Google Analytics npm version License: MIT

:rocket: Integrate Google Analytics in next.js with ease

Installation

NPM

npm i @blackbox-vision/next-google-analytics

YARN

yarn add @blackbox-vision/next-google-analytics

Integration Steps

  1. Generate a Google Analytics account if you don't have one.

  2. Get the Google Analytics tracking ID.

  3. Create a .env.local with following content:

NEXT_PUBLIC_GOOGLE_ANALYTICS=your_tracking_id
  1. Create a custom app and add the following contents:
import { GoogleAnalytics } from '@blackbox-vision/next-google-analytics';

function MyApp({ Component, pageProps }) {
  return (
    <>
      <GoogleAnalytics id={process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS} />
      <Component {...pageProps} />
    </>
  );
}

export default MyApp

Track events

You can track custom events with this API by doing the following:

import { googleAnalytics } from "@blackbox-vision/next-google-analytics";

googleAnalytics.event("my_event", {
  my_param: "xyz",
});

Compatibility

We're supporting next.js v11 only for now, but we've a GoogleAnalyticsLegacy component in the works and intentions to support older versions of next.

0.2.1

7 months ago

0.1.2

7 months ago

0.2.0

7 months ago

0.1.4

7 months ago

0.2.2

7 months ago

0.1.3

7 months ago

0.1.5

7 months ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago