Getting Started

One script tag gives your game login and analytics. A second package gives it cloud saves.

What you get

  • Authentication: Google and Discord sign-in, and a widget your players already recognise.
  • Analytics: daily active players, average session length, and day-1/7/14/28 retention, counted from real sessions.
  • Player data, per-player cloud saves, read and written from your game server.
  • Progression: name your game's milestones and see which one players stop at, on the dashboard or as JSON. Start the list at the moment your game becomes playable: a funnel cannot see anyone who never reached its first step.
  • Errors: the crashes your players hit, from the browser and your game server, grouped and ready to hand to a coding agent.
  • Tokens: coming soon.
1

Get your API keys

  1. Sign up at strafe.fun/signup.
  2. Go to your games and click New Game.
  3. Open the game, then Settings → API Keys → Generate API Keys.
  4. Copy the App ID (public, goes in your page) and the App Secret (server only, shown once).
The secret authenticates your game server. Keep it out of browser code, out of git, and out of anything you ship to players. If it leaks, regenerate it on the same screen.
2

Add the SDK to your game

Browser

<script src="https://strafe.fun/js/strafe.js"></script>
<script>
  const strafe = new Strafe({ appId: 'your-app-id' });
</script>

That single line mounts the login widget and starts measuring sessions. Analytics needs no further setup. From npm instead:

npm install @strafe-fun/sdk

import { StrafeClient } from '@strafe-fun/sdk/browser';
const strafe = new StrafeClient({ appId: 'your-app-id' });

Server (optional)

Only needed for cloud saves and for reacting to logins on your own game server.

const { Strafe } = require('@strafe-fun/sdk/server');

const strafe = new Strafe({
  appId: 'your-app-id',
  appSecret: process.env.STRAFE_APP_SECRET,
});

strafe.on('playerJoin', (player) => {
  console.log(player.id);          // unique player id
  console.log(player.name);        // display name
  console.log(player.data);        // saved data (already loaded)
});

// Save player data any time
strafe.savePlayerData(player.id, { highScore: 9001 });
3

Check it actually works

Check it worked

Open the sandbox with your App ID. It loads the real SDK, sends real events, and tells you which ones we received, usually within a second or two.

Then open your own game and watch the same checklist under Settings → Setup on your game's page. Every line there is something we actually received, so nothing reads as “working” until it genuinely is.

From your game's own console, the same check by hand:

// in the page where you created the client
await fetch('https://strafe.fun/api/sdk/verify', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    appId: strafe.getAppId(),
    sessionId: strafe.getSessionId(),
    deviceId: strafe.getDeviceId(),
  }),
}).then(r => r.json()).then(console.log);

// { app: { exists: true, active: true },
//   session: { startedAt: '...', durationSec: 0, identity: 'device' }, ... }

session: null means nothing arrived. Check the App ID, and check the browser console for a blocked request. Full details in the API reference.

Where to next

  • Authentication: reading the logged-in player, verifying tokens server-side.
  • Analytics: exactly how DAU, session length and retention are counted, and the consent rules for anonymous players.
  • Progression: two lines to name your milestones, and a funnel that says which one players stop at and how long they lasted first.
  • Errors: what the SDK captures on its own, how crashes are grouped, and how to pull them as a brief for a coding agent.
  • Tokens: what's planned, and what to do today so you're ready.