Skip to main content

Analytics operations

The creator-facing behavior of every number lives in internal/domain/plan (the tiers) and internal/analytics (the reads). This page is what an operator needs to run the analytics stack: where geography comes from, how visitor identity works, and what the maintenance jobs own.

GeoIP: the source of geography​

Country, region, city, and network (ASN) resolve from local MaxMind databases — GeoLite2-City for place, GeoLite2-ASN for the network. A local database is why this works identically behind Cloudflare, behind a bare Caddy origin, and on custom domains: no network hop on the redirect path, no visitor IP sent to a third party, and one answer shared by geo-routing and analytics (they cannot disagree).

Configure with:

LSGBIO_GEOIP_CITY_DB=/data/geoip/GeoLite2-City.mmdb
LSGBIO_GEOIP_ASN_DB=/data/geoip/GeoLite2-ASN.mmdb
# Optional: allow CF-IPCountry / CF-IPCity as a fallback when the resolver
# misses. Only safe behind a proxy that overwrites these headers. Default off.
LSGBIO_GEOIP_ALLOW_HEADERS=false

Deployment rules:

  • Mount, don't bake. The databases are not in the image — license terms forbid redistribution in most cases, and a database baked at build time is stale by the time it ships. Mount a volume and point the env vars at it.
  • Refresh weekly with MaxMind's geoipupdate (cron, systemd timer, or a sidecar) with the license key in a secret. Alert when the mounted file is older than 30 days: a stale database silently degrades every answer.
  • Missing files are non-fatal. The server boots, logs a loud warning, and serves redirects with unknown geography. Never fail a redirect over geo.
  • GeoLite2 requires a MaxMind account and attribution — verify the license before shipping, and document it next to the privacy policy.

Privacy line: lookups store country/region/city name and ASN only. No coordinates, no postal codes, and no raw IP is ever written to click_events, logs, or exports — the IP exists in memory for the lookup and is discarded.

Visitor identity: two first-party cookies​

Unique visitors and sessions are exact because the redirect mints two anonymous cookies for humans (never bots):

  • lsg_vid — a random UUID, 30 days. The visitor.
  • lsg_sid — a random UUID, re-set on every click; its 30-minute Max-Age IS the session boundary, so inactivity is measured without server-side state.

Both are random tokens with nothing inside — no IP, no fingerprint, no cross-site identifier — and HttpOnly, SameSite=Lax. Bots get no cookies and no identity rows. The tokens land in click_uniques per (link, day, kind, hash) and are pruned on the same schedule as raw click events (retention); the rollups survive, the per-visitor rows do not.

Pre-cookie history reads as zero visitors, and the UI labels that as coverage rather than presenting it as a collapse. If your jurisdiction requires a consent banner for functional cookies, this pair belongs in that review: first-party, anonymous, but not exempt everywhere.

Bio page analytics​

Bio pages and sub-pages have their own first-party event stream in page_events, written by the public page renderer rather than the dashboard. The collector validates the target and then hands the event to a buffered ingester; it never waits for the INSERT. One writer flushes every couple of seconds with COPY, so a burst of page views is one database round trip rather than one per visitor. The queue drops rather than blocking a public page if the database cannot keep up, and the drop counter is logged and exported through the ingester stats.

page_events is partitioned by month. The nightly retention sweep drops whole old partitions and deletes only the cutoff month's remaining rows, so pruning does not scan a growing table. Partitions are rolled forward at boot and on the maintenance ticker, with a default partition as the safety net.

  • Every published page with a PageID loads /page-analytics.js and a no-JavaScript 1x1 pixel. The script sends one view on load and one block_click when an anchor or button inside a [data-block-id] is activated. Contact-form blocks are excluded from block clicks because a submission is an outcome, not a click.
  • The collector (POST /api/analytics/page) validates that the page is published and that the block belongs to that page. It is intentionally unauthenticated, and an invalid target returns the same empty response as a successful beacon so the endpoint cannot be used to enumerate content.
  • Page views and block clicks reuse the same anonymous lsg_vid / lsg_sid cookies as redirect clicks. Bots get neither a cookie nor an identity row, and the page query filters them out while surfacing the filtered count.
  • A row snapshots the page title, path, block label, block kind, collection, and link destination at event time. Renaming or deleting a block therefore does not rewrite history, which is why the table has no foreign keys.
  • Contacts remain in contact_messages and are joined into the report by owner and window; they are not duplicated as page events.

