pro setup

Pro Setup

Cloudflare D1, API keys, leaderboard, analytics, and Kajabi webhooks.

GamifyKit Pro — setup

Pro turns on cross-device sync, real course leaderboards, quiz-gated paths, and

creator analytics. The backend is hosted by us (Wize); buyers only paste an API key.

Architecture

  • Backend lives in the Wize Astro app: src/pages/api/gamify/* (Cloudflare Workers).
  • State store: Cloudflare D1 (SQL) — chosen over Sanity because leaderboards need

ORDER BY xp and state writes are frequent. Schema: src/lib/gamify/schema.sql.

  • Auth: each buyer has an API key (Bearer) for theme→API calls; the creator dashboard uses

the site's better-auth session + an admin allowlist.

Endpoints

| Route | Auth | Purpose |

|---|---|---|

| GET/POST /api/gamify/state | Bearer apiKey | load / upsert a student's xp·level·badges·unlocks·credited completion count (monotonic merge) |

| GET /api/gamify/leaderboard | Bearer apiKey | top-N by XP for a product |

| POST /api/gamify/webhook/kajabi?buyer=<id> | HMAC sig | quiz pass → unlock gated step |

| GET /api/gamify/analytics | session + admin | aggregate stats + event counts |

Provision (one-time)

GamifyKit reuses the site's existing D1 database (binding DB, wize-school-db) — no new

database to create. Just apply the gamify tables (prefixed gamify_):

npx wrangler d1 execute wize-school-db --remote --file=src/lib/gamify/schema.sql
# seed a buyer:
npx wrangler d1 execute wize-school-db --remote --command \
 "INSERT INTO gamify_buyer (id, api_key, plan, kajabi_site, webhook_secret, created_at) \
  VALUES ('wize', 'gk_live_xxx', 'pro', 'wize.school', 'whsec_xxx', strftime('%s','now')*1000)"

Set GAMIFY_ADMIN_EMAILS (comma-separated) for dashboard access.

For an existing install created before GamifyKit 1.0.0, also apply:

npx wrangler d1 execute wize-school-db --remote --file=src/lib/gamify/migrations/002_credited_completed.sql

Buyer setup (in Kajabi theme settings)

1. Settings → Gamification → Mode = Pro.

2. Paste Pro API base URL (https://www.wize.school) and Pro API key.

3. (Quiz gating) Add a Kajabi automation on quiz pass → webhook to

…/api/gamify/webhook/kajabi?buyer=<id> signed with the buyer's secret.

Production verification

  • studentKey: the theme prefers current_site_user.id, then email, then an anonymous

browser key. For Pro customers, verify a logged-in member resolves the same key in two

browsers before promising cross-device sync for that site.

  • Quiz webhook: the handler accepts common Kajabi automation payload shapes plus signed

HMAC requests. Capture one live quiz-pass webhook during onboarding and map any custom

field names before enabling quiz-gated paths.