> ## Documentation Index
> Fetch the complete documentation index at: https://docs.newly.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Feature flags for your app

> Turn a feature in your app on or off, or roll it out to some of your users, without a new build or store review.

A feature flag is a switch your app reads while it runs. You put a feature behind a flag, ship your app, and then turn the feature on, off, or on for some of your users from Newly. Your live app follows the next time it opens or comes back to the foreground, with no new build and no App Store or Google Play review.

Use a flag to:

* **Switch something off fast.** Something broke after a release? Turn its flag off and each user stops getting it as soon as their app opens or comes back to the foreground.
* **Roll out step by step.** Start a new feature at 10% of your users and raise it as the numbers hold up.
* **Give early access.** Turn a feature on only for your team, your testers, or customers you choose by email.
* **Change a value without a build.** Send a price, a piece of copy or a limit with the flag, and change it from Newly.

Flags live in **Marketing & analytics**, under **Release**, then **Feature flags**. You can also manage them by asking the agent in your chat, or with the `newly flags` command in your terminal. All three change the same flags, and each change is kept in the flag's history.

## Add flags to your app

**1. Ask the agent**

Open **Feature flags** and select **Add to my app**, or ask in the chat: *Add feature flags to my app*. The agent asks which feature to put behind a flag, adds flag support to your app, puts the feature behind the flag, and creates the flag, **off**.

**2. Check the flag**

The new flag appears in **Feature flags**, under **Development**. Its history shows **Agent** as who created it.

**3. Try it in your preview**

Turn the flag on in **Development**. Leave your app's preview and come back to it (or reopen it), and it shows the feature. Turn it off and the feature goes away.

**4. Go live**

When you're ready for real users, create the same flag in **Production** and turn it on there, for everyone or for a group first. See [Who gets it](#who-gets-it).

> [!NOTE]
>
> A flag that your app has never heard from (for example, the very first launch with no internet) counts as **off**. That's why the agent always keeps the old behaviour working behind the flag.

## Development and Production

Every flag exists separately in **Development** and **Production**, each with its own app key. Your app picks the right one by itself:

| Your app runs as | Reads |
| - | - |
| Your preview in Newly, or any development build | **Development** flags |
| TestFlight, the App Store, Google Play, an APK you download, an internal test build | **Production** flags |

So you can try a flag in your preview without touching what your users get. Never copy a key into your code or switch environments by hand. The app chooses for you.

### App keys

The strip at the top of **Feature flags** shows the app key for the environment you're looking at. Your app reads its flags with this key. It is public by design, like a publishable payment key: it can only read this app's flags, never change them.

* **Copy** copies the key.
* **Create key** appears only when the environment has no key yet.
* **Rotate** replaces the key. Builds that still carry the old key stop reading flags and fall back to each flag's default (off) until you ship a build with the new key. Only rotate a key if you need to.

## The flag list

Each row shows:

* the flag's **key** (its name in your code) and description;
* **who gets it**, for example *Staff + 25% of everyone*, or *No one (off)*;
* who changed it last (**In Newly**, **Agent** or **CLI**) and when; select it to open the history;
* the **on/off switch**. It saves at once.

Select a flag to edit it.

## Who gets it

A flag is **on** for a user when it's switched on **and** at least one of its **groups** matches that user.

* A **group** has a name, filters, and a **Roll out to** percentage.
* **Any one group** is enough. Groups are joined by **OR**.
* **Every filter** in a group must match. Filters are joined by **AND**.
* **Any one value** in a filter is enough. A filter can hold several values, shown as chips joined by **or**. **Is not** works the other way: the user must match **none** of its values, so `User ID is not a, b` leaves out both.
* A group with **no filters** is everyone.
* A new flag starts with one group, **Everyone** at 100%.

A filter compares one thing about the user:

| Filter on | What it is |
| - | - |
| **User ID** | The signed-in user's ID in your app, or the device's own ID when nobody is signed in |
| **Email** | The signed-in user's email |
| **Other** | Any property your app sends, such as `plan`, `platform` or `country` |

With one of: **is**, **is not**, **contains**, **starts with**, **ends with**. Capital letters don't matter. A filter only matches users who send that information, so **is not** never matches a user who has no email or property at all.

### Examples

| You want | Set up |
| - | - |
| Only your team | Group **Staff**: Email **ends with** `@yourcompany.com` (add more domains as more values in the same filter), roll out 100% |
| Your team, plus 10% of everyone else | Group **Staff** as above, **OR** group **Everyone** with no filters at 10% |
| Pro users on iPhone | Group: `plan` **is** `pro` **AND** `platform` **is** `ios` |
| Everyone except one tester | Group: User ID **is not** `the-tester-id` |

> [!WARNING]
>
> To match **either** of two emails or domains, put both values in **one** filter: type one, press Enter, type the next. Two separate filters on Email must **both** match, so a group with "Email ends with @a.com" AND "Email ends with @b.com" matches no one. The editor warns you when this happens and offers **Merge into one filter**.

### Roll out to

Each group has its own **Roll out to** percentage. Every user always lands in the same spot for a flag, so they don't flip between on and off. Raising the percentage only adds users: nobody who already has the feature loses it.

### Value sent with it

