Gamification shows up in fitness apps, learning platforms, loyalty programs, and SaaS onboarding: points for actions, streaks, levels, badges, a leaderboard. When the rules run in the browser the UI feels alive — the counter ticks up the instant you finish a lesson. It also means the entire rulebook ships to every user.
This article covers what a client-side gamification engine exposes, which parts must be authoritative on a server, and where code protection is and is not worth it.
The rules are a public download
A browser-side points engine usually looks like this:
export function award(event, state) {
const base = POINTS[event.type] ?? 0;
const streak = streakBonus(state.days, STREAK_TABLE);
const mult = state.tier ? TIER_MULT[state.tier] : 1;
return { ...state, points: state.points + (base + streak) * mult };
}
After a production build, POINTS, STREAK_TABLE, and TIER_MULT sit in a JS chunk. The whole economy is readable. A user can:
- Read exactly how many points each action is worth and which action has the best ratio.
- Call
awardfrom the console with a fabricated event and inflate their own total. - Patch the state object before it is synced and claim a badge, a tier, or a leaderboard spot they did not earn.
- Discover unreleased tiers, secret achievements, or a promo multiplier that was only hidden by the UI.
If points unlock something real — a discount, a prize draw, a paid tier, a public ranking — then a client-computed score is a number the user controls.
Low stakes vs. real stakes
Not every points counter needs defending. A "you read 3 articles today" nudge with no reward can live entirely in the browser; spending effort to protect it is wasted. The line is whether the number buys anything:
- Cosmetic / motivational: fine to compute and store client-side.
- Redeemable or competitive: the award must be computed and stored on the server from events the server itself witnessed.
Treat the browser's number as optimistic UI, and let the server be the ledger.
What to keep on the server
- The authoritative points balance, tier, and any badge that unlocks a reward.
- The award rules for anything redeemable or ranked (so the table is not a readable menu to game).
- Leaderboard computation, from server-recorded events, not client-submitted scores.
- Anti-abuse checks: rate limits, event validation, replay protection.
What protection can still do
Even with the ledger on the server, you may keep some logic in the client — an optimistic preview of what an action will award, or a rules engine you would rather a competitor not copy wholesale. For that slice:
- Make the server authoritative for anything redeemable; the client computes a preview, not the truth.
- Validate every synced event server-side; never trust a submitted total.
- Extract the preview or rules-engine function into its own module and apply a protection pass — renaming and string tables as a floor, VM-based protection if copying the economy logic is the concern.
- Keep production source maps off so the original rulebook is not handed back verbatim.
A JS VM obfuscator compiles the function to custom bytecode and ships a small interpreter, so pretty-printing the chunk no longer prints a clean points table and multiplier logic. It does not stop a user from faking events or editing their local total — only the server can — and it does not hide data the preview needs at runtime. It raises the cost of lifting your rules engine.
VEILVM is a browser-based JSVMP workspace (disclosure: I work on it) you can point at a preview or rules module before wiring protection into CI. Protect the proprietary logic; keep the ledger and the award rules for anything redeemable on the server.
Checklist
- [ ] Redeemable or competitive points are computed and stored on the server from server-witnessed events.
- [ ] The client total is treated as optimistic UI, never trusted on sync.
- [ ] Award tables that gate real rewards are not shipped as a readable chunk.
- [ ] Leaderboards are built from server records, not client-submitted scores.
- [ ] Only proprietary preview or rules logic is a candidate for protection; cosmetic counters are left alone.
- [ ] Production source maps are off, and synced events are validated and rate-limited.
If you want to try VM protection on a single extracted function, VEILVM runs in the browser with no sign-up: 3 free runs a day, up to 5 KB per file (resets at 00:00 UTC). A free account raises the input limit to 30 KB. Pro is $9/month or $79/year and adds an API so the protection step can run in CI. Standard requests are processed in memory and are not written to logs. Start at https://vm.ldvmp.com.
Top comments (0)