Skip to main content
In a multiplayer game, each player’s game client tracks that player. A dedicated server is not a player. It sends only the results that it decides, such as a match result or a checked purchase.

Who sends what

Never put the secret key in a client build. Anyone can read a key from a game build. A game build uses only the publishable key. The secret key stays on your server, in an environment variable.

A server build is not a player

The game SDKs know when they run in a dedicated server build: In a server build, the SDK does not send game_open, session_start, session_end, or app_crash. So the server does not count as an install, a player session, or a crash. It logs one line that tells you why. Your own track() and identify() calls still work. They use the server’s own anonymous ID, so they do not join a player. Use them only for events about the server itself, for example server_start. Set build (for example "server") so you can filter them. To send the automatic events from a server build anyway, turn on the option: For example, a listen server (a host who also plays) is a player. In Godot, a host started with --headless for a test is a server build. Turn the option on for these runs.

Send results from the server

Results that the server decides belong to the player, not to the server. Send them from the server with the player’s IDs. This is the same pattern as a web checkout: the client sends its IDs, and the backend sends the event.
  1. The client sends its anonymous_id and session_id to the server, for example when it joins the match.
  2. The server sends the event with the Node.js SDK in server mode, or with the HTTP API. It uses the secret key, and sets anonymous_id and session_id of that player. Add user_id when you know the player’s account.
Node.js
HTTP
The event joins the player’s profile and session, so it appears in the same reports as the client events. See Join server events to players and Session ID of the client. A server written in Godot, Unity, or Unreal has no secret key option in the game SDK. Send these events from the server process with an HTTP request (as the curl example), or from a backend in Node.js.

Purchases

The client can send a purchase event at once. When your server checks the receipt, send the checked purchase from the server with the player’s IDs. Add validated: true so you can tell the two apart. See Server events.

Checklist

  • Each client uses the publishable key and tracks its own player.
  • A server build sends no game_open and no sessions, unless you turn on the option.
  • The server sends match results and checked purchases with the secret key, the player’s anonymous_id, and the player’s session_id.
  • The secret key is never in a client build.