InvergeDocs
JavaScript

JavaScript SDK

@inverge/nexus — one isomorphic package for the browser (React, Vue, Angular, Svelte…) and Node (Express, Fastify, Nest, serverless), plus Telescope for Node.

The same package runs in the browser and on the server. It ships ESM + CommonJS + TypeScript types and has no required runtime dependencies.

  • npm @inverge/nexus 1.4 · Node 18+ (global fetch) · modern browsers · source
  • Entry points: @inverge/nexus, @inverge/nexus/react, @inverge/nexus/telescope (Node only)
  • API reference

Install

npm install @inverge/nexus
npm install socket.io-client   # only for nexus.realtime
npm install rrweb              # only for browser session replay

Initialise

import { Nexus } from '@inverge/nexus';

const nexus = Nexus.init({
  apiKey: 'nxs_live_xxx',
  appVersion: '2.1.0',
  remoteConfigEnabled: true,
});

await nexus.identify('user_123', { email: 'ada@example.com' });
nexus.events.track('page_view', { path: '/pricing' });

Nexus.instance;   // the same client, anywhere

Services: sessions · events · logs · errors · flags · remoteConfig · links · realtime · surveys · replay · push · inApp · liveActivities.

Configuration

OptionDefault
apiKey—
appVersion, defaultProperties— / {}
autoTrackSessionstrue
autoCaptureErrorstrueBrowser error / unhandledrejection; Node uncaughtException / unhandledRejection
flushOnHidetruePage hide / process exit
flushIntervalMs, maxBatch10000, 50
logLevelwarnsilent · error · warn · info · debug
remoteConfigEnabled, remoteConfigRealtime, remoteConfigDefaultsfalse, false, {}
replayEnabled, replayMaskAllInputs, replayBlockClass, replayMaskTextClassfalse, true, nexus-block, nexus-maskBrowser only
services, enabledall onSwitching services off
fetchglobal fetchCustom fetch

Frameworks

import { NexusProvider, useNexus, useFlag, useRemoteConfig, useTrackEvent } from '@inverge/nexus/react';

export function Root() {
  return (
    <NexusProvider config={{ apiKey: 'nxs_live_xxx', remoteConfigEnabled: true }}>
      <App />
    </NexusProvider>
  );
}

function App() {
  const rc = useRemoteConfig();            // re-renders when config changes
  const promo = useFlag('promo_banner');
  const track = useTrackEvent();
  return <button onClick={() => track('cta_click')}>{rc.getString('cta_label', 'Buy now')}</button>;
}

Hooks: useNexus(), useTrackEvent(), useFlag(key), useRemoteConfig(), useRemoteConfigValue(key, fallback). Pass an existing client with <NexusProvider client={nexus}>.

Server-side sends

From Node you can drive the server products — push, Live Activities, in-app fetches — with the same client:

await nexus.push.notification().title('Shipped').toUser('u_1').send();
await nexus.liveActivities.template('order_tracking', 'order_42').step('pending').toUser('u_1').start();

Lifecycle

await nexus.flush();   // everything, now
nexus.dispose();

Telemetry flushes automatically on page hide / tab switch and on SIGTERM, SIGINT and beforeExit.

On this page