Skip to documentation

INSTALLATION & SDK USAGE

Start collecting events.

Connect your website or backend to Neksora. Install the SDK, send your first event, and check that it reaches your project.

Quick start

  1. Create or select a project in the correct environment.
  2. Add your website’s exact allowed origin in project settings, including the scheme and port, such as https://shop.example.com.
  3. Open Install & verify to generate a public pk_ collection key and a snippet configured for your project. Save the key; its raw value is shown only when created.
  4. Install the snippet, connect your consent manager, and visit an allowed page. Use Check collection and Live events to inspect delivery.
The tracking script URL serves JavaScript. The collector URL receives events and must include /v1/batch. Use your deployment’s URLs; the example.com addresses below are placeholders.

Install the browser script

Add this to your HTML <head> once per page. Replace the public key, script URL, and collector URL with the values from Install & verify.

HTML · browser installation
<script>
  window.neksora = window.neksora || function () {
    (window.neksora.q = window.neksora.q || []).push(Array.from(arguments));
  };
</script>
<script async
  src="https://cdn.example.com/tracker.js"
  data-project-key="pk_your_public_project_key"
  data-endpoint="https://events.example.com/v1/batch"
  data-collect-campaigns="false"
  data-mode="anonymous"
  data-consent="pending"></script>

The queue accepts calls before the script finishes loading. This example waits for consent; connect the callbacks in Consent & privacy to start collecting. Events attempted while collection is paused are discarded.

For a single-page app, load the snippet once in the root layout. Initial page views and History API navigation are tracked automatically. Avoid adding a manual page call for the same navigation.

Use HTTPS in production. HTTP is supported only on localhost or loopback for development. If you host the script yourself, build the repository with npm run build and serve packages/sdk-web/dist/tracker.js from your static host.

Use the browser package

The browser package is currently a local workspace package and has not been published to npm. In a repository workspace app, declare "@neksora/sdk-web": "*" in dependencies, install from the repository root, then build the SDK:

Shell · build browser package
npm install
npm run build --workspace @neksora/sdk-web

Initialize on the client, such as in a React effect. Keep one client per application and call destroy() on teardown. Choose either the script or package installation for a page.

TypeScript · browser client
import { createAnalytics } from '@neksora/sdk-web';

const analytics = createAnalytics({
  projectKey: 'pk_your_public_project_key',
  endpoint: 'https://events.example.com/v1/batch',
  mode: 'anonymous',
  consent: 'pending',
  collectCampaigns: false,
  excludePaths: ['/account/private/'],
  onDiagnostic: ({ code, count, status }) => {
    console.info('Neksora delivery', { code, count, status });
  },
});

// Call when your consent manager grants analytics permission.
analytics.setConsent(true);
analytics.track('product_viewed', { product_id: 'sku-123' });
await analytics.flush();

// On application teardown:
analytics.destroy();

The package is ESM-only. Browser initialization requires a secure context and modern browser APIs including fetch, AbortController, TextEncoder, and crypto.randomUUID.

Track custom events

Call track when an action completes. Use stable event names and JSON-safe properties: strings, numbers, booleans, null, arrays, and objects.

JavaScript · custom events
window.neksora('track', 'product_viewed', {
  product_id: 'sku-123',
  category: 'accessories',
  price: 49,
  currency: 'USD',
});

window.neksora('track', 'signup_completed', {
  plan: 'starter',
  source: 'pricing',
});

// Optional: record a manual page view when automatic page views are off.
window.neksora('page', { section: 'catalog' });

Package usage is equivalent: analytics.track(name, properties). Page views, sessions, engagement, 90% scroll depth, outbound links, and downloads are enabled by default. Forms, site search, video, page titles, device details, and UTM campaigns require configuration.

TypeScript · optional browser measurement
// Add these options to createAnalytics(), or a queued 'init' command.
const measurementOptions = {
  collectCampaigns: true,
  collectPageTitle: true,
  collectDeviceInfo: true,
  enhancedMeasurement: {
    scroll: [25, 50, 75, 90],
    outboundClicks: true,
    downloads: true,
    forms: true,
    siteSearch: { parameters: ['q', 'search'] },
    video: true,
  },
};

For advanced script configuration, queue window.neksora('init', options) before the async script loads, with your key, endpoint, consent, and measurement options. A queued init takes precedence over the script’s data attributes.

Identify customers and accounts

Enable identified collection in project settings and set data-mode="identified" or mode: 'identified'. Use the same immutable application user ID on every device, and identify again after restoring your application’s authenticated session.

JavaScript · customer identity
// After your application authenticates the customer:
window.neksora('identify', 'customer-123', { plan: 'growth' });
window.neksora('group', 'company-456', { plan: 'business' });

// Subsequent browser events use this identity.
window.neksora('track', 'report_created', { format: 'csv' });

// On logout, before another person uses the app:
window.neksora('reset');

identify and group do nothing in anonymous mode. Reset deliberately discards pending events to avoid carrying one user’s activity into another account.

Profile email is redacted by default. Collecting it requires the project’s separate Allow profile email permission and SDK option collectUserEmail: true (or data-collect-user-email="true"). Send it only as an identify trait; email: null removes the profile value. Email in ordinary event properties remains redacted.

Record ecommerce events

Use the ecommerce helper for validated shopping events, including view_item, add_to_cart, begin_checkout, purchase, and refund.

JavaScript · purchase event
window.neksora('ecommerce', 'purchase', {
  transaction_id: 'order-123',
  currency: 'USD',
  value: 49,
  items: [
    { item_id: 'sku-123', item_name: 'Travel bag', price: 49, quantity: 1 },
  ],
});

