> For the complete documentation index, see [llms.txt](https://nghiaxchis.gitbook.io/ncmaz-nextjs-headless-cms-wordpres-blog-magazine/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nghiaxchis.gitbook.io/ncmaz-nextjs-headless-cms-wordpres-blog-magazine/ncmaz-faust/nextjs-google-analytics.md).

# Nextjs-google-analytics

From version 2.3.0, Ncmaz has built-in script **Nextjs-google-analytics**, so please update the theme to the latest version, along with adding this environment variable to your project - **`NEXT_PUBLIC_GA_MEASUREMENT_ID`**

### Usage:

Your *Google Analytics measurement id* is read from `NEXT_PUBLIC_GA_MEASUREMENT_ID` environment variable, so make sure it is set in your production environment:

* [Vercel](https://vercel.com/docs/environment-variables)
* [Netlify](https://www.netlify.com/blog/2020/12/10/environment-variables-in-next.js-and-netlify/)

If the variable is not set or is empty, nothing will be loaded, making it safe to work in development.

To load it and test it on development, add:

```shell
NEXT_PUBLIC_GA_MEASUREMENT_ID="G-XXXXXXXXXX"
```

to your `.env.local` file.

### How to get a tracking ID - *Google Analytics measurement id*?

1. Visit [Google Analytics](https://analytics.google.com/).&#x20;
2. Sign in with your Google account.&#x20;
3. Create a new property for your website and get a tracking ID of the form **G-XXXXXXXXXX**.
