Gamejar

For developers › Gamejar SDK

Gamejar SDK: leaderboards and saves

Add one script and your game gets leaderboards (this week, all time) and saved progress for players. Gamejar takes care of sign-in, the server and the database. Free.

A request (prompt) for the AI

If you make your game with Claude or another AI, copy this, fill in the last 3 lines and give it together with your game's code. The AI doesn't know the Gamejar SDK, so the request lists exactly which functions to use.

Please add the Gamejar SDK to my game (a leaderboard and saved progress).

Everything the SDK has (nothing else exists, don't invent functions):
- In index.html's <head>, BEFORE any other script: <script src="https://gamejar.fun/sdk.js"></script>
- Gamejar.score.submit(score)  → Promise { ok, improved, best, rank }. Only a better score counts.
- Gamejar.showLeaderboard()  → Gamejar draws the leaderboard window itself. The Promise ends when it closes.
- Gamejar.score.top({ period: 'week' })  → { list: [{ rank, name, score, me }], me }
- Gamejar.player()  → Promise { name } or null (not signed in)
- Gamejar.save.set('progress', data) / Gamejar.save.get('progress') / Gamejar.save.remove('progress')  → signed-in players only (otherwise false / null)

What to do:
1. Every time a round ends (won or lost), send the score with Gamejar.score.submit().
2. Add a «🏆 Leaderboard» button on the start screen and the game-over screen: pause the game, call Gamejar.showLeaderboard(), carry on when it closes.
3. If the game has levels or progress: keep saving to localStorage, and also save with Gamejar.save.set('progress', …). At start, take whichever of Gamejar.save.get('progress') and localStorage got further.
4. Don't make your own sign-in button, leaderboard table or «new best» message: Gamejar shows those itself.
5. No other servers, Firebase or online connections. Keep all the code in ONE index.html file.

My game's score:
- What the score is: (e.g. stars collected, seconds survived)
- Is higher or lower better:
- Highest possible score:

1. Add the script

Put it in index.html's <head>, before your game's own code, so window.Gamejar is ready when the game starts.

<!-- index.html, <head> дотор, тоглоомынхоо скриптээс ӨМНӨ -->
<script src="https://gamejar.fun/sdk.js"></script>

2. Send scores, show the board

Send a score whenever a round ends: only a player's better score is kept. Gamejar shows a small note at the top on a new best.

If the player isn't signed in, the score waits in the browser and goes on the board once they sign in. Gamejar offers the sign-in itself.

// Тоглолт дуусахад (зөвхөн илүү сайн оноо тооцогдоно)
Gamejar.score.submit(1250);

// Шилдэг онооны цонх (Gamejar өөрөө зурна)
button.onclick = () => Gamejar.showLeaderboard();

// Эсвэл жагсаалтыг өөрөө зурах
const { list, me } = await Gamejar.score.top({ period: 'week' }); // 'week' | 'all'
// list: [{ rank: 1, name: 'ХурданЧоно42', score: 1250, me: false }, …]

3. The player

You only ever see the player's username. Their email and Google details never reach you.

const p = await Gamejar.player();   // { name: 'ХурданЧоно42', supporter: false } эсвэл null
Gamejar.onPlayer((p) => { /* нэвтэрсэн / гарсан үед */ });
Gamejar.login();                        // Gamejar-ын нэвтрэх цонх (товч дарахад дуудна)

4. Saving progress (cloud save)

Keeps a signed-in player's progress: start on a phone, carry on on a computer. Up to 32 KB a value, 64 KB in all per game.

Keep saving to localStorage for players who aren't signed in. At start, take whichever of the two got further.

// Тоглогч нэвтэрсэн бол явцыг нь хадгална (өөр төхөөрөмж дээр ч үргэлжилнэ)
await Gamejar.save.set('progress', { level: 7, coins: 340 });   // нэвтрээгүй бол false
const s = await Gamejar.save.get('progress');                   // байхгүй бол null
await Gamejar.save.remove('progress');

5. Testing on your computer

Anywhere but Gamejar (localhost, a file) the SDK runs in test mode: every call works and is kept in your browser only. You can build and test the whole game without Gamejar.

// Өөрийн компьютер дээр: SDK бүх зүйлийг энэ хөтөчид хадгалж, жинхэнэ шиг ажиллана.
// Жагсаалтаа тайлбарлаж болно (Gamejar дээр илгээх маягтын тохиргоо үйлчилнэ):
Gamejar.init({ boards: { main: { order: 'asc', format: 'time', mn: 'Хугацаа' } } });

6. When you send the game

On the submit form, tick «🏆 Leaderboard» and fill in the board's name, which is better (higher or lower), the highest possible score and how it is shown.

The SDK reaches the real boards only while your game runs at its own address (<your-id>.gamejar.fun). It can never touch another developer's scores or saves.

Scores are sent by the player's browser, so someone may try to send a fake one. Anything above the highest possible score is refused, and we remove fake scores and ban the player.

Send your game → For developers