init
Create the singleton Landscape client and start autocapture.
Create the client
import { init } from "@hyperreal/landscape-core";
init({ endpoint: "/api/events" });
init (packages/core/src/index.ts) creates the singleton. Module-level identify, page, track, setUserProperties, setConsent, flush, and reset call through this instance.
Returns the active LandscapeClient.
Signature
function init(config?: LandscapeConfig): LandscapeClient
config defaults to {}. Options are defined on LandscapeConfig in packages/core/src/types.ts.
Side effects
In the browser, init() starts autocapture and emits one $pageview unless autocapture.pageViews is false.
Public methods never throw into the host app. Pass onError to observe failures.
Common options
| Option | Default | Effect |
|---|---|---|
endpoint |
unset | ingest URL for HttpTransport |
transport |
from endpoint, else no-op |
custom sender; overrides endpoint |
batchSize |
10 |
flush when the in-memory buffer reaches this size |
flushIntervalMs |
5000 |
interval flush in ms |
defaultConsent |
true |
used when no consent is stored |
autocapture |
true |
false disables all; a map disables listed categories. pageViews: false skips the initial $pageview |
collectMetadata |
true |
false disables all; a map disables listed collectors |
captureElementText |
false |
include trimmed text (max 128 characters) on click events |
debug |
false |
console.debug autocapture events |
validator |
unset | schema validator for non-$ events |
plugins |
unset | registered at init |
onError |
unset | (error, source) => void |
All options
| Option | Default |
|---|---|
downloadExtensions |
pdf, zip, doc, docx, xls, xlsx, csv, dmg, exe, pkg |
redactPath |
identity (no stripping) |
country |
unset; otherwise skips timezone/locale fallback |
sessionTimeoutMs |
30 * 60 * 1000 (30 minutes) |
maxSessionMs |
24 * 60 * 60 * 1000 (24 hours) |
maxQueueSize |
200 |
maxEventAgeMs |
7 * 24 * 60 * 60 * 1000 (7 days) |
retryBaseMs |
1000 |
retryMaxMs |
60000 |
pluginCircuitBreakerThreshold |
3 |
storage |
createConfigStorage() (localStorage, then sessionStorage, then memory) |
eventStore |
IndexedDB (landscape / events) with memory fallback |
enrichers |
[] |
Metadata collectors
Default collectMetadata: true attaches:
| Collector | Fields | Source |
|---|---|---|
userAgent |
$userAgent |
navigator.userAgent |
browser |
$browser |
brave, edge, opera, chrome, firefox, safari, or unknown |
deviceCategory |
$deviceCategory |
mobile, tablet, or desktop |
viewport |
$viewportWidth, $viewportHeight |
window.innerWidth / innerHeight |
screen |
$screenWidth, $screenHeight |
screen.width / screen.height |
language |
$language |
navigator.language |
timezone |
$timezone |
IANA name from Intl |
country |
$country, $countrySource |
ISO 3166-1 alpha-2; source cdn, timezone, or locale. Omitted when unresolved. |
path |
$path |
location.pathname |
referrer |
$referrer |
document.referrer when present |
utm |
$utm_source, $utm_medium, $utm_campaign, $utm_term, $utm_content |
query string; omitted when absent |
init({
endpoint: "/api/events",
collectMetadata: { userAgent: false },
});
Path redaction:
import { combineRedactors, redactNumericSegments, redactUuidSegments } from "@hyperreal/landscape-core/redact";
init({
endpoint: "/api/events",
redactPath: combineRedactors(redactNumericSegments, redactUuidSegments),
});
Numeric path segments and UUIDs become /:id. Applies to $path and click href pathnames.
Multiple clients
Construct LandscapeClient directly when you need more than the singleton. getClient() returns the singleton or null before init.
Autocapture: Autocapture. Ingest route: Ingesting Events.