Purchase and refund events require a transaction ID. Items need an ID or name; quantities must be positive integers and monetary values finite and nonnegative. Include an uppercase three-letter currency whenever you supply value. Repeated calls create distinct events, so reconcile transactions by your business transaction ID.

Send events from Node.js

Use Node.js 22 or later. The Node SDK supports ESM, CommonJS, and TypeScript. It is not yet published to npm; workspace consumers can declare "@neksora/sdk-node": "*". To generate a verified archive for another application, run these commands from the repository root:

Shell · build and pack Node SDK
npm install
npm run build --workspace @neksora/sdk-node
npm run sdk-node:check

# In your consuming application, install the generated archive:
npm install /absolute/path/to/neksora/dist/releases/npm/neksora-sdk-node-0.1.0.tgz

A deployment administrator must issue a server credential scoped to your project and environment. On an initialized deployment with migrations applied and the updated worker and ingestion service running:

Shell · create server credential
go -C services/ingestion run ./cmd/admin --action server-key-create \
  --project PROJECT_UUID --environment test --name 'Application backend' \
  --expires-in 2160h

Save the returned write_key in your backend environment as NEKSORA_SERVER_WRITE_KEY. Keep it out of browser bundles and NEXT_PUBLIC_* variables. Server events use /v1/server/batch; browser public keys and the browser endpoint are separate.
TypeScript · server events
import { createAnalytics } from '@neksora/sdk-node';

const writeKey = process.env.NEKSORA_SERVER_WRITE_KEY;
if (!writeKey) throw new Error('Missing NEKSORA_SERVER_WRITE_KEY');

const analytics = createAnalytics({
  writeKey,
  endpoint: 'https://events.example.com/v1/server/batch',
});

analytics.identify({ userId: 'customer-123', traits: { plan: 'growth' } });
analytics.track({
  userId: 'customer-123',
  event: 'payment_confirmed',
  properties: { transaction_id: 'order-123', value: 49, currency: 'USD' },
});

// Await delivery before a serverless invocation ends.
const result = await analytics.flush();
console.info('Delivery counts', result.accepted, result.suppressed);

// During application shutdown, after producers have stopped:
await analytics.shutdown();

Pass identity on every server event; identify() emits an event without changing shared client state. Enable identified collection on the project to send identities. For an event without identity, pass mode: 'anonymous' and omit user, visitor, and group IDs. Pass consent: false to discard an individual call.

The server SDK does not infer visitor device, page, session, timezone, or IP from the backend machine. Pass verified visitor context explicitly. To connect browser history, pass the browser’s UUID as anonymousId alongside the authenticated userId.

flush() drains the events queued at invocation and returns accepted and suppressed counts. Delivery failures reject with DeliveryError and retain unsent events. Inspect code, status, retryAfterMs, and pending before retrying. shutdown() seals the client and drains it; do not call it after every request on a shared client.

Queues are in memory. For business-critical events, persist an event UUID and payload with the business transaction in an application outbox. Pass that UUID as eventId and reuse it with the same payload on retry.

Browser API reference

Use analytics.method(...args) with the package, or window.neksora('method', ...args) with the script. Calls needing a return value must wait until the script has loaded.

Browser SDK methods and behavior
MethodBehavior
track(name, properties?)Record a custom event. Properties must be JSON-safe.
page(properties?)Record a page view for the current URL. Automatic page views are enabled by default.
ecommerce(name, properties)Validate and record a supported ecommerce event.
identify(userId, traits?)Associate a customer in identified mode. Call again after restoring authentication.
group(groupId, traits?)Associate an account in identified mode.
getSessionId() / getAnonymousId() / getUserId()Read existing in-memory IDs without allocating new ones. Wait until the script is loaded; await flush() after capture when using Web Locks.
setConsent(boolean) / optOut()Enable collection, or withdraw consent and clear pending events and identity.
reset()Discard unsent events, abort delivery, and clear visitor, customer, and group identity. Use on logout.
flush()Attempt a browser batch. Delivery failures are reported through diagnostics.
destroy()Stop the client, discard pending events, and remove listeners.
attachYouTube(player)Attach an existing YouTube API player. Package usage returns a detach function.

Browser defaults: batches of 20 events, a 5-second flush interval, and a 500-event pending queue. Temporary network failures retry while the page stays open; delivery is best effort and pending events do not survive a reload.

Verify & troubleshoot

  1. Visit the installed website on an allowed origin, grant analytics consent, and trigger a distinctive test event.
  2. In your browser’s Network panel, confirm the script loads and a POST reaches the configured /v1/batch URL. Default batching can take about five seconds.
  3. Open the project’s Install & verify screen and click Check collection. Inspect Live events for the event name and timestamp.

No network request

Check consent, DNT/GPC, excluded paths, blocked scripts, and your content security policy. Allow the script host in script-src and the collector origin in connect-src. A localhost collector works only on the visitor’s own device.

Collector rejects events

Check the key’s project and environment, key expiry or revocation, exact allowed origin, project enabled state, and identity permissions. For browser collection across origins, the collector must allow POST and OPTIONS with the Content-Type header.

Events accepted but not visible

Acceptance and processing are separate steps. Confirm the worker is running, wait for processing, and check again. Collection verification includes earlier retained events; match your test event’s timestamp in Live events.

Duplicate page views or missing identity

Install one client and avoid manual page calls alongside automatic page views. Identity needs identified mode, project permission, and a new identify call after authentication is restored.