analytics

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

type TenantConfig struct {
	GoogleMeasurementID string
	AnonymizeIP         bool
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL