Skip to content

Config-driven analytics via Partytown (opt-in, zero bytes when unused) #741

Description

@jamiefolsom

Once performant-software/react-components#595 removes the always-bundled GA loader, sites that do want analytics need a supported path. Proposal:

  • New optional config key, e.g. analytics: { ga_measurement_id } (validated by the config schema).
  • When set, the base layout renders the standard gtag snippet as a script tag wrapped in Partytown (type="text/partytown", @astrojs/partytown with forward: ['dataLayer.push', 'gtag']), so the tracker runs in a web worker off the main thread instead of competing with map/search JS.
  • When unset (the default), nothing is rendered and no analytics code ships at all.

This keeps analytics opt-in per site, improves Core Web Vitals for sites that opt in, and keeps public bundles clean for everyone else. Could later admit privacy-friendly alternatives (Plausible/Matomo) under the same config key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions