# Google Analytics

Integrate Google Analytics 4 into Redocly project using the Google tag (gtag.js).

With the [`consent`](/docs/platform/config/consent) option on, this integration loads only while the consent state allows the analytics category.
In `opt-in` mode the visitor must accept first.
In `opt-out` mode the category starts on and stays on until the visitor refuses.

## Configuration

| Option | Type | Description |
| --- | --- | --- |
| includeInDevelopment | boolean | Set this option to `true` to enable Google Analytics in development mode and preview builds. Default: `false`. |
| trackingId | string | **REQUIRED.** Google Analytics tracking ID. |
| conversionId | string | Tracking ID obtained in Google Ads. |
| floodlightId | string | Tracking ID obtained in the Google Marketing Platform. |
| head | boolean | Put tracking scripts in the head tag instead of body. Only allowed in root `redocly.yaml`. |
| anonymizeIp | boolean | When present, Google Analytics masks the sender's IP address. Only allowed in root `redocly.yaml`. |
| exclude | [string] | Do not send page view events on certain pages. |
| optimizeId | string | Google Optimize container ID. |
| cookieExpires | number | Cookie expiration time in seconds. Only allowed in root `redocly.yaml`. Default: `63072000` (two years). |
| respectDNT | boolean | When set to `true`, Google Analytics does not load for visitors who enable "Do Not Track" in their browser. Only allowed in root `redocly.yaml`. |

## Example

```yaml
analytics:
  ga:
    includeInDevelopment: true
    trackingId: GA-MY_TRACKING_ID
    exclude:
      - /private-docs/**
    conversionId: AW-MY_CONVERSION_ID
    floodlightId: DS-MY_FLOODLIGHT_ID
    optimizeId: MY_OPTIMIZE_CONTAINER_ID

    # Only configured globally in the root redocly.yaml
    head: true
    anonymizeIp: true
    respectDNT: true
    cookieExpires: 63072000
```

## Resources

- **[Analytics configuration](/docs/platform/config/analytics)** - Explore configuration for popular analytics providers
