Skip to content
Peekbird

Feature flags

A feature flag turns a feature on for some of your visitors: a share of them, an audience, or everyone. Your code asks whether it's on, in the page or on your server, and switching it off takes effect within a minute, with no deploy.

Make a flag

  1. Under your site's A/B testing, open Feature flags and choose New flag.
  2. Name it. Its key is what your code asks for, such as new-search; it's made from the name unless you type one.
  3. Choose the Rollout (%): the share of matching visitors it's on for. 100% is everyone.
  4. Optionally, choose audiences: it's then on only for visitors in them (any or all, as you choose), and the rollout is a share of those.
  5. Switch it On. A flag that's off is off for everyone, whatever its rollout.

The flags list switches each one on or off in one click: the kill switch, if a feature misbehaves.

Use it in your code

window.peekbird = window.peekbird || [];
peekbird.push(['flag', 'new-search', function (on) {
  if (on) {
    // The new feature.
  }
}]);
  • In the page, the callback runs once Peekbird has run, with true or false. Ask from anywhere, before or after the snippet loads.
  • On a server, the SDKs answer at once, from the flags they downloaded: see Server-side SDKs.
  • A flag that doesn't exist, or was deleted, is off. So is every flag before the visitor agrees to cookies, where your site waits for consent.

Once the snippet has run, the page can also ask without a callback:

// Once the snippet has run: true or false at once.
if (window.peekbird.flag && peekbird.flag('new-search')) {
  // The new feature.
}

Who gets it

  • Each visitor is in or out by a hash of their visitor ID and the flag's own seed, so the answer stays the same on every page and visit, and the page and your server agree.
  • Raising the rollout only adds visitors: everyone it was already on for stays on. Lowering it turns it off for some of them.
  • Audiences are checked each time your code asks, so a visitor who joins one gets the flag from then on.
  • On a server, audiences work with what the server knows: see Server-side SDKs.

When changes arrive

  • Pages: within about a minute, as your snippet's file refreshes (see Speed, CSP and single-page apps).
  • Servers: within about 30 seconds, as the SDKs check for changes.

See how it's going

Each time a page asks for a flag, Peekbird notes the answer the visit got, on or off, once a visit. So while you roll a feature out, you can look at the visits that had it apart from the rest:

  • Visits with it on and Visits with it off, under each flag, open their recordings.
  • The Feature flag filter (under Experiments) finds them in Recordings, Analytics, Heatmaps and Funnels: "was on" or "was off".
  • A funnel's Compare → Feature flag puts visits with it on beside those with it off, step by step (see Funnels).
  • A heatmap's Visits menu shows where those with it on click, against those with it off.

"Off" means the flag is switched on, but the visit wasn't in its rollout or audience: the 90% beside a 10% rollout. A flag that's switched off for everyone isn't on your pages at all, so nothing is noted then. Answers given on your server, by an SDK or the decide API, are noted too.

Flags and tests

A flag turns something on; it doesn't measure it. To learn whether the feature helps, test it: an "In your code" experiment splits visitors between the old and the new, and its results count your goals for each (see Experiments). A common path: test it, ship the winner behind a flag at 100%, then remove the flag from your code.

Flags that are on are part of your site's public snippet file (their keys and rollouts, never their names or descriptions), like experiments. Flags that are off aren't in it at all.

See what your visitors see.

Start free in a few minutes: one snippet, every feature. Move to a bigger plan when you need more tracked visits.