Skip to content

Add optional GA4 page-view tracking to API home page with env-based configuration - #54

Draft
varun2948 with Copilot wants to merge 2 commits into
masterfrom
copilot/add-google-analytics-tracking
Draft

Add optional GA4 page-view tracking to API home page with env-based configuration#54
varun2948 with Copilot wants to merge 2 commits into
masterfrom
copilot/add-google-analytics-tracking

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown

This issue asks for Google Analytics integration to capture page views and enable geography reporting, plus maintainers’ setup documentation. This PR adds GA4 instrumentation to the served home page and wires deployment/runtime configuration so tracking can be enabled in production without code changes.

  • Runtime integration (API home page)

    • api/app.py now reads OSMSG_GA_MEASUREMENT_ID via get_ga_measurement_id().
    • home() passes ga_measurement_id into the template context.
  • Conditional GA4 script injection

    • api/templates/home.html conditionally renders the standard gtag.js snippet only when a measurement ID is configured.
    • Default behavior remains unchanged when unset (no analytics script emitted).
  • Deployment + local config plumbing

    • Added OSMSG_GA_MEASUREMENT_ID passthrough in:
      • infra/docker-compose.yml (api service)
      • docker-compose.yml (api service)
    • Added config examples/comments in:
      • .env.example
      • infra/.env.example
  • Maintainer documentation

    • docs/infra.md now documents how to enable/disable GA4 via OSMSG_GA_MEASUREMENT_ID for deployed environments.
  • Focused API coverage

    • tests/test_api.py adds checks for:
      • env parsing/normalization (get_ga_measurement_id)
      • script presence when configured
      • script absence when unset
def get_ga_measurement_id() -> str | None:
    measurement_id = os.getenv("OSMSG_GA_MEASUREMENT_ID", "").strip()
    return measurement_id or None

# in home handler
return Template("home.html", context={"ga_measurement_id": get_ga_measurement_id()})

Copilot AI changed the title [WIP] Add Google Analytics to track global page views Add optional GA4 page-view tracking to API home page with env-based configuration Aug 1, 2026
Copilot AI requested a review from varun2948 August 1, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Google Analytics to track global page views

2 participants