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

Extending

Read heatmaps and ship websites, funnels and history from another module, report events and variations from page code, and call the Marketing HTTP API.

Other code reaches the Marketing module in three ways. Backend modules call the @antelopejs/interface-dms-marketing interface. Code on a tracked site calls the tracker's JavaScript API. Anything else calls the HTTP API.

Read heatmaps from a backend module

Every /modules/ page of the DMS is reserved to the platform owner. To show Marketing data to tenant users, build your own page and read the data through the interface. Declare the interface in optionalDependencies. A call made before a module implements the interface waits for one. Past 1,000 waiting calls, a new call rejects with ProviderQueueFullError, and a storage failure rejects too. The example catches the rejection and shows the page without analytics.

Terminal bash
pnpm add --save-optional @antelopejs/interface-dms-marketing
src/heatmap.ts typescript
import { GetClickHeatmap } from "@antelopejs/interface-dms-marketing";

export async function pricingHeatmap(tenantId: string) {
  try {
    return await GetClickHeatmap({
      tenantId, // an authenticated and authorized tenant id only
      path: "/pricing",
      from: "2026-09-01T00:00:00.000Z",
      to: "2026-09-30T23:59:59.999Z",
    });
  } catch {
    return null; // The page can work without analytics.
  }
}

The query also takes an optional websiteId. Without both from and to, it reads the last 7 days. The consumer reference defines the query, the result types, the date limits, element anchors and tenant boundaries. Resolve an element anchor against the rendered page when you can. Show an unavailable state apart from a successful heatmap with no clicks.

Tip

Keep the page itself backend-declared: compose it from DMS blocks, and make only the heatmap overlay a custom block with .meta({ name, description, icon }).

Ship websites, funnels and history as code

A project can ship its websites, funnels and page snapshots as code through the same interface. A demo or a migration can ship its history the same way. Never write the module's tables directly.

Write the content from a Hook.TENANT_BEING_PROVISIONED handler. The DMS fires it once per tenant, when the tenant is created. For the default tenant, that is on the start that creates it, after every DATABASE_INITIALIZED handler has finished. A SaaS module fires it for each workspace it creates. All four content calls require a nonempty tenantId without surrounding whitespace, in TypeScript and at runtime. There is no fallback tenant.

src/index.ts typescript
import { Hook, RegisterHook } from "@antelopejs/interface-dms/hooks";
import {
  EnsureFunnel,
  EnsureWebsite,
  ImportAnalytics,
} from "@antelopejs/interface-dms-marketing";

async function writeShopContent(tenantId: string) {
  await EnsureWebsite({ tenantId, id: "shop-site", name: "Shop", domain: "shop.example.com" });
  await EnsureFunnel({
    tenantId,
    id: "shop-quote-request",
    websiteId: "shop-site",
    name: "Quote request",
    steps: [
      { kind: "url", value: "/pricing" },
      { kind: "custom", value: "quote_submitted" },
    ],
  });
  await ImportAnalytics({
    tenantId,
    importId: "shop-history",
    websiteId: "shop-site",
    sessions: [
      {
        visitor: "visitor-1",
        events: [
          { kind: "pageview", at: "2026-10-01T09:00:00Z", url: "https://shop.example.com/pricing" },
          { kind: "custom", at: "2026-10-01T09:02:00Z", url: "https://shop.example.com/pricing", name: "quote_submitted" },
        ],
      },
    ],
  });
}

export function construct() {
  RegisterHook(Hook.TENANT_BEING_PROVISIONED, async ({ tenantId }) => {
    await writeShopContent(tenantId);
  });
}
  • EnsureWebsite and EnsureFunnel are keyed by the ID you choose and write once. They answer created, then kept for an ID that already exists, whether declared or made in the dashboard. Nothing refreshes the content later, because it belongs to the tenant.
  • EnsurePageSnapshot({ tenantId, websiteId, url, html, viewport, document }) declares the backdrop of a page's heatmap when the tracker cannot capture it, for example for a page that is not online or for imported history. It is keyed by the page path and the layout of viewport, and it needs a website with snapshotsEnabled. It is sanitized like a capture. A <style> that holds a < before a letter, !, / or ? is dropped, so write that character as a CSS escape, "<\6c ength>" for "<length>". A capture of the live page replaces the declared snapshot. If a snapshot is already stored for that page and layout, the call answers kept.
  • ImportAnalytics replays history through the live collection pipeline with its own timestamps. It runs once per importId and website, and the first call answers imported. Later calls with that ID write nothing. They answer in_progress while the first call is replaying, then skipped. A call that finds the replay stopped, because it failed or its process died, resumes it, and each UTC day of it counts once. Split larger histories into chronological windows that cover the entire website. Concurrent imports with different IDs for the same website reject, and an unfinished import blocks later windows until a call with its ID completes it. The reference has the failure and rollout contract.
  • Call them from the provisioning hook, not from start() or DATABASE_INITIALIZED. Those run on every boot, and the calls do not wait for the database to be ready.

The consumer reference has the contracts, the exact declaration rule and the import's limits.

Report events and variations from a tracked site

The tracker installs window.dmsMarketing on the tracked site. Guard every call with ?., because the object is absent when the script is blocked or fails to load.

app.js javascript
window.dmsMarketing?.track("signup_submitted", { plan: "pro" });

window.dmsMarketing?.variation("hero-cta").then((arm) => {
  if (arm === "bold-cta") showAlternateHero();
});
  • track(name, data?) reports a custom event, with a name of up to 50 characters and optional data of up to 4,096 characters of serialized JSON. Custom events feed the Overview and can be funnel steps.
  • variation(key) resolves to the arm that the backend assigned this visitor, and reports the exposure. null means that you render the control.
  • exposure(experiment, variation) reports an exposure for integrations that assign arms on their own.

Mark elements that page snapshots must never capture with data-dms-marketing-mask (text masked) or data-dms-marketing-block (replaced by an empty box). See Tracker & custom events.

Call the HTTP API

All routes live under /api/marketing. The public routes serve tracked sites. The other routes need a DMS JWT.

RouteAuthPurpose
POST /collectpublicEvent ingestion
GET /tracker.jspublicThe tracker script
GET /experiments.js?website=publicPer-visitor A/B assignments, as a script
GET /websitestenant memberList websites
POST /websites, PUT /websites/:id, DELETE /websites/:idtenant ownerCreate, update and delete websites
GET /stats/overview, /stats/pages, /stats/heatmaptenant memberDashboard, page inventory and heatmap reads
GET /funnels/:id/resultstenant memberFunnel and A/B computation
GET /settings, PUT /settingsplatform ownerRuntime settings

The complete route table and the event contract are in HTTP API. The snapshot and assignment contracts are in Page snapshots and heatmaps and A/B assignment.