# How to send server events from Node.js

> Send purchases, match results, and webhook events from a Node.js backend or game server with the Secret key, joined to the same player as the game.

By Yos Riady. Updated 2026-11-24. Published 2026-11-24. Canonical URL: https://manalens.dev/integrations/nodejs

A Node.js backend or game server sends server events to POST /v0/events with the project Secret key. Use them for what the server knows best: purchases, match results, and webhooks. Forward the player ID or the anonymous ID of the game, so server events join the same player. The Secret key stays on your server, never in a page or a game build.

## Key takeaways

- A Node.js server sends up to 100 server events in one request to POST /v0/events with the Secret key.
- Send user_id, anonymous_id, or both, so server events join the same player as the game or the website.
- Make the message_id from the provider event ID, so a webhook that arrives twice counts once.

## Do I need an SDK for server events?

No. Node.js 18 and later has fetch, so one POST request sends a batch of up to 100 events. The Manalens Node SDK adds a queue, retries, and shutdown(). It is not public yet: request it from the contact page. The with-express-server example uses it.

1. Create a Secret key in Settings, General, Credentials. It is shown once.
2. Store it in an environment variable or a secret store on your server.
3. Send events to POST /v0/events with Authorization: Bearer and channel server.
4. Set user_id, anonymous_id, or both, and a message_id for each event.
5. Check for 202 and the events in the project activity feed.

- [Request the Node SDK](https://manalens.dev/support)
- [Example: with-express-server](https://github.com/manalens/examples/tree/main/with-express-server)

## How do I send a server event?

Send the Secret key as Authorization: Bearer, with no x-publishable-key header. Every event has channel server and type track or identify. A request from a browser with the Secret key gets 403, so this code must run on your server.

*Node.js, on your server*

```javascript
await fetch('https://events.manalens.dev/v0/events', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MANALENS_SECRET_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ events: [{
    channel: 'server', type: 'track', event: 'match_end',
    user_id: 'player_42', message_id: crypto.randomUUID(),
    properties: { mode: 'duel', won: true },
  }] }),
});
// 202 {"accepted":1}
```

## How do I join server events to the player?

Send user_id, anonymous_id, or both. With only user_id, the event joins that player. With the anonymous_id of the game or the browser, it joins that device, even before the player signs in. With both, earlier anonymous activity joins the player profile. To put the event in the player session, also send the session_id of the same client.

*Where each ID comes from in the game or on the website.*

| SDK | Anonymous ID | Session ID |
| --- | --- | --- |
| JavaScript web SDK | getAnonymousId() | getSessionId() |
| Godot addon | get_anonymous_id() | get_session_id() |
| Unity package | AnonymousId | SessionId |

## How do I handle webhooks and retries?

Make the message_id from the provider event ID, so a webhook that arrives twice counts once. Do not send the IP or the user agent of a webhook request: they belong to the provider, not the player. For a player request, forward the player IP and user agent in context. Manalens uses the IP only for an in-memory country lookup and never stores it.

Stripe and Paddle need no code: connect their webhooks in Settings, Integrations, and put the player ID in the checkout.

- [How to connect Stripe for game sales and subscriptions](https://manalens.dev/integrations/stripe)
- [How to connect Paddle for game sales and subscriptions](https://manalens.dev/integrations/paddle)

## How do I check that server events arrive?

A good request returns 202 with {"accepted":N,"rejected":0,"errors":[]}. A refused event is listed in errors with a reason. Then check the events in the project activity feed. Server events appear in every report, and channel reports show them as Direct. A 403 with SECRET_KEY_FROM_BROWSER means the request has an Origin header, so it did not come from your server.

## Frequently asked questions

### Which key do server events use?

The Secret key, which starts with mana_sk_. Keep it on your backend in an environment variable or a secret store. The Publishable key cannot send server events, and the Secret key cannot send web or app events. A browser request with the Secret key gets 403, so a key in a page fails.

### How many events can one request send?

Up to 100 server events and 256 KB in one request. Every event in the batch must have channel server. Old timestamps are allowed, so you can backfill, but a timestamp more than 5 minutes in the future is refused. Server events have their own rate limit, separate from game events.

### Is the Node SDK public?

Not yet. The Manalens Node SDK adds a queue, retries, and shutdown(), and it is available on request from the contact page. Without it, Node.js 18 and later can send server events with fetch. The JavaScript, Godot, and Unity SDKs are already open source on GitHub.

## Sources

- [Node.js: fetch](https://nodejs.org/api/globals.html#fetch)
- [Stripe: Webhooks](https://docs.stripe.com/webhooks)

## Related guides

- [Example project: with-express-server](https://github.com/manalens/examples/tree/main/with-express-server)
- [Example project: with-stripe](https://github.com/manalens/examples/tree/main/with-stripe)
- [Example project: with-paddle](https://github.com/manalens/examples/tree/main/with-paddle)
- [How to add analytics to an Electron game](https://manalens.dev/integrations/electron)
- [Server events reference](https://docs.manalens.dev/sdks/server)
