Last updated

Google Analytics

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

Configuration

OptionTypeDescription
includeInDevelopmentbooleanSet this option to true to enable Google Analytics in development mode and preview builds. Default is 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, the IP address of the sender will be masked. 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. The default value is 63072000 (two years). Only allowed in root redocly.yaml.
respectDNTbooleanWhen set to true, Google Analytics will not be loaded at all for visitors that have "Do Not Track" enabled 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