Skip to content
Next.js HOC to integrate Google Analytics on every page change
Branch: master
Clone or download
Latest commit 32899e9 Jan 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Fix "analytics not found" error (#17) Nov 5, 2018
.babelrc
.gitignore
.npmignore Add next-ga code Jun 20, 2018
LICENSE
README.md
index.js Add next-ga code Jun 20, 2018
package.json Update babel monorepo to v7.3.1 (#29) Jan 22, 2019
renovate.json Add renovate.json (#1) Jul 11, 2018
yarn.lock Update babel monorepo to v7.3.1 (#29) Jan 22, 2019

README.md

next-ga

Next.js High Order Component to integrate Google Analytics on every page change.

Usage

Install it

yarn add next-ga

Import it inside your pages/_app.js;

import Router from "next/router";
import withGA from "next-ga";

Wrap your custom App container with it

// pass your GA code as first argument
export default withGA("UA-xxxxxxxxx-1", Router)(MyApp);

That's it, now when the user access a page it will log a pageview to Google Analytics, each page change after that will also trigger a pageview on Google Analytics.

Note: This module detects if it's running in localhost and do nothing there to avoid polluting your analytics with local data.

You can’t perform that action at this time.