New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@lshay/next-ga

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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.

latest
Source
npmnpm
Version
0.5.4
Version published
Maintainers
1
Created
Source

@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;

FAQs

Package last updated on 07 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts