2020-11-30 08:07:08 -05:00
---
2021-11-10 01:08:50 -05:00
sidebar_position: 6
2020-11-30 08:07:08 -05:00
id: plugin-google-analytics
title: '📦 plugin-google-analytics'
slug: '/api/plugins/@docusaurus/plugin-google-analytics'
---
2021-12-28 08:23:27 -05:00
import APITable from '@site/src/components/APITable';
2021-06-09 13:59:39 -04:00
The default [Google Analytics ](https://developers.google.com/analytics/devguides/collection/analyticsjs/ ) plugin. It is a JavaScript library for measuring how users interact with your website **in the production build** . If you are using Google Analytics 4 you might need to consider using [plugin-google-gtag ](./plugin-google-gtag.md ) instead.
2020-11-30 08:07:08 -05:00
2021-12-28 08:23:27 -05:00
:::caution production only
This plugin is always inactive in development and **only active in production** to avoid polluting the analytics statistics.
:::
2021-03-19 06:00:41 -04:00
## Installation {#installation}
2020-11-30 08:07:08 -05:00
```bash npm2yarn
npm install --save @docusaurus/plugin -google-analytics
```
:::tip
2021-12-28 08:23:27 -05:00
If you use the preset `@docusaurus/preset-classic` , you don't need to install this plugin as a dependency.
You can configure this plugin through the preset options.
2020-11-30 08:07:08 -05:00
:::
2021-03-19 06:00:41 -04:00
## Configuration {#configuration}
2020-11-30 08:07:08 -05:00
2021-11-10 06:04:43 -05:00
Accepted fields:
2021-12-28 08:23:27 -05:00
< APITable >
2021-11-10 06:04:43 -05:00
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `trackingID` | `string` | **Required** | The tracking ID of your analytics service. |
| `anonymizeIP` | `boolean` | `false` | Whether the IP should be anonymized when sending requests. |
2021-12-28 08:23:27 -05:00
< / APITable >
2021-11-10 06:04:43 -05:00
2021-12-28 08:23:27 -05:00
### Example configuration {#ex-config}
2021-11-10 06:04:43 -05:00
2021-12-28 08:23:27 -05:00
You can configure this plugin through preset options or plugin options.
2021-11-10 06:04:43 -05:00
:::tip
2021-12-28 08:23:27 -05:00
Most Docusaurus users configure this plugin through the preset options.
2021-11-10 06:04:43 -05:00
:::
2021-12-28 08:23:27 -05:00
```js config-tabs
2022-01-06 06:31:58 -05:00
// Preset Options: googleAnalytics
// Plugin Options: @docusaurus/plugin -google-analytics
2021-12-28 08:23:27 -05:00
2021-11-10 06:04:43 -05:00
const config = {
trackingID: 'UA-141789564-1',
anonymizeIP: true,
};
```