Skip to content

Quick Start

The minimum setup is a single call. The Time on Page plugin auto-registers with sensible defaults — you don’t wire anything by hand.

analytics.ts
import { AnalyticsBrowser } from "@adpharm/silo-analytics";
// The minimum setup — one call, the Time on Page plugin auto-registers with
// sensible defaults (Silo CDN, event gateway, writeKey-namespaced storage).
export const analytics = AnalyticsBrowser.load({
writeKey: "your-write-key",
env: window.env.PUBLIC_APP_ENV, // optional — namespaces storage keys per env
});

With just writeKey (+ optional env), the library fills in:

  • cdnURLhttps://cdn.silo.adpharm.digital
  • timeOnPage.apiHosthttps://event-gateway.silo.adpharm.digital/v1/t
  • timeOnPage.writeKey → inherits from the top-level writeKey
  • Storage keys → ajs_user_id_${writeKey}_${env} and ajs_user_traits_${writeKey}_${env} (no suffix if env is omitted)

Pass anything you want to override. timeOnPage is Partial<> — only the fields you set change; the rest keep their defaults.

analytics.ts
import { AnalyticsBrowser } from "@adpharm/silo-analytics";
// Override anything you want to customize. `timeOnPage` is `Partial<>` — only
// the fields you set are overridden; apiHost + writeKey still default.
export const analytics = AnalyticsBrowser.load({
writeKey: "your-write-key",
env: "production",
cdnURL: "https://your-cdn.example.com", // override the Silo CDN default
timeOnPage: {
minSeconds: 10, // partial override; apiHost + writeKey still default
maxSeconds: 1800, // cap events at 30m instead of the 900s default
idleSeconds: 60, // pause engagement after 60s of no input (0 disables)
eventName: "Engagement", // beacon event name (default "Page Time Spent")
heartbeatSchedule: [60, 120, 240], // custom backoff (false disables)
scrollTracking: false, // opt out of scroll-depth fields
},
user: { cookie: { key: "custom_cookie_key" } }, // full override
});

See Configuration for every option, its type, and default.

In a single-page app, fire analytics.page() on every client-side route change (the standard Segment integration pattern). The plugin listens for those page events — plus browser back/forward via popstate — to roll the page_view_id and reset the engagement window per view. Without it, a whole SPA session looks like one long page-view.