Skip to content
Open Screeb

Load Screeb for a stable share of your users to spread a monthly user quota over the month.

A large consumer app can use up its Screeb user quota in a few days: once it is reached, only the users already tracked this month can be surveyed. To spread the quota over the whole month, load Screeb for a stable share of your users only.

This function keeps Screeb for every user in Japan and for one user in ten elsewhere. A hash of the user ID decides, so a given user always gets the same answer.

function isScreebEnabledForUser(userId: string, country: string): boolean {
if (country === "ja") {
return true;
}
return cyrb53Hash(userId, 42) % 10 === 0;
}
// cyrb53, a fast 53-bit string hash: https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
function cyrb53Hash(str: string, seed: number): number {
let h1 = 0xdeadbeef ^ seed;
let h2 = 0x41c6ce57 ^ seed;
for (let i = 0; i < str.length; i++) {
const ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}

Check the user before each Screeb command, starting with init:

if (isScreebEnabledForUser("<USER-ID>", "us")) {
$screeb("init", "<YOUR-CHANNEL-ID>", { identity: { id: "<USER-ID>" } });
}
if (isScreebEnabledForUser("<USER-ID>", "us")) {
$screeb("event.track", "plan_upgraded", { plan: "pro" });
}
if (isScreebEnabledForUser("<USER-ID>", "us")) {
$screeb("identity.group.assign", "company", "Acme Inc");
}

To survey other users next month, derive the seed from the month instead of a constant: cyrb53Hash(userId, new Date().getMonth()).