Black Friday: Sumly for life, one payment from $79 · until 1 Declifetime from $79 →

Feature flags and experiments

Turn a feature on for some people, test two versions of a page or a paywall, and see which one brings more money. Sumly works out each person's value on its server, and counts each variant's paying customers and revenue from the payments it already ties to your visitors and app users.

Quick start

  1. 1

    In Visitors › Flags, make a flag: a name, who gets it, and whether it is on or off or has variants. Its key, such as new-checkout, is what your code reads.

  2. 2

    Read it where the feature is, with a fallback for the moment before the first answer.

  3. 3

    Something wrong? Turn off for everyone on the flag. Sites get it on the next page, apps when they come back to the front or within 5 minutes.

Read a flag

On a site, after the Sumly script tag:

sumly.flagsReady().then(() => {
  if (sumly.isEnabled('new-checkout')) {
    document.body.classList.add('new-checkout');
  }
  const plan = sumly.getVariant('paywall', 'monthly');
});

Or with the typed package in a bundled site:

import { sumly } from '@sumly/sdk/web';

sumly.init({ siteKey: 'sl_your_key' });
await sumly.flagsReady();
const on = sumly.isEnabled('new-checkout');

In React Native or Expo, the hooks render again when a value changes:

import { Text } from 'react-native';
import { Sumly } from '@sumly/sdk/react-native';
import { useFlag, useVariant } from '@sumly/sdk/react-native';

export function Checkout() {
  const fast = useFlag('new-checkout', false);
  const plan = useVariant('paywall', 'monthly');
  return {fast ? 'One step' : 'Three steps'} · {plan};
}

// Outside a component:
if (Sumly.isEnabled('new-checkout')) {
  // …
}

On iOS with Sumly.swift:

if Sumly.isEnabled("new-checkout") {
    showNewCheckout()
}
let plan = Sumly.getVariant("paywall", default: "monthly")

On Android with Sumly.kt:

if (Sumly.isEnabled("new-checkout")) {
    showNewCheckout()
}
val plan = Sumly.getVariant("paywall", "monthly")

On your server, with the secret key:

import { Sumly } from '@sumly/sdk/server';

const sumly = new Sumly({ key: process.env.SUMLY_KEY! });
const on = await sumly.isEnabled('u_1842', 'new-checkout');
const all = await sumly.flags('u_1842', { properties: { plan: 'pro' }, country: 'SI' });

