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

Context and period

How the analytics pages share one website and one period, why days are UTC days, how live updates reach the blocks, and how the website state is derived.

The analytics pages share one context, a website and a period. This page explains how the toolbar declares that context, how the routes read it, and how the pages stay live.

The toolbar is declared on the backend

Each analytics page declares its toolbar on the backend with static toolbar = marketingToolbar() (src/pages/blocks.ts). The toolbar is the DMS pageToolbar() with three parts:

  • the website picker (DmsMarketingWebsitePicker) as its leading website child
  • the DMS LiveToggle
  • the DMS PeriodSelector (scope marketing), whose comparisons the toolbar offers as a menu

The gate DmsMarketingContext (frontend-vue/app/components/Context.vue) wraps the blocks. The picker and the gate share one context read (useContextWebsite).

The picker shows the website's state as a dot and the age of its last event (websiteStateShort). It reads just now under JUST_NOW_MS (5 seconds), or for an event stamped ahead of the browser's clock. Its tooltip and accessible name carry the full line, with the UTC days. The toolbar places the LiveToggle and the PeriodSelector on the right.

The period is one scope for every block

The bar holds the DMS PeriodSelector, id marketing, drawn with the toolbar's defaults (PAGE_TOOLBAR_PERIOD_DEFAULTS). The presets are today and the last 7, 30 and 90 days, plus a custom range. The default is the last 30 days. The comparison is the previous period (the default), the previous year, or none, in a dropdown beside the window.

The DMS keeps the period in the page URL (?marketing.period=…&marketing.compare=…, and marketing.from and marketing.to for a custom range) and remembers the user's last choice. It publishes the period under the scope marketing, which every stock block of the pages binds to, source tables and banners included. The blocks append from and to to their fetch URL, plus compareFrom, compareTo, preset and comparison.

The routes read the comparison window that the selector sends. comparison names it for the labels (comparisonKindOf), so a previous-year comparison reads the same days a year earlier. "None" sends no window, and every change, comparison series and change column is left out.

The routes map the bounds onto the UTC days that carry the same dates, which are the days rollup rows are keyed on. They cap a window at MAX_QUERY_PERIOD_DAYS (90) and cut it at its start, so the recent days stay in (services/period.ts). Without from and to, they read the last 7 days.

A day is a day in UTC

East of UTC, between local midnight and UTC midnight, a window that ends on the local today would name a UTC day in which nothing was counted yet. The routes move such a window back to end on the current UTC day. The website state's tooltip says when the reader's days start.

The day in progress is partial. The traffic curve draws its last stretch dashed, the KPI sparklines leave it out, and every change compares it with the same elapsed share of the matching comparison day (RollupRead.compareRows). A comparison window without a rollup row counts as no comparison, so the page never shows a change against zero. A one-day window draws its curve hour by hour from the raw events (services/hourly-traffic.ts).

Live updates come from one realtime topic

The pages declare the DMS live option (CONTEXT_PAGE_LIVE). Blocks read again at most every 15 seconds, or every 60 seconds once the period spans 8 days or more, and the choice is remembered under marketing.

Ingestion publishes on one realtime topic, marketing.events (services/realtime.ts). It publishes once the day's rollup holds a batch, or failed to hold it, because the raw events are stored either way. It also publishes when a page snapshot is stored. Messages are batched to one per tenant per second on each instance, scoped to the tenant whose websites collected, with { count } as the only payload. The payload names no website and no event.

Every stock block of the pages declares that topic as its realtimeTopic (LIVE_SCOPE), and the tables add liveHold (LIVE_TABLE_HOLD, "N new events · Show"). The context bar registers the topic on its page (RegisterPageTopic), so the module's own blocks, which read through useApiData, follow it as page topics. The bar reads the websites' last events through usePageLiveRefresh on the same topic. The KpiCard blocks of the Overview take the topic like the other stock blocks.

The module keeps no clock of its own. Every read goes through the page's live gate, and the DMS polls at the maximum rate only while the realtime stream is down. While live updates are paused (the toolbar's LiveToggle, the L key, or a hidden tab), nothing reads. The toggle counts the published count values, and Resume reads every block that missed one. The DMS selector keeps a relative preset where it was and moves a day preset on at midnight. Past days are closed rollups and do not move. Only the day in progress can change.

The website comes from the URL first

The page URL names the website (?website=), so each tab keeps its own and a copied link opens on the same site. A stock block reads the website through a {{query.website}} token (websiteUrl(), src/pages/blocks.ts) and reads again when the bar switches it.

A pick in the bar is also stored on the server for each member, in marketing_preferences (PUT /api/marketing/context). That stored pick is the website of pages opened without one. It lives on the server because the blocks fetch from the API origin, which need not share cookies with the console.

A block route resolves its website in this order (services/context.ts):

  1. the website query parameter
  2. the caller's stored selection, while it still belongs to the tenant
  3. the most recently active site

The route answers 404 while the tenant has no website.

Links between the module's pages carry the website and the selector's keys. The module's own components use useContextLink(), which adds the website and then the DMS withPeriodQuery. A declared row action uses {{query.X}} tokens that the DMS fills from the page URL (CONTEXT_QUERY, src/pages/blocks.ts).

While the tenant has no website, the context container renders a first-run hero instead of its children, so no block fetches anything.

Website states

The context bar shows each website's state from the same read:

  • live once a pageview arrived
  • waiting before the first pageview
  • paused when the site's own tracking switch is off
  • imported when the latest session activity is no newer than the latest instant that the site's completed imports filled (marketing_imports.importedThrough)

An imported site holds data from ImportAnalytics, and nothing proves yet that the tag collects. The first collected hit after the import turns the site live. A live session that ended before an import's latest event does not.