next-simple-google-analytics
Add Google Analytics to your Next.js site in a jiffy
Table of Contents
About
This module is heavily based on the official example.
Usage
Add the default export to the Head
of _document.js
:
static async { const initialProps = await Document return ...initialProps } { return <Html lang='en'> <Head> <GoogleAnalytics id="UA-X00XXX0X-X"/> </Head> <body> <Main /> <NextScript /> </body> </Html> }
GoogleAnalytics GoogleAnaltyicsevent'didthing' category label value
Route changes are required using routeChangeComplete
.
Install
This project uses node and npm.
$ npm install next-simple-google-analytics$ # OR $ yarn add next-simple-google-analytics
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT © Tiaan du Plessis