You can attach a short text value (up to 4 KB) to a flag, such as `{"button": "Pay with Apple Pay"}`. Your app gets it only while the flag is on for that user. Use it for copy, prices or limits you want to change without a build.

## History

Every change to a flag is kept: who made it (**In Newly**, **Agent** or **CLI**), when, and what changed (turned on or off, who gets it, the value, the description). History is kept even after a flag is deleted.

## Use the agent

The agent can do everything the Feature flags tab does. Ask it in the chat, for example:

* *Put the new onboarding behind a flag.*
* *Turn on new-checkout for our team only.*
* *Roll dark-mode out to 25% of users in production.*
* *Turn off holiday-banner everywhere.*
* *Who changed new-checkout last?*

The agent works in **Development** unless you ask for Production. Before it changes a production flag, it tells you what changes and for whom.

## Use the CLI

The `newly flags` commands work from your app's folder. Every command works on **Development** unless you add `--env prod`, so you never change what your users get by accident.

| Command | Does |
| - | - |
| `newly flags init` | Creates the app's keys if missing and adds flag support to your app |
| `newly flags ls` | Lists flags, on or off, and who gets each |
| `newly flags show <key>` | Shows one flag's groups, filters and value |
| `newly flags on <key>` / `off <key>` | Turns a flag on or off |
| `newly flags create <key>` | Creates a flag, off unless you add `--on` |
| `newly flags set <key>` | Changes a flag; only what you pass changes |
| `newly flags delete <key>` | Deletes a flag (add `--yes` for Production) |
| `newly flags log <key>` | Shows the flag's history |
| `newly flags usage` | Shows this month's reads and what was charged |
| `newly flags keys` | Shows the app keys; `keys rotate --env prod --yes` replaces one |

Set who gets a flag with `--group` (you can repeat it) and `--rollout`:

```bash theme={null}
# Your team, plus 25% of everyone else, in Production
newly flags set new-checkout --env prod \
  --group "Staff:100:email ends_with @yourcompany.com,@yourcompany.io" \
  --rollout 25

# Pro users on iPhone, at half of them
newly flags set paywall-v2 --group "Pro on iOS:50:plan is pro and platform is ios"
```

A group is written as `name:rollout:filters`. Filters are joined with `and`, and values with commas. `--rollout 25` adds an **Everyone** group at 25%.

## Pricing

Each app gets **1,000,000 flag reads free every month**, counted from the 1st, UTC. Reads from Development and Production builds count together. Past the free million, reads cost **20 credits per million reads**.

* **One read** is your app asking for its flags: when it opens, and when it comes back to the foreground, at most once a minute. One read covers every flag at once.
* An app with 10,000 people using it daily, each opening it or coming back to it about six times a day, makes roughly 1.8 million reads a month, so about 16 credits past the free million.
* Reads are charged every hour, a little after the hour ends.
* **Flags keep working when you run out of credits.** Your app is never cut off. Add credits to keep your balance positive.

Where to see it:

* **Account, Usage**: **Feature flag reads this month** lists each app's reads against its free million. Charges show under **By area** as **Feature flags**.
* **Feature flags**: the strip above your flags shows this app's reads this month.
* **Reserved credits**: you can reserve credits for **Feature flags**. Like Backend, a reserve here only warns you by email at 90% and 100%. It never stops your flags.

## Troubleshooting

> [accordion] I don't see Feature flags in Marketing & analytics
>
> Feature flags is rolling out, and the tab only appears on accounts that have it. Open a cloud project, then **Marketing & analytics**, **Release**, **Feature flags**.

> [accordion] I turned a flag on but my app didn't change
>
> * Leave the app and come back to it, or reopen it. Apps refresh their flags when they open and when they return to the foreground, at most once a minute.
> * Check the environment. Your preview and development builds read **Development**; TestFlight, App Store, Google Play and downloaded APKs read **Production**. A flag turned on only in Development won't show in a TestFlight build.
> * Check **who gets it**. A group with filters only matches users who send that information. Email filters match only signed-in users; a User ID filter matches the device's own ID when nobody is signed in.
> * Check that the app reads the same key as the flag (open the flag; its key is the name in your code).

> [accordion] My group matches no one
>
> Two filters on the same thing (for example two Email filters) must **both** match. To match either value, put both values in one filter. The editor shows **Merge into one filter** when it spots this.

> [accordion] Some users get the feature and others don't
>
> That's the **Roll out to** percentage doing its job. Each user always gets the same answer. Set it to 100% for everyone in that group.

> [accordion] My app stopped reading flags after I rotated the key
>
> Builds with the old key fall back to each flag's default (off) until they ship with the new key. Run `newly flags init` (or ask the agent to update the flag keys) and ship a new build.

> [accordion] I was charged for feature flag reads
>
> Each app gets a million reads free each month, counting Development and Production together. Past that, reads cost 20 credits per million. **Account, Usage**, **Feature flag reads this month** shows each app's reads. Reads come from app launches and returns to the app, so an app with many daily users reads more.

> [accordion] Can I use a flag to hide something secret or paid?
>
> No. A flag decides what your app shows, but the user's email and properties come from the app itself, so it isn't a security check. Protect paid features and private data on your server.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.