Markers
This API is used to send engagement markers to the Gamebeast platform, from the browser and from servers.
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.
Client methods
In the browser, markers are attributed to the current user and session automatically.
They're sent in batches of 10, or every 10 seconds. When the page is hidden or closed, buffered markers go out with fetch keepalive, so they survive the page unloading. If the browser is offline, they're saved to localStorage and sent when the connection returns or on the next visit.
send(eventName, properties?)
voidreturn type
Records a marker for the current user and session.
eventNamestringThe name of the marker, e.g. "level_completed".
propertiesRecord<string, unknown>The marker's data, as a plain JSON-serializable object. Optional.
Usage
gamebeastMarkers.send("RoundEnded", { Score: 600, Map: "Office", Duration: 120 });flush()
Promise<void>return type
Sends everything buffered now. Resolves once the requests have settled.
Server methods
On the server, 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.
eventNamestringThe name of the marker, e.g. "purchase_completed".
propertiesRecord<string, unknown>The marker's data, as a plain JSON-serializable object. Optional.
options.distinctIdstringThe user the marker is about. Omit it for a server-level marker.
options.sessionIdstringThe user's session, if you track one. Optional.
options.timestampnumber | DateWhen 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 };
}