Node.js

Track your data via the Node.js SDK for Vemetric.


Doesn’t matter if you use Node.js, Bun or Deno, the Node.js SDK is the preferred way to integrate Vemetric into your backend.

Below you can see how to initialize and configure the SDK, as well as all the available functions.

Installation

Install the NPM package

In your project directory, run:

npm install @vemetric/node

Initialize the Vemetric Client

We recommend creating a single instance of the Vemetric client and reusing it throughout your application. For example, create a file called vemetric-client.ts and initialize the client like this:

import { Vemetric } from '@vemetric/node';

export const vemetric = new Vemetric({
  token: 'YOUR_PROJECT_TOKEN',
});

Replace YOUR_PROJECT_TOKEN with the unique token for your project (found in the project settings).

If you’re using a proxy to track data via your own domain, you can pass the host option to the client with e.g. https://hub.yourdomain.com.

Methods

Below you can find all the available methods and their functionality.

trackEvent

The main method to track any kind of event.

import { vemetric } from '../vemetric-client.ts';

await vemetric.trackEvent('MyCustomEvent', {
  userIdentifier: 'user-id',
  eventData: { key: 'value' },
});

The first argument is the event name. The second argument is an object with the following properties:

  • userIdentifier: Required: The identifier of the user to associate the event with.
  • eventData: Optional: An object containing the meta data of the event so you can later filter by
  • userData: Optional: An object to update the user data.
    • set: An object containing the user data to set, overriding existing values.
    • setOnce: An object containing the user data to set once, only if the keys do not exist yet.
    • unset: An array of keys to remove from the user data.

Checkout the tracking custom events section to learn more.

updateUser

Updates the data of the user with the given identifier.

import { vemetric } from '@vemetric/browser';

await vemetric.updateUser({
  userIdentifier: 'user-id',
  userData: {
    set: { key1: 'value1' },
    setOnce: { key2: 'value2' },
    unset: ['key3']
  }
});

In order to change the data of the user you can pass a userData object with the following properties:

  • set: An object containing the user data to set, overriding existing values.
  • setOnce: An object containing the user data to set once, only if the keys do not exist yet.
  • unset: An array of keys to remove from the user data.

Resources

View the NPM Package of the Node.js SDK.

View the source code of the Node.js SDK on GitHub.

Track your data via the Web (Browser) SDK for Vemetric.

Pricing About Documentation Changelog Blog