GamebeastDocs
Dashboard
Node.js SDKAPI Reference

Markers

This API is used to send engagement markers from your server, for users or for the server itself.

For more information about Markers, visit the Markers Guide.

const gamebeastMarkers = gamebeast.markers;

Markers are batched and sent in the background. Each marker is validated when you send it: properties must be a plain JSON-serializable object, such as { level: 3 }, and are copied immediately, so changing the object afterwards doesn't affect the marker. An invalid marker is dropped with an error in the log rather than throwing, so one bad marker never fails a batch.

Failed sends are retried with exponential backoff. Rejections the backend won't accept on a retry (an invalid marker, a bad key) are logged and dropped.

You say who each marker is about. A marker without a distinctId is a server-level marker, attributed to this process's serverId.

Markers are sent in batches of 100, or every 5 seconds; change this with the markers option. During an outage the buffer holds up to 10,000 markers, then drops the oldest first. Call flush() or shutdown() before the process exits so nothing buffered is lost.

send(eventName, properties?, options?)

voidreturn type

Records a marker.

eventNamestring

The name of the marker, e.g. "purchase_completed".

propertiesRecord<string, unknown>

The marker's data, as a plain JSON-serializable object. Optional.

options.distinctIdstring

The user the marker is about. Omit it for a server-level marker.

options.sessionIdstring

The user's session, if you track one. Optional.

options.timestampnumber | Date

When the event happened, as epoch milliseconds or a Date. Defaults to now.

Usage

gamebeastMarkers.send("purchase_completed", { sku: "gems_100" }, { distinctId: user.id });

// A server-level marker, not tied to a user
gamebeastMarkers.send("server_restarted");

flush()

Promise<void>return type

Sends everything buffered now. Resolves once the requests have settled. In a serverless function, await it before the handler returns:

export async function handler(event) {
  gamebeast.markers.send(
    "checkout_completed",
    { total: event.total },
    { distinctId: event.userId }
  );
  await gamebeast.flush();
  return { statusCode: 200 };
}

On this page