Nexus (entry point)
Nexus (entry point) in the JavaScript SDK.
// access
Nexus.init({ apiKey })| Symbol | Kind | Summary |
|---|---|---|
Nexus | class | The Nexus umbrella SDK — one entry point for every service, correlated to a single journey session. |
NexusConfig | interface | Configuration for {@link Nexus.init }. |
Nexus
classThe Nexus umbrella SDK — one entry point for every service, correlated to a single journey session. Isomorphic: works in every browser framework and in Node/Express.
import { Nexus } from '@inverge/nexus';
const nexus = Nexus.init({ apiKey: 'nxs_...' });
nexus.events.track('order_placed', { total: 42 });init()
static methodstatic init(config: NexusConfig, opts?: { force?: boolean }): NexusInitialise the SDK. Idempotent: if an instance already exists it is
returned as-is — a repeated call (an SSR module re-eval, an HMR reload, a
second import) will NOT tear down and reconnect the live realtime socket.
Pass { force: true } to deliberately dispose the current instance and
start a fresh one (e.g. to switch API keys).
Parameters
Prop
Type
Returns Nexus
config
propertyreadonly config: ResolvedConfigsessions
propertyreadonly sessions: NexusSessionsevents
propertyreadonly events: NexusEventslogs
propertyreadonly logs: NexusLogserrors
propertyreadonly errors: NexusErrorsflags
propertyreadonly flags: NexusFlagslinks
propertyreadonly links: NexusLinksrealtime
propertyreadonly realtime: NexusRealtimeremoteConfig
propertyreadonly remoteConfig: NexusRemoteConfigsurveys
propertyreadonly surveys: NexusSurveysreplay
propertyreadonly replay: NexusReplaypush
propertyreadonly push: NexusPushinApp
propertyreadonly inApp: NexusInAppliveActivities
propertyreadonly liveActivities: NexusLiveActivitiesinstance
propertystatic readonly instance: NexusThe app-wide instance. Throws if {@link init} hasn't run.
isInitialized
propertystatic readonly isInitialized: booleandistinctId
propertyreadonly distinctId: string | nullsessionKey
propertyreadonly sessionKey: stringenabled()
methodenabled(service: NexusService): booleanWhether a product is switched on — config services / NEXUS_<SERVICE>_ENABLED.
Parameters
Prop
Type
Returns boolean
identify()
methodidentify(distinctId: string, options?: IdentifyOptions): Promise<void>Identify the current end-user (shorthand for sessions.identify).
Parameters
Prop
Type
reset()
methodreset(): voidForget the current user and start a fresh session (e.g. on logout).
View sourceflush()
methodasync flush(): Promise<void>Flush all batched telemetry now.
View sourcedispose()
methoddispose(): voidNexusConfig
interfaceConfiguration for {@link Nexus.init }.
apiKey
propertyapiKey: stringTenant API key (nxs_...). Sent as x-api-key, and in the socket handshake.
baseUrl
propertybaseUrl?: stringAPI origin. Partner endpoints live under /partner. Default https://services.inverge.net.
realtimeUrl
propertyrealtimeUrl?: stringRealtime (Socket.IO) origin. Defaults to {@link baseUrl}.
autoTrackSessions
propertyautoTrackSessions?: booleanStart/refresh a journey session automatically. Default true.
autoCaptureErrors
propertyautoCaptureErrors?: booleanCapture uncaught errors automatically (browser window/unhandledrejection, Node process). Default true.
flushOnHide
propertyflushOnHide?: booleanFlush queued telemetry on page hide / process exit. Default true.
flushIntervalMs
propertyflushIntervalMs?: numberBatch flush cadence (ms) for events/logs. Default 10000.
maxBatch
propertymaxBatch?: numberMax items per flush. Default 50.
logLevel
propertylogLevel?: 'silent' | 'error' | 'warn' | 'info' | 'debug'Diagnostic verbosity. Default warn.
appVersion
propertyappVersion?: stringApp/service version reported with telemetry.
defaultProperties
propertydefaultProperties?: Record<string, unknown>Properties merged into every event/person context.
remoteConfigEnabled
propertyremoteConfigEnabled?: booleanFetch Remote Config at init (and on foreground). Default false.
remoteConfigRealtime
propertyremoteConfigRealtime?: booleanRe-fetch Remote Config live on publish (needs a realtime connection). Default false.
remoteConfigDefaults
propertyremoteConfigDefaults?: Record<string, unknown>In-app default Remote Config values.
replayEnabled
propertyreplayEnabled?: booleanRecord browser session replay (rrweb). Requires the rrweb peer dependency.
Browser-only; no-op on the server. Default false.
replayMaskAllInputs
propertyreplayMaskAllInputs?: booleanRedact every input value from replay. Default true.
replayBlockClass
propertyreplayBlockClass?: stringCSS class on elements to fully block (never captured) in replay. Default nexus-block.
replayMaskTextClass
propertyreplayMaskTextClass?: stringCSS class on elements whose text is masked in replay. Default nexus-mask.
replayFlushIntervalMs
propertyreplayFlushIntervalMs?: numberHow often (ms) buffered replay events are shipped. Default 5000.
fetch
propertyfetch?: typeof globalThis.fetchCustom fetch implementation (defaults to global fetch).
services
propertyservices?: Partial<Record<NexusService, boolean>>Switch products off without removing their code, e.g. { liveActivities: false }.
On Node the NEXUS_<SERVICE>_ENABLED environment variables apply too — off wins.
A switched-off service makes no request and never throws.
enabled
propertyenabled?: booleanfalse switches every service off (also NEXUS_ENABLED=false). Default true.
