[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationArchitecture

Architecture

How a visit moves through the Marketing module, the storage choices behind it, the anonymous identity, the phasing and the known limits.

This section explains how the module is built and why. It is for people who develop the module or integrate against its API. Feature behaviour for dashboard users is in Usage.

Follow one visit through the system

A visitor opens /pricing, then submits a signup form. The tracker sends a pageview and a signup_submitted custom event. Ingestion validates the events, assigns them to a tenant and a session, and updates the daily counters. The Overview reads those counters. A funnel reads the retained events to check their order.

That split explains a common surprise. After raw events expire, traffic totals still exist, but the old funnel journey can no longer be computed. Data flow shows which table owns what, and HTTP API lists the endpoints. Read the snapshot and assignment contracts only when you integrate those features.

Data flow

text
client site (tracked website)          DMS admin (Vue 3 / Inertia)
        │  <script tracker.js>                 │
        ▼                                      ▼
POST /api/marketing/collect  ◄──── batched events (sendBeacon)
        │
        ├─► marketing_events              raw, thin, short retention (heatmaps)
        ├─► marketing_funnel_trails       per session, its funnel events (funnels, raw retention)
        ├─► marketing_sessions            visit + acquisition context (statistics retention)
        └─► marketing_website_statistics  daily rollups, one row per website-day (dashboards)

POST /api/marketing/snapshot ◄──── one serialized page rendering per sampled visit the
        │                          backend asked for (GET snapshot.js negotiation),
        │                          or the size of one too large to upload
        └─► marketing_page_snapshots      opt-in, masked, one per (website, path, layout)

Key choices

Each choice below comes from what worked, or failed, in earlier AntelopeJS code.

Rollups at write time. The Overview never reads raw events. Heatmaps and funnel results are the deliberate exceptions. Heatmaps query the bounded raw window, and funnel results a per-session index of it, which is why marketing_events exists at all. cms-audit failed because it stored raw rows only. The daily rollup comes from the RouteStatistics of dms-api, with one change. Each website-day is its own row (_id is websiteId:day) instead of an embedded day array. The scalar counters are then native server-side increments, so concurrent batches, parallel instances included, add their deltas instead of overwriting each other (services/rollup-write.ts).

Session quality uses the same increments. A bounce counts as a transition, so the batch that brings a second pageview takes the bounce back. Duration grows by per-batch extensions. Bounce rate, average duration and pages per session all derive from scalars.

A day also carries the top-N maps, the one part that stays a read, merge and write. Their keys are dynamic and evicted at a cap, which no increment can express. Exit pages rely on that merge to move a session's single exit count from one page to the next. Past TOP_MAPS_RETENTION_DAYS (455 days, a year plus the 90 days of MAX_QUERY_PERIOD_DAYS), the hourly prune empties the maps, and only the scalars keep the full statistics retention. No dashboard loses anything it could read, because the oldest read is a 90-day window compared with the previous year. A comparison that reaches days whose maps are already empty shows no change rather than a false one. TOP_DIMENSIONS in src/types/statistics.ts declares the dimensions once, and drives the write, the trim and the read.

Every page, no per-route opt-in. The tracker captures every page. Sampling applies only to heatmap events (clicks and scroll depths), at the rate the Settings page publishes.

Thin events. Storage holds no headers, no bodies, no IP and no user agent. The tracker reports an absolute URL, and the server stores the path alone. Ingestion drops the query string after it extracts the UTM parameters onto the session. The hostname only tells an internal navigation from an acquisition referrer. A referrer that matches the website's domain, or any hostname the batch was tracked from, is dropped and never counted as a source.

Page content only as opt-in snapshots. marketing_page_snapshots is the one table that holds page content. A website must opt in. Form values and marked elements are masked before anything leaves the visitor's browser. One capture per website, path and layout is kept, under a retention of its own. The table exists because the heatmap needs a backdrop and most production sites refuse to be framed. It stays a static, masked rendering, never a recording. See Page snapshots and heatmaps and Pages and heatmaps.

Country without the IP. With geoipDatabasePath configured, the module resolves the collect request's IP to an ISO country code against a local MaxMind .mmdb file (services/geoip.ts) and stores the code on the session. The IP itself is still never stored, and no network call happens. The option is opt-in on purpose. The module ships no GeoIP data, so the operator who mounts a database (GeoLite2 under its EULA, or a commercial one) accepts its licensing terms and owns the compliance analysis. Without the option, sessions carry no country and the Overview hides the card.

Acquisition rolled up whole. All five utm_* parameters land on the session, and each rolls up as its own dimension. topCampaigns also keys full (source, medium, campaign) triples, with the resolved channel as a fourth part. A control-character separator joins them, and the statistics read splits them back, so the composite key never leaves the storage layer. The channel (direct, organic, email, referral, social or paid, MARKETING_CHANNELS in src/types/statistics.ts) is a mapping of the referrer domain, utm_medium and the ad click-id parameter. The module resolves it when the session's rollup increment fires (services/acquisition.ts) and never stores it on the session, so the classifier can change without a migration. The cost is that a change never reaches back. Sessions already rolled up keep their channel in the topChannels counters, and only later sessions use the new rules. The Email channel and the referral mediums arrived that way.

Sessions. A session groups a visitor's events until DEFAULT_SESSION_IDLE_TIMEOUT_MS (30 minutes) of inactivity. Acquisition context (referrer, UTM, device) lives on the session, so events stay thin. Only a pageview opens a session, and the session starts at that pageview's own timestamp, not at the batch's arrival. A batch without a pageview, such as a click or a scroll depth sent long after the page loaded, joins the visitor's last session even past the timeout. The gap counts as idle, not as visit time. The batch is dropped when the visitor has no session. A pageview whose campaign parameters (UTM or an ad click ID) differ from the open session's starts a new session, as in Google Analytics. Acquisition is fixed when a session starts, and joining would lose the campaign.

Anonymous identity

For each request, the server computes visitorId = sha256(monthly salt + website + IP + UA) (services/visitor-id.ts). It stores none of the raw inputs and sets no cookie. The salt rotates monthly, which changes the visitor ID and therefore the deterministic A/B assignments.

These measures reduce the personal data stored. They do not establish a legal consent exemption for your deployment. Assess the rules that apply to you, especially before you enable page snapshots or GeoIP. The module has no session replay. Page snapshots are static captures that each site enables separately.

Phasing

  1. Audience measurement. Shipped. Dashboards on rollups, and website CRUD.
  2. Funnels and retention. Funnels shipped, computed at read time. Session cohorts and daily funnel snapshots are pending.
  3. A/B tests. Shipped. Server-side deterministic assignment (experiments.js), exposure capture, and the results read per funnel step (z-test and SRM check). The split is part of the funnel itself (marketing_funnels.experiment) and is scored against the funnel's own steps, so there is one definition, one page and no goal to pick. A first version was withdrawn at cf93e20. It shipped storage and a GrowthBook definitions endpoint without CRUD, and relied on a client SDK that hashes a visitorId the client never has. The current version assigns on the server instead. See A/B assignment.
  4. Heatmaps. Shipped. Click and scroll-depth overlays over a page snapshot the tracker captures. A per-selector view is the remaining overlay.
  5. Session replay, optional. Not started. The plan is rrweb behind explicit consent, with masked inputs, short retention and sampling.

Known scaffold limits

  • Session resolution is serialized per website and visitor on each instance (services/sessionize.ts), and each instance resolves against the database row another instance wrote. Only simultaneous first hits of one visitor on two instances can still open two sessions, and the next idle timeout merges the visitor back onto one.
  • Rollup scalar counters are native increments and stay correct across instances. The top-N maps are last-write-wins between instances. The maps already accept that approximation because they evict at a cap (services/rollup-write.ts).
  • The collect path resolves websites through a cache with a TTL (WEBSITE_CACHE_TTL_MS). After a site is deleted, beacons that other instances still cache can land for up to the TTL. The deleting instance drops its own entry at once.
  • Funnel computation runs at read time over marketing_funnel_trails, one row per session holding its pageviews, custom events and exposures, which collection unions in by event id beside the raw events. A read streams the window's sessions through a cursor into counters, so it has no cap and holds one session at a time. A backfill walks the events written before the trails existed, newest first, at start and after each hourly prune (services/funnels/trail-backfill.ts). Each pass also walks a covered website again down to two hours before the start of its last complete walk, which heals a trail write that failed after its events were stored. A website created on this version starts covered. Until the backfill reaches a window's start, the read flags incomplete and verdicts are withheld. A session past MAX_TRAIL_EVENTS (derived from the largest entry's size, to fill half of MongoDB's 16 MiB document limit) keeps its earliest events by timestamp, whatever order collection and the backfill write them in. Among events that share the last timestamp kept, the first written stay: collection writes a batch in its order and the backfill in the order its walk reads, so only that tie can differ between the two. The session counts on its kept events and leaves the read complete. The hourly prune cuts the trails at the instant it cuts the raw events, so a read counts the events table's rows, past the cap aside.
  • A funnel with a started split is read over the split's runs instead of the selected period. Its results are the same whatever period the context bar shows, and a stopped split is final. The read runs one conversion window past the last stop, so late goals still count, but exposures in that window do not. One fetch spans the first start to the last stop, pauses included, because a range scan per run would cost more than the rows a pause holds. A long-running split is therefore read over its whole life, which the raw-event retention bounds.
  • Split analysis is per session and applies a Bonferroni correction when several challengers face the control. The raw-event retention bounds both sides of the ratio. The per-arm z-test and the SRM check answer null rather than a number when their approximation's validity floor is not met. A stopped split can resume and accumulates its runs. Anyone who reads a p-value before deciding can then stop the test early on noise. The Resume confirmation and the usage guide warn against that, and nothing enforces it.
  • Module pages are owner-only by DMS design. Customer-facing dashboards belong in project pages, a phase 1 decision.
  • The refused-host memory behind the install guide is per instance and in memory, for an hour and up to 5 hosts per site. Behind a load balancer, the instance that answers the poll may not be the one that refused the beacon.
  • KNOWN-ISSUES.md lists the defects found end to end and how they were closed.

Pages in this section