Each SDK also has getFlag (the raw value), getFlagPayload (the JSON a flag or variant carries), getFlagDetail (the value, why, and whether it came from the server, the device's cache, a bootstrap or the fallback), onFlags and reloadFlags.

Who gets it

A flag has one or more groups of people, tried in order. The first group whose conditions a person matches, and whose share takes them in, decides. A group with no conditions is everyone.

  • Conditions look at the country (from the request), the platform (web, iOS, Android), the app version (compared as versions, so 1.10 is above 1.9), a list of user ids, the e-mail, any property you give, or a property of the person's company.
  • A share lets a group in a part at a time: 5%, then 25%, then everyone.
  • With variants, each person falls in one by the shares you set, or a group can always get one, such as your team always on the new version.
  • By company: set Same value for everyone in to company and send Sumly.group('company', 'acme'); everyone in Acme then gets the same value.

Properties to target by come with identify:

import { Sumly } from '@sumly/sdk/react-native';

Sumly.identify('u_1842', { properties: { plan: 'pro', language: 'sl' } });

On a site, sumly.identify({ id: 'u_1842' }, { properties: { plan: 'pro' } }) does the same, and so does identify from your server with traits.properties. Only what you give as properties is kept for flags.

Experiments

Give a flag with variants a goal and start it: the goal can be an event (signup), a page (/thanks), signing up (the first identify after seeing the flag) or paying. The first variant is the control.

From the first time a person's app or site uses the value, Sumly counts them under that variant. The results show, per variant: people, how many reached the goal, the rate, how many paid, the revenue and the revenue per person, each against the control. A variant that brings fewer sign-ups but more money shows it.

  • Too early until each variant has 150 people and the test 3 days, with 20 conversions (30 paying people for a payment goal).
  • Better or worse only when the whole range is above or below the control. The ranges stay honest however often you look, so checking every day does not turn luck into a winner.
  • Chance it's better says how likely a variant beats the control, in plain numbers.
  • The split is off when the people in each variant are far from the shares you set: usually a page or app reads the flag in some places and not others. No call is made until that is fixed.
  • One very large order is capped so it cannot decide a test alone, and a lift above 50% is marked as worth a second look.
  • People who saw two variants (on two devices before signing in) are left out.

Ship this on a variant gives it to everyone the flag reaches and ends the experiment; its results stay as they were. Remove the flag from your code later, then delete it.

Holdout: under the project's flag settings, keep up to 20% of people out of every experiment. They get each control and show as Holdout in the results, so you see what all your tests together changed.

Signed user ids

The public key is in your app, so anyone could ask for the flags of any user id. If a flag names people, turn on Only trust user ids signed by your server in the project's flag settings. Your server signs the user id with the signing secret shown there and the app passes the signature along:

import { Sumly } from '@sumly/sdk/server';

// On your server, when the person signs in:
const hash = Sumly.signUserId('u_1842', process.env.SUMLY_FLAG_SECRET!);
// Send hash to the app with the session; there: Sumly.identify('u_1842', { hash })

Speed, cache and the first page

One request brings all of a person's flags. The SDKs keep the last answers for the last five people on a device and ask again at start, after identify, when the app comes back to the front, and every 5 minutes while it is open. When Sumly cannot be reached they wait longer each time, up to 30 minutes. A site keeps answers in the browser only where its visitor allowed the cookie.

An app that promises only its own user id leaves the phone sets flagsSignedInOnly: true in Sumly.init: nothing is asked before identify, and the install id never goes with flags.

To have the right value on the very first paint, decide the flags on your server with @sumly/sdk/server and put them in the page before the script tag: window.sumlyFlags = {"new-checkout": true}. The script uses them until its own answer comes. data-flags="off" on the script tag stops it asking at all.

Behind your own domain, pass /sumly/f through the way you pass /sumly/e; until you do, the script asks sumly.dev itself.

Plans

Free: 3 flags and 1 experiment running at once. Starter: 20 flags and 3 experiments at once. Growth and the lifetime deal: no limit. Holdouts, company flags and signed user ids are on every plan.

Moving from PostHog

The calls line up one to one, and the hash is the same, so keeping a flag's key and rollout keeps the same people in.

PostHogSumly
isFeatureEnabled(key)isEnabled(key, fallback)
getFeatureFlag(key)getFlag(key, fallback) or getVariant(key, fallback)
getFeatureFlagPayload(key)getFlagPayload(key)
onFeatureFlags(cb)onFlags(cb)
reloadFeatureFlags()reloadFlags()
useFeatureFlagEnabled / useFeatureFlagVariantKeyuseFlag / useVariant
group(type, key, props)group(type, key, props)
person propertiesidentify(id, { properties })
$feature_flag_called$flag_seen, sent by the SDKs
bootstrap.featureFlagswindow.sumlyFlags or bootstrapFlags

Make each flag in Visitors › Flags with the same key, groups and shares, or ask your assistant to do it over MCP with save_flag. Then swap the calls and remove PostHog's flags.

The API

POST /api/v1/flags with the public or the secret key returns every flag of one person. It is in the API reference and the OpenAPI file.

Questions

Where are the rules worked out?

On Sumly's server. An app or a page asks once and gets back only the values for that one person, never the rules, the user ids in them or the shares. A flag marked server only never reaches the public key at all.

What happens before the first answer, or offline?

Every call takes a fallback, and that is what it returns until the first answer. The SDKs keep the last answer on the device, so an app opened offline gets the values it had. A deleted flag gives the fallback too.

Does a person keep their value?

Yes. The value comes from a hash of the flag's key and the person, so the same person gets the same value on every call and every device. Once they sign in, their user id decides, so the web and the app agree. Raising a rollout from 10% to 30% keeps the first 10% in.

Does a person keep their variant in an experiment?

Yes, from the first time they see it. Sumly keeps that variant for them on its server, also after they sign in and when you change the shares halfway.

Do flags count toward my visits?

No. Asking for flags and the $flag_seen events are not visits.

Can I use them on my server?

Yes: @sumly/sdk/server with the secret key reads every flag, also the server-only ones, and may say where the person is.

Is it the same hash as PostHog?

Yes: sha1 of the key, a dot and the id. Keep a flag's key and its rollout and the same people stay in when you move over.

Page names first, then what the pages say