Web games: your website and your game
A browser game usually shares a domain with its own website: a landing page, a pricing page, a sign in page, then the game. If the game SDK starts on every page, every visitor opens a game session and counts as a player, and your player numbers stop meaning players. Keep the two apart: the website tracker on your site, the game SDK inside your game.
Two trackers, two jobs
Ravensight has two separate ways to measure a web game, each with its own key, and they are meant to run on different pages.
| Where | Use | Key | What it counts |
|---|---|---|---|
| Public pages: landing, marketing, pricing, blog | The website tracker, createSiteTracker() |
Your website key, gt_site_... |
Visitors, page views, sources and goals, with no player identity |
| Inside the game, for a player who is playing | The game SDK, new Ravensight() |
Your game's public key, gt_pub_... |
Players, sessions, retention, funnels and everything else on the dashboard |
A key shipped in a web page is public, because anyone can read it from
the page: use a public key with an event allowlist and a monthly
ceiling, and keep gt_live_ keys on your own server. See
Public builds.
In a browser the game SDK sends game_started as soon as
the client is created and game_exited when the page is
hidden. That is right inside a game and wrong on a landing page: a
visitor who reads one page and leaves becomes a player with a two event
session. Two of our own web games did exactly this: over 30 days, more
than 80% of their new players were really website visitors.
Start the game SDK only inside the game
In a single page app, decide on every route change which tracker runs. Create the game client the first time a signed in player reaches a game route, never at app start and never on a public route. Run the website tracker on public routes and destroy it before a game route. Leaving the game for a public page keeps the game client, so the player's session carries on when they come back.
import Ravensight, { createSiteTracker } from 'ravensight';
let site = null; // the website tracker, public pages only
let game = null; // the game SDK, created once, inside the game only
// Your own rule for which routes are the game.
const isGameRoute = (path) => path === '/play' || path.startsWith('/play/');
// Call this from your router after every completed navigation.
export async function onRoute(path, account) {
if (isGameRoute(path) && account) {
if (site) { site.destroy(); site = null; }
if (!game) {
game = new Ravensight({ ingestKey: 'gt_pub_your_public_key', gameVersion: '1.4.0' });
await game.init();
}
// A random id stored with the account, never a sequential one: see below.
await game.identify(account.analyticsId);
} else if (!isGameRoute(path) && !site) {
site = createSiteTracker({ key: 'gt_site_your_website_key' });
}
}
-
Never create the game client to "warm it up".
Creating it is what sends
game_started, so a client built at app start counts the visitor even if nothing else is tracked. - Drop gameplay events from public pages. If shared code tracks an event before the game client exists, discard it instead of queueing it for later: a queued visitor event would be sent under the next player.
- Your sign in, sign up and account pages are public pages for this purpose. The website tracker already leaves out sign in, account and receipt routes on its own; see Connect a website for its consent and excluded path options.
- A game with no public pages (the page is the game, as in a typical HTML5 export) needs none of this: create the client when the game starts.
Identify on sign in, reset on sign out
A browser does not know who is playing, so without help the same person on a phone and a laptop counts twice, and two people on one browser count once. If your game has its own accounts, tell the SDK who signed in. This needs version 0.12.0 or later of the ravensight package.
// After your own sign in succeeds, and at boot when a session is already signed in.
// analyticsId: a random UUID made once per account and stored with it.
await game.identify(account.analyticsId);
// When the player signs out.
await game.resetIdentity();
-
Pass a random, high-entropy id, such as a random
UUID or a random analytics id you make once for each account and
store with it. Never pass a sequential database key, an email, a
name or a handle: your game's salt reaches every browser that plays
it, so anyone could hash 1, 2, 3 and onward and match a guessable
id, while a random one cannot be guessed. A value containing
@, an empty value and a value over 256 bytes are refused, andidentifyrejects with aTypeError, so await it or catch it. - Only a salted hash leaves the browser. The SDK hashes the id with your game's own salt and sends the hash once per session. The raw id is never sent or stored. The hash still identifies one player across sessions, so it is a pseudonymous identifier: declare it in your game's privacy notice.
- Each identified session uses one event from your included allowance, then from your prepaid balance. The same account again in the same session sends nothing and uses nothing. With an empty balance the request is refused, costs nothing, and is tried again at the next session.
-
resetIdentity()also switches the browser to a fresh device id, so the next person on that browser is not linked to the last one.
Every Ravensight SDK has the same pair of calls under its own language's spelling; see the page for your engine.
How Ravensight tells you
The Data quality card on your game's Health page, and
visitorSessions in the
get_data_quality tool, check for this on
every web game. They look at the devices first seen in the selected
range (30 days by default) that sent a web event, real players only,
and count how many never sent more than 3 events in any session: a
session start and very little else. Events your game server sends into
the browser's session count toward that session.
- Flagged when we are 95% sure at least 60% of those devices did nothing past a session start. The card shows a warning with the fix and a link to this page.
- Clear below that. A game where even half its new players leave at once stays clear.
- Too few to read with fewer than 10 new web devices.
Players who open your game and leave at once look the same as visitors, so a flag means "check where your site starts the SDK", not proof. After you fix it, the check reads only devices first seen since then, so it clears as the range moves past the fix; choose a shorter range on the Health page to see it sooner. Events already stored are not rewritten, so earlier visitors stay in your history.
To check by hand, open a public page in a private window with your
browser's network panel open. Nothing should go to the
/session endpoint and no game_started event
should be sent until you sign in and open the game.