Page reports answer views, unique visitors, sessions, block clicks, tracked link clicks, contacts, pages, a view → block → link → contact funnel, and the same breakdowns as the link board: source, country, device, browser, OS, language, UTM source/medium/campaign, destination, and collection.

Campaign analytics​

campaign_events carries public campaign activity: view, join, share, and action_start. The event ingester batches rows in the same shape as the click pipeline and upserts campaign_stats_daily in the same transaction, so a chart cannot disagree with the raw rows it came from. Days are bucketed in the campaign's own timezone, not the server's or UTC.

The Campaign Analytics tab reads the daily rollup for views/joins/entries/ shares and the raw window for dimensions the rollup does not store: country, referrer host, device, browser, OS, language, and UTM source/medium/campaign. Action conversion comes from completion counts against participants. Joins and participants are lifetime counts where the metric says so; views, joins, shares, and entries are windowed.

Ingestion writes two rollups from the same batch:

  • campaign_stats_daily buckets by the campaign's own timezone. The campaign detail tab reads this, because "today" for a Kolkata campaign should mean today there.
  • campaign_stats_daily_utc buckets the same events by UTC. The cross-surface overview reads this, because link clicks and page views are already on a UTC axis and silently shifting campaign counts across midnight makes the chart disagree with its own totals.

The duplicate write is one row per campaign/day per flush, never per event. page_events is monthly-partitioned; the retention sweep drops whole old partitions and deletes only the boundary month.

The cross-surface overview​

The default Analytics board is an aggregate, and it is deliberately not one blended "traffic" number: a page view, a link click, and a campaign view are different events. The overview shows them as separate cards and separate series, keeps the funnel in surface terms (page views → block clicks → link clicks → contacts), and offers source, country, device, browser, OS, language, and UTM breakdowns normalized across the three surfaces.

Source is a filter, never a tab strip. All sources is the default; choosing Links, Bio pages, or Campaigns narrows the same page to a detailed board for that surface. Each detailed board has the same panel mechanics as the links board: drag reorder, hide/restore, saved views, and layout that restores from a saved view. A saved view now stores its surface plus the selected page or campaign, so opening it returns to the right detail board.

Page and campaign charts share the links board's comparison and grouping controls: the previous window renders as a dashed line, and daily points can be grouped into Monday-start weeks or calendar months without another query. The workspace overview is deliberately UTC-only; campaign detail stays in the campaign's timezone. Every surface board exports a multi-section CSV of its metrics, series, content tables, breakdowns, and outcomes. Top pages, links, and campaigns drill into their owning detail board rather than dead-ending in the aggregate.

Public share links remain Links-board only. The shared renderer answers the link timeseries, link breakdowns, and top-link table; serving a Bio or Campaign view through it would show the wrong numbers under the right name, so creating a share link for a non-Links view is refused rather than misrepresented.

Maintenance jobs​

JobCadenceOwns
Partition roll-forward (EnsurePartitions)boot + monthlyclick_events partitions, so ingest never lands in the default partition
Reconciliation (Reconcile)nightlyrecomputes click_daily from raw events, repairing dropped batches
Retention (Prune)nightlydeletes click_events, click_uniques, campaign_events, and page_events past the plan's raw-retention window
Campaign rollup (UpsertCampaignStatsDaily)every ingest flushkeeps campaign_stats_daily in step with accepted campaign events; the rollup is not pruned with the raw rows

Query API behavior worth knowing​

  • Unfiltered reads answer from the click_daily rollup; filters or hour granularity read the raw partitions and are clamped to raw retention (400 days) even on the largest plan. The served window is echoed in every response and the UI states it.
  • Filters name dimensions (country, device, referrer, the UTM set, city, destination host), never columns; the whitelist lives in internal/analytics/filters.go and values are always bound parameters.
  • The board's panels share one query shape, so cross-filtering from a breakdown row narrows every panel by construction.
  • The cross-surface board (GetWorkspaceAnalytics) returns per-surface totals, a daily series, normalized breakdowns, top pages/links/campaigns, and the funnel. It never returns a single combined traffic total.
  • Saved views store a surface (all, links, pages, campaigns) plus an optional page_id or campaign_id. Older views read as links, so the migration does not change where they open.
  • Share links (/share/<token>) answer with the view's query run at the owner's tier; creating a token rotates it, deleting revokes it, and a revoked token is indistinguishable from a never-issued one.