bradgarropy / next-google-analytics

πŸ“Š google analytics for next.js

Home Page:https://npmjs.com/package/@bradgarropy/next-google-analytics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ“Š next google analytics

version downloads size github actions coverage typescript contributing contributors discord

Google Analytics 4 for Next.js.

πŸ“¦ Installation

This package is hosted on npm.

npm install @bradgarropy/next-google-analytics

πŸ₯‘ Usage

This component integrates Google Analytics 4 into your Next.js website. It downloads and initializes the gtag script, and no further setup is required. In order to work, this component must be placed in the pages/_app.js file.

// pages/_app.js
import GoogleAnalytics from "@bradgarropy/next-google-analytics"

const App = ({Component, pageProps}) => {
    return (
        <>
            <GoogleAnalytics measurementId="G-XXXXXXXXXX" />
            <Component {...pageProps} />
        </>
    )
}

To ensure that Google Analytics is working, you can check a few things.

  1. A network request was made to https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX.
  2. window.dataLayer exists and includes your Measurement ID.
  3. When you navigate your site, items are added to the window.dataLayer array.

πŸ“– API Reference

<GoogleAnalytics>

Name Required Default Example Description
measurementId true "G-XXXXXXXXXX" Google Analytics Measurement ID.

The example below shows how to use the component.

<GoogleAnalytics measurementId="G-XXXXXXXXXX" />

❔ Questions

πŸ› report bugs by filing issues
πŸ“’ provide feedback with issues or on twitter
πŸ™‹πŸΌβ€β™‚οΈ use my ama or twitter to ask any other questions

✨ contributors


Brad Garropy

πŸ’» πŸ“– ⚠️ πŸš‡

About

πŸ“Š google analytics for next.js

https://npmjs.com/package/@bradgarropy/next-google-analytics

License:MIT License


Languages

Language:TypeScript 76.2%Language:CSS 15.1%Language:JavaScript 8.8%