> For the complete documentation index, see [llms.txt](https://docs.amply.tools/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.amply.tools/developer-guide/built-in-campaigns.md).

# Built-in campaigns

Ship campaigns inside your app build, so the app shows them on its very first launch, even with no internet.

*Amply SDK 0.16.0+ (iOS, Android and React Native).*

A campaign marked **Built-in** in Amply ships inside your app build. Your app can show it on its very first launch, before it has ever reached Amply and even with no internet. Mini-app screens and their images are included.

You add no code and no secret. After a one-time setup for iOS or Expo, you run one command, commit the files it writes, and build.

**Use this when** a campaign must be there from the first second: an onboarding flow, a first-launch paywall, a consent or terms screen. **You can skip it** for campaigns that can wait until the app has been online once. Every other campaign reaches the app as usual.

## The three steps

{% stepper %}
{% step %}

### Turn on Built-in

In Amply, open the campaign and turn on **Built-in**. It is on the campaign's first step, under the campaign type. See [Built-in](https://docs.amply.tools/user-guide/campaigns.md#built-in) in the user guide.

Only **active** campaigns are bundled, so start the campaign too.
{% endstep %}

{% step %}

### Run the bundle command

In your app project's root folder, run:

```bash
npx @amplytools/cli bundle --android <android-public-key> --ios <ios-public-key>
```

Use the **public** API key of each application (the same `apiKeyPublic` you pass to the SDK). Pass only the platforms you ship. The command never needs a secret key.

It downloads your built-in campaigns with every screen and image they use, checks every file, and writes the bundle file for each platform. Where it goes depends on your project; see [Where the file goes](#where-the-file-goes). The first run also saves your keys and paths in `amply.json`, so from then on you only run:

```bash
npx @amplytools/cli bundle
```

Requires Node.js 18 or newer.
{% endstep %}

{% step %}

### Commit and build

Commit the bundle file(s) and `amply.json`. Your next build carries the campaigns.

**On iOS, add the file to your app target once.** See the iOS tab below. **On Expo, add the Amply config plugin once.** See the Expo tab. Android needs nothing extra.
{% endstep %}
{% endstepper %}

## Where the file goes

{% tabs %}
{% tab title="Android" %}
The command writes `app/src/main/assets/amply-bundle.json`. Android packages everything under `assets/` automatically.

If the command can't find your app module, or finds several, choose the folder yourself:

```bash
npx @amplytools/cli bundle --android <android-public-key> --out-android myapp/src/main/assets
```

{% endtab %}

{% tab title="iOS" %}
The command writes `amply-bundle.json` into your app's folder, the one that holds the app target's `Info.plist`.

**Add it to your app target once:**

1. Open the project in Xcode.
2. Drag `amply-bundle.json` from Finder into your app's folder in the Project navigator.
3. In the dialog, tick your app target under **Add to targets**.

The file is then listed under your target's **Build Phases → Copy Bundle Resources**. Later runs of the command only replace its contents, so you do this once. Until you do, the command reminds you on every run. It reads your Xcode project to check, and never changes it.

If your app folder is a synchronized folder (the default for projects created in Xcode 16 or later), every file in it is already part of the target, and there is nothing to do.

If the command can't find your app folder, or you have several app targets, choose the place yourself with `--out-ios <path>`.
{% endtab %}

{% tab title="React Native" %}
The command writes two files:

* `android/app/src/main/assets/amply-bundle.json`
* `ios/<YourApp>/amply-bundle.json`

On iOS, add the file to your app target once in Xcode, exactly as in the iOS tab. Android needs nothing extra.

This also applies to an Expo project that keeps its `ios/` and `android/` folders in the repository.
{% endtab %}

{% tab title="Expo" %}
In a managed Expo project (no `ios/` and `android/` folders in git), the **Amply config plugin** puts the files into your build. Add it to `app.json`:

```json
{
  "expo": {
    "plugins": ["@amplytools/react-native-amply-sdk"]
  }
}
```

The command then writes two files to your project root, next to `app.json`:

* `amply-bundle.android.json`
* `amply-bundle.ios.json`

Commit both. When you run `npx expo prebuild`, or build with EAS (which runs prebuild for you), the plugin copies each file into the native project and adds the iOS one to the app target. There is no Xcode step.

{% hint style="info" %}
Older guides said to remove this plugin entry. For built-in campaigns it is required. In a project without bundle files it changes nothing, so keeping it is safe.
{% endhint %}
{% endtab %}
{% endtabs %}

The file must be named `amply-bundle.json` inside the app. The SDK looks for no other name and needs no setting.

## Keep the bundle up to date

A bundle is a snapshot taken when you ran the command. **Run it again before each release**, so the build carries what you have in Amply now.

If nothing changed in Amply, the command reports that the bundle is up to date and leaves your files exactly as they are. You get no diff to commit.

### Check it in CI

`--check` compares the committed bundle with what Amply has published now. It writes nothing, and fails with exit code `1` when the bundle is out of date. On iOS it also fails while the file is not part of your app target, or when your Xcode project can't be read to confirm that.

Pin the version in CI, so a build never runs a release of the command you haven't reviewed:

```bash
npx @amplytools/cli@1.0.0 bundle --check
```

In GitHub Actions, for example:

```yaml
- uses: actions/setup-node@v4
  with:
    node-version: 20
- run: npx @amplytools/cli@1.0.0 bundle --check
```

Add `--json` for a machine-readable summary.

## What happens on the device

* **First launch, never online.** The app shows the built-in campaigns from the bundle, screens included. No network needed.
* **First successful download from Amply.** The live campaigns replace the bundle for good. From then on the app doesn't use the bundle again. Offline, it uses its saved copy of the live campaigns, as it always has. A failed or interrupted download changes nothing.
* **The version is frozen in the build.** Until a device first loads campaigns from Amply, it shows each built-in campaign as it was when you ran the command. Edits you make in Amply later, including stopping the campaign, reach that device with its first successful download.
* **Impressions and limits count the same** as for any campaign, and carry over when the live campaigns arrive. A user who saw the onboarding from the bundle doesn't see it again because of a "once per device" limit.
* **The bundle belongs to one key.** A device ignores a bundle made for another public key. A development bundle never shows in a production build. It also means a build that uses your development key doesn't show a bundle made with your production key.
* **A damaged bundle is ignored as a whole.** The SDK logs one warning and starts as if there were no bundle. It never crashes the app or delays the SDK.
* **Older SDK versions ignore the file.** Shipping it with an app on an earlier SDK does no harm.

The one exception: in an emergency, Amply support can switch an app back to the campaigns in its bundle.

## What gets bundled

A campaign is in the bundle when it is **Built-in** and **active**, and is **not running an A/B test**. A stopped or draft campaign is left out, even with Built-in on.

The whole file can be up to **20 MB**. If your campaigns' screens would go over that, the command stops and writes nothing. Bundle fewer campaigns or use lighter images.

## Check that it works

1. Delete the app from your test device or simulator, so it has never been online with Amply.
2. Install the new build and turn on airplane mode.
3. Launch the app and do whatever triggers the campaign.

The campaign shows. If your app listens to system events, `ConfigFetchFinished` reports `configSource: "bundle"` and the bundle's `bundleGeneratedAt`. See [Events](https://docs.amply.tools/reference/events.md#configfetchfinished).

If nothing shows:

* Check that the campaign was active and Built-in when you ran the command, and that you ran it for this platform's key.
* On iOS, check that `amply-bundle.json` is under your target's **Copy Bundle Resources**.
* Check that the build uses the same public key the bundle was made with.
* Make sure the app has never downloaded campaigns from Amply. Once it has, it uses the live campaigns instead.

## If the command fails

Nothing is written until every file for every platform has been downloaded and checked, so a download or check failure leaves your existing bundle files untouched. Each file is then replaced in one step, never left half-written.

| Exit code | Meaning                                                                               | What to do                                                                                                                                     |
| --------- | ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `0`       | Done. With `--check`: up to date.                                                     | Commit the files.                                                                                                                              |
| `1`       | `--check` found a difference.                                                         | Run `npx @amplytools/cli bundle` and commit the result. If the message is about Xcode, add the file to your app target.                        |
| `2`       | A wrong option, an unreadable `amply.json`, or a path that can't be found or written. | Read the message. If your app folder wasn't found, pass `--out-android` or `--out-ios`.                                                        |
| `3`       | Network error: no connection, a timeout, or an error from the server.                 | Check your connection and run it again.                                                                                                        |
| `4`       | The downloaded content didn't pass its checks, or the bundle would be over 20 MB.     | Run it again. If it keeps happening, contact Amply support with the message. For the size limit, bundle fewer campaigns or use lighter images. |
| `5`       | Nothing is published for this key yet.                                                | Check that you used the public key of the right application. If you did, save any campaign of the app in Amply and run it again.               |
| `70`      | A bug in the command itself.                                                          | Contact Amply support with the message.                                                                                                        |

## With an AI assistant

If your assistant is connected to Amply over [MCP](https://docs.amply.tools/reference/mcp-tools.md), it can mark a campaign as built-in when it creates or edits it. It can also tell you what the next bundle will hold for an application, which built-in campaigns are missing from it and why, and the exact command to run.

## Related

* [Campaigns → Built-in](https://docs.amply.tools/user-guide/campaigns.md#built-in) — the switch in the campaign form
* [Installation](https://docs.amply.tools/developer-guide/installation.md) — adding the SDK and the Expo plugin
* [Events](https://docs.amply.tools/reference/events.md#configfetchfinished) — where the app's campaigns came from
* [Campaign delivery](https://docs.amply.tools/concepts/campaign-delivery.md) — how the app gets its campaigns
* [Changelog](https://docs.amply.tools/changelog.md) — the release that added built-in campaigns
