Analytics

Add analytics to docs.json so you can see which pages readers visit on your live site.

Before you begin

  • Theme and layout already set; see Apply your branding if you have not configured docs.json yet
  • A published docs URL for verification (merge to your default branch, open a branch preview, or use a custom domain). Local docs preview does not load analytics scripts
  • For Plausible only: a vanity subdomain or custom domain mapped to your docs. Plausible requires a resolved hostname

Add analytics to docs.json

Add a top-level scripts object to docs.json. docs.page injects the matching tags on published pages only, not during local preview. For how injection works, GTM versus GA precedence, and preview suppression, see Analytics.

ProviderUse when
Google Tag ManagerYou manage tags in GTM and want one container for GA and other scripts
Google Analytics (GA4)You want a direct GA4 integration without Tag Manager
PlausibleYou use Plausible and have a custom domain or vanity subdomain on your docs

When both googleTagManager and googleAnalytics are set, docs.page loads GTM only and skips direct GA injection. Route GA through your GTM container instead. Plausible loads only when the request resolves to a configured custom domain or vanity subdomain, not on the default docs.page/{owner}/{repo} path alone.

  • Pick one provider approach

    Choose a row from the table above and gather the container ID, measurement ID, or Plausible site for that provider.

  • Declare scripts in docs.json

    Add a scripts object at the top level of docs.json. Use one of the shapes below.

    json
    {
      "scripts": {
        "googleTagManager": "GTM-XXXXXXX"
      }
    }

    Replace GTM-XXXXXXX with your container ID from Google Tag Manager.

    For field types, optional keys, and additional examples, see docs.json: scripts.

  • Publish so the live site picks up config

    Commit and push docs.json, then merge to your default branch or share a branch preview URL. See Publish.

    Analytics tags render on published pages (production, branch previews, and custom domains), not in local preview mode.

Verify

Open a live docs URL (not the local preview shell) and confirm the provider script loads.

  1. Open your published site: production URL, branch preview (https://docs.page/{owner}/{repo}~{ref}), or custom domain.
  2. Inspect the page in DevTools: open Network, reload, and filter for:
    • GTM: gtm.js from googletagmanager.com
    • GA4 (direct): gtag/js when googleAnalytics is set and googleTagManager is absent
    • Plausible: script.js from plausible.io or your self-hosted URL
  3. Confirm events in the provider dashboard: GTM Preview or Tag Assistant for Tag Manager; GA4 Realtime for direct GA; Plausible dashboard for page views on your mapped domain.

Troubleshooting

SymptomLikely causeFix
No analytics scripts in local previewExpected (preview mode suppresses scripts)Verify on a published or branch-preview URL
GA4 script missing but GTM is configuredGTM takes precedence over direct GAAdd GA as a tag inside GTM, or remove googleTagManager to use direct GA
GA shows one page title for every routePages missing frontmatter titleAdd title to each page's YAML frontmatter (body # headings do not count); see Page frontmatter
Plausible script never loadsNo custom domain or vanity subdomain on the requestUse a vanity subdomain or request a custom domain, then open the site on that hostname
Plausible loads but no page viewsdata-domain must match the hostname readers useConfirm the domain in Plausible matches your docs domain exactly
Scripts present but no dashboard dataProvider misconfiguration or ad blockersCheck container or measurement ID spelling; test in a clean browser profile
Changes not reflected after pushCached bundle or wrong branchConfirm docs.json is on the branch docs.page serves; hard-reload the live page

Related