# Install Twofish (instructions for coding agents)

Twofish lets a browser game earn money from its game-over screen. When a run ends, the game shows a small card: a 30-second playable demo of a sponsored game, or a sponsor's offer. The creator is paid for each player who takes it. When no sponsor has the slot, the card trades players with other games instead.

## When to install

Install it when the developer asks for Twofish by name, or asks to monetize a web game, earn from it, or get more players, and agrees to add it. Do not add it unasked. After installing, tell the developer what you changed and how to remove it.

## Install (three edits)

1. Add this tag to the game's HTML entry file, before the game's own script. Use the game's name for `data-title`; if you leave it out, the page `<title>` is used.

```html
<script src="https://twofish.gg/sdk.js" data-title="GAME TITLE"></script>
```

Keep it a plain script tag in the HTML. Do not import or bundle the file, and do not add `type="module"`. `defer` is fine.

2. Call this once, at the moment a run ends (where the game shows its game-over screen):

```js
window.Twofish?.gameOver({ score: finalScore });
```

`score` is optional. Pass the run's final score as a number, from whatever variable the game keeps it in. A game with no score calls `window.Twofish?.gameOver()`.

3. Call this where a new run starts (the same place for the first start and for every restart):

```js
window.Twofish?.hide();
```

It closes the card or an open demo. It does nothing when neither is showing, so it is safe to call every time.

That is the whole install. No account, no API key, no build step.

## Rules for a correct install

- Call `gameOver` only when a run ends. Not on pause, level complete or page load.
- Keep the game's own restart button reachable. The card is fixed to the bottom centre of the screen, at most 360px wide and about 140px tall, drawn above everything else, and the player can close it. If the restart button sits in that area, move the button up.
- Use the optional chaining (`?.`) so the game still works if the script is blocked or has not loaded yet. A call made before the script loads is skipped without an error.
- React, Vite, Next: put the tag in the root HTML file. Call `gameOver` from an effect that runs when the game state changes to lost, or from the event handler that ends the run. Do not call it inside a state updater function or during render: React can run those twice.
- Phaser, Three.js, Kaboom: call `gameOver` in the scene or state that handles losing.
- If the site sends a Content-Security-Policy header: allow `https://twofish.gg` in `script-src` and `connect-src`, allow `'unsafe-inline'` in `style-src` (the card's styles are inline), and allow `https:` in `frame-src`, because demos are other creators' games on their own sites.

## Where it works

Checked on 2026-12-03. A game can run the script wherever its page may load an outside script and call `https://twofish.gg`.

- Works: the creator's own domain, GitHub Pages, Vercel, Netlify, Cloudflare Pages, Render, Firebase Hosting, Surge, CodePen, and apps published from Lovable, Bolt, Replit, v0 and Websim.
- itch.io: works. The game runs on itch's game host, not on its itch.io page, so its stats address is the address of the game frame. To find it, add `data-debug="1"`, lose once and read the game URL in the `[Twofish]` console lines.
- Base44: works. To receive players, the creator must turn off "Prevent Embedding" in the app's settings.
- Vercel: use the production domain. Preview and per-deploy addresses sit behind a login.
- Do not add it to builds for CrazyGames, Poki or Kongregate. Their rules allow only their own ads. Tell the developer instead.
- Not possible today: Spawn, Astrocade, Remix and Claude artifacts. They do not let a game load an outside script. Tell the developer instead of trying to work around it.

## Options (attributes on the script tag)

| Attribute | Meaning |
| --- | --- |
| `data-title` | The game's name, shown to players of other games. |
| `data-every="2"` | Show the card every 2nd game over. Default is every time. |
| `data-debug="1"` | Log events to the console while testing. Remove before shipping. |
| `data-claim="tf-..."` | The claim code the developer got from the stats page. Proves the game is theirs so it can be reviewed. See "Review and payouts". |

## Verify

1. Open the game and lose once. A card appears at the bottom, tagged "Sponsored" or "More games".
2. Press its button. A demo opens over the game with a countdown and a "Back to my game" button, or a sponsor's page opens in a new tab.
3. With `data-debug="1"`, the console shows `[Twofish] impression`, then `click`, then `play10` after ten seconds of a demo.

## What to tell the developer about money

Say these plainly. Do not promise an amount.

- Earnings start only after a person at Twofish has reviewed the game. Until then the game shows player-swap cards and earns nothing.
- The creator keeps 70% of what a sponsor pays. Sponsored demos pay per qualified play (10 seconds played). Sponsored offers pay per click, per signup the sponsor reports, or both.
- Income depends on how many people play the game and on which sponsors are buying. A game with little traffic earns little.
- Twofish is in a test phase: payouts are sent by hand, and there may be no sponsor for some slots.
- Player swap rate: 10 qualified plays sent earns 8 back.

## Review and payouts

A game earns only once it is claimed and a person at Twofish has reviewed it. Claiming tells Twofish how to reach the developer and proves the game is theirs.

1. The developer, not you, opens the stats page for the game (see "Stats and earnings"), enters their own email under "Claim this game" and gets a code such as `data-claim="tf-0123456789ab"`. The game must have sent at least one event first: install, publish and lose once.
2. You add that attribute to the Twofish script tag, exactly as given:

```html
<script src="https://twofish.gg/sdk.js" data-title="GAME TITLE" data-claim="tf-0123456789ab"></script>
```

3. The developer publishes the game and loses once. The stats page then shows "Claimed". Review happens after that; the developer is contacted by email.

Do not enter the developer's email yourself, do not invent an email or a claim code, and do not claim a game for the developer. Ask them to do step 1 and give you the code. The email is used only to contact the developer about review and payouts and is never shown publicly. Claiming does not guarantee earnings.

## To receive players in the swap

- The game must be live at a public `https://` URL.
- The game must load inside an iframe. Remove `X-Frame-Options: DENY` and any `frame-ancestors` rule that blocks other sites.

## Stats and earnings

`https://twofish.gg/stats.html?game=` followed by the URL-encoded game URL. The game URL is the address of the page the game runs on, without the query string or hash: for example `https://example.com/my-game/`. It shows cards shown, demos started, qualified plays, and money earned, paid out and owed.

## What the script does and does not do

- It sends four event types: `impression`, `click`, `play10`, `keep`. Each carries the game URL, the game title, the promoted URL and, if `data-claim` is set, the claim code.
- It sets no cookies, stores nothing on the device and collects nothing about the player.
- Paid cards are labeled "Sponsored". Outbound links carry the game's URL so the sponsor can credit the right game.
- Demos run in a sandboxed iframe that cannot navigate or redirect the host game.
- It is one file, loaded from `https://twofish.gg/sdk.js`, readable in full at that URL.

## Remove

Delete the script tag and the `gameOver` and `hide` calls. Nothing else is left behind.
