Skip to content
Last updated

Google Analytics

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

With the 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

OptionTypeDescription
includeInDevelopmentbooleanSet this option to true to enable Google Analytics in development mode and preview builds. Default: false.
trackingIdstringREQUIRED. Google Analytics tracking ID.
conversionIdstringTracking ID obtained in Google Ads.
floodlightIdstringTracking ID obtained in the Google Marketing Platform.
headbooleanPut tracking scripts in the head tag instead of body. Only allowed in root redocly.yaml.
anonymizeIpbooleanWhen 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.
optimizeIdstringGoogle Optimize container ID.
cookieExpiresnumberCookie expiration time in seconds. Only allowed in root redocly.yaml. Default: 63072000 (two years).
respectDNTbooleanWhen 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

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