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
;
;;
Wrap your custom App container with it
// pass your GA code as first argument"UA-xxxxxxxxx-1" RouterMyApp;
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.