Documentation
¶
Overview ¶
Package analytics injects per-tenant analytics snippets into served HTML.
Per gocodealone-multisite SPEC.md V25: when the tenant's multisite.yaml has analytics.google.measurement_id set, the host injects gtag.js into rendered pages. Without an ID set, ⊥ injection.
The actual snippet is rendered by workflow-plugin-analytics — this package only owns the per-tenant gating + HTML splice point.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectGtag ¶
func InjectGtag(html []byte, cfg TenantConfig) []byte
InjectGtag returns html with a `<script>` block inserted before the closing `</head>` tag. If no </head> is present (rare — degraded HTML) the snippet is prepended.
If cfg is disabled, returns html unchanged.
The snippet content is intentionally minimal here. Production wires this through workflow-plugin-analytics, which has a more complete gtag rendering surface; this implementation is the fallback used when that plugin is not loaded.
func RenderGtagSnippet ¶
func RenderGtagSnippet(cfg TenantConfig) []byte
RenderGtagSnippet returns the gtag.js script tag block. The measurement ID is interpolated; anonymize_ip is gated.
The measurement_id must match the GA4 pattern (G-XXXXXXXXXX). Anything else is escaped at the JS string boundary to prevent injection.
Types ¶
type TenantConfig ¶
TenantConfig is the per-tenant analytics config (from multisite.yaml).
func (TenantConfig) Enabled ¶
func (c TenantConfig) Enabled() bool
Enabled returns true iff this config opts the tenant into analytics injection.