Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-gtag

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-gtag

Simple Gtag tracker for Next.js

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47
increased by113.64%
Maintainers
1
Weekly downloads
 
Created
Source

next-gtag

npm version MIT License code style: prettier

Simple Gtag tracker for Next.js.
Core source code is copied from Next.js official example.

Requirements

  • Next.js (v11.0.0 or later)

Features

  • 👋 Easy and simple to use
  • 🚀 High Performance by next/script
  • 🕳 Zero dependencies

Installation

Using npm

npm install next-gtag

or yarn

yarn add next-gtag

Usage

pages/_app.js:

import { NextGtag } from "next-gtag";

function MyApp({ Component, pageProps }) {
  return (
    <>
      <NextGtag trackingId="YOUR_TRACKING_ID" />
      <Component {...pageProps} />
    </>
  );
}

export default MyApp;

pages/_document.js:

import { Html, Head, Main, NextScript } from 'next/document'
import { gtagScript } from "next-gtag";

export default function Document() {
  return (
    <Html>
      <Head />
      <body>
      <Main />
      <NextScript />
      {gtagScript}
      </body>
    </Html>
  )
}

Then, gtag tracking will be added to your page. 🥳

Util Functions

gtagEvent

gtagEvent is a helper function to track events.
See google document for more details.

import { gtagEvent } from "next-gtag";

gtagEvent('ACTION_NAME', {
  value: 123,
  category: 'CATEGORY_NAME', // optional
  label: 'LABEL_NAME',       // optional
  nonInteraction: false      // optional
})

Contribution

Please feel free to open an issue or make a pull request.

License

Distributed under the MIT License. See LICENSE for more information.

Keywords

FAQs

Package last updated on 01 Nov 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc