Web SDK
A preview JavaScript package for reading a member's streak. Not yet on npm.
Preview, not yet on npm. @streakdev/web isn't published, so installing it fails today. This page describes the preview API so you can plan for it.
What works today
- Show progress with the widget script. It needs no build step. See Integrations overview.
- Count actions from your platform or server: the WordPress plugin, the incoming URL for course platforms, or the webhook for your own backend.
- Read a member's streak from any language with
GET /v1/state.
What the package will do
The Web SDK reads progress for your own UI. It doesn't count actions. Counting stays on your server.
createClient(options)
import { createClient } from "@streakdev/web";
const client = createClient({ baseUrl: "https://api.streakfox.com" });| Option | What it does |
|---|---|
baseUrl | API endpoint. Defaults to https://api.streakfox.com. |
aliasToken | Short-lived signed identity token. Needed before reward values are revealed. |
adminToken | Server only. Required for aliasUser(). Never ship it to a browser. |
headers | Extra request headers. |
client.getState(input)
Fetches a member's progress for one action.
const state = await client.getState({
projectId: "YOUR_PROJECT_KEY",
event: "YOUR_ACTION",
userHash: "MEMBER_ID",
});
state.streak.current; // current streak or running total
state.streak.best; // best ever
state.week; // the last 7 daysprojectId takes your project key. event takes your action. userHash is the member ID you count with.
client.aliasUserWithToken(input)
Links the browser's anonymous visitor to a signed-in member, using a short-lived token your server creates. See Connecting users.
await client.aliasUserWithToken({ projectId: "YOUR_PROJECT_KEY", token: tokenFromYourServer });Repeating the same link is safe. Linking that visitor to a different member returns 409 ALIAS_IDENTITY_CONFLICT.
client.aliasUser(input)
The server-side version. It needs adminToken, so call it only from your server.
await client.aliasUser({
projectId: "YOUR_PROJECT_KEY",
anonymousId: "anon_visitor_id",
userHash: "MEMBER_ID",
});