<!-- KeepSnappy docs for keepsnappy CLI 0.1.0-alpha.35 -->

# The measuring build

> What the SDK puts in your app's build, its options and build variables, how to make a Release build, and how to check that a store build carries none of it.

This page is for whoever owns your app's build. It says what the SDK changes in a [measuring build](https://keepsnappy.com/docs/glossary.md#measuring-build), which variables turn it on, and how to check that a store build carries none of it.

`keepsnappy init` makes these changes for you ([Getting started](https://keepsnappy.com/docs/getting-started.md#1-set-up-your-app)). For an app with its own `ios/` and `android/` folders that never runs `expo prebuild`, see [Bare React Native](https://keepsnappy.com/docs/bare-react-native.md).

## What the SDK does

The SDK is `@keepsnappy/react-native`. It measures from inside your app: taps, screens and React render times. You add no app code.

A build carries the SDK only when [`KEEPSNAPPY=1`](https://keepsnappy.com/docs/glossary.md#keepsnappy1) is set while it is built. This page calls it the build switch. Your store builds leave it unset, so they carry none of the SDK ([Store builds](#store-builds)).

<span id="versions-that-work-together"></span><span id="install-and-build-by-hand"></span><span id="the-command-line-tool"></span><span id="two-config-changes"></span><span id="wrap-your-metro-config"></span><span id="add-the-config-plugin"></span>When init leaves a step to you, [Install by hand](https://keepsnappy.com/docs/install.md) has the versions, the install commands and the config changes.

## Plugin options

| Option | Default | Effect |
|---|---|---|
| `measureFromLaunch` | `true` | Measures from launch. |
| `renderTimes` | `true` | Records render times per component, with React's profiling renderer. |
| `waitForActivation` | `false` | Measures nothing until `keepsnappy run` [activates](https://keepsnappy.com/docs/glossary.md#activation) the app, from its next launch. Wins over `measureFromLaunch`. |
| `tapText` | `true` | `false`: never reads text on screen to name a tap. |

Leave `renderTimes` on. Render times are the main measure a result is judged on ([How a result is decided](https://keepsnappy.com/docs/results.md)).

`waitForActivation` lets one build also serve your other test jobs. `keepsnappy run` activates such a build on Android. On an iOS simulator it does so when `keepsnappy.yml` sets `app.wait_for_activation` to `true`, and it switches the activation off after the last run. It can't activate the build on an iPhone on a cable, so use a build without this option there.

A tapped element with no test id and no accessibility label is named by its text on screen. Use test accounts and test data, or set `tapText` to `false`.

An option the SDK doesn't know fails the build. Keys go in build variables, never in the options.

## The build switch

The SDK reads these variables when the app is built. Set each one the same way for `expo prebuild` and for the build.

| Variable | Value | Effect |
|---|---|---|
| `KEEPSNAPPY` | `1` | Puts the SDK into the build. Any other value, or none, leaves it out, whatever the options say. |
| `EXPO_PUBLIC_KEEPSNAPPY_KEY`, `EXPO_PUBLIC_KEEPSNAPPY_INGEST_URL` | from **Setup** | Only for a build whose app sends its own measurements. See below. |
| `KEEPSNAPPY_METRO_GRAPH` | `0` | Stops saving the Metro dependency graph ([Your data](https://keepsnappy.com/docs/data.md#the-metro-dependency-graph)). |

<!-- key-usage:start -->
The SDK key can only send measurements; it is built into the app, so treat it as public. A build whose app sends the measurements itself needs `EXPO_PUBLIC_KEEPSNAPPY_KEY` and `EXPO_PUBLIC_KEEPSNAPPY_INGEST_URL`: Android, BrowserStack and every run through the Appium driver or the `farm` command. Only `keepsnappy run --upload` on an iOS simulator or a cabled iPhone needs neither in the build: the CLI reads the data off the device.
<!-- key-usage:end -->

Route by route:

- iOS, on a simulator or an iPhone on a cable: `keepsnappy run --platform ios-sim --upload` reads the app's data from the simulator with `xcrun simctl` and uploads it with the CI key. `keepsnappy run --platform ios-device --upload` does the same on a cabled iPhone with `devicectl`. The build carries neither variable.
- Android, on an emulator or a phone on a cable: `keepsnappy run --platform android-emulator` (or `android-device`) has the app send its own measurements. The build must carry `EXPO_PUBLIC_KEEPSNAPPY_KEY` and `EXPO_PUBLIC_KEEPSNAPPY_INGEST_URL` ([Android](https://keepsnappy.com/docs/android.md#android-emulator)).
- Real phones on BrowserStack, iOS or Android: `farm open` starts the session, your test tool runs, and `farm close` ends it. The app sends its own measurements here too, so the build needs the same two variables ([BrowserStack](https://keepsnappy.com/docs/browserstack.md)).

Without them nothing arrives. `keepsnappy run` then prints `Session failed: no run sent any data. Check that the build carries the SDK and that the app reaches the API.` A BrowserStack session prints `No iteration sent any data`.

Metro reads the values when it bundles the app, and it caches what it bundled. After you change a variable or an option, clear the cache: `npx expo start --clear`.

### Older setups

Builds set up with older variables still build as before. `EXPO_PUBLIC_KEEPSNAPPY=1` works like `KEEPSNAPPY=1`. `EXPO_PUBLIC_KEEPSNAPPY_AUTO=1` stands for `measureFromLaunch`, and `EXPO_PUBLIC_KEEPSNAPPY_PROFILE=1` or `KEEPSNAPPY_REACT_PROFILING=1` for `renderTimes`. A variable you set wins over its option, and only over the part it covers.

## Make a Release build

A measuring build is a Release build with `KEEPSNAPPY=1`. If your app's `eas.json` profiles are all development-client builds, none of them makes one. Build Release by hand, on your machine or in CI, with the commands below. They don't use `eas.json`.

Run the same setup scripts your normal Release build needs, such as code generation or compiling translations. A KeepSnappy build still needs their output. If the build stops, look for the first error from those scripts or the compiler in the build log.

If you use an iPhone on a cable, follow [the iPhone build and install steps](https://keepsnappy.com/docs/on-your-mac.md#an-iphone-on-a-cable). Before uploading an iOS build to a device farm, check its signing instructions. Your build job needs access to its signing keychain and the provisioning profiles for the Release bundle ID and each extension it includes. Check app groups and push entitlements against those profiles. For a fork, use bundle IDs your signing team controls.

If the build waits for [activation](https://keepsnappy.com/docs/glossary.md#activation), check that your run route can activate it. The [SDK options](#plugin-options) explain how this works on Android and iOS, and [BrowserStack](https://keepsnappy.com/docs/browserstack.md#how-it-runs) shows where the run token is used on the farm.

iOS, on a simulator. Set `KEEPSNAPPY=1` in the shell that runs both commands:

```sh
export KEEPSNAPPY=1
npx expo prebuild --platform ios
npx expo run:ios --configuration Release --device "iPhone 16"
```

Android, on an emulator or a phone. The app sends its own measurements, so set the key and the address too, from **Setup**. Replace both quoted placeholders first:

```sh
export KEEPSNAPPY=1
export EXPO_PUBLIC_KEEPSNAPPY_KEY='<your SDK key>'
export EXPO_PUBLIC_KEEPSNAPPY_INGEST_URL='https://REPLACE_WITH_YOUR_API_HOST'
npx expo prebuild --platform android --no-install
cd android && ./gradlew assembleRelease
```

The APK is `android/app/build/outputs/apk/release/app-release.apk`. For an emulator on a Linux CI machine, add `-PreactNativeArchitectures=x86_64` to the `gradlew` command.

<span id="bare-react-native-no-expo"></span>An app that never runs `expo prebuild` builds another way: see [Bare React Native](https://keepsnappy.com/docs/bare-react-native.md).

## Store builds

Without `KEEPSNAPPY=1`, and without the older `EXPO_PUBLIC_KEEPSNAPPY=1`, Metro leaves your bundle unchanged. The config plugin also leaves the SDK's native module out of the iOS and Android projects. Run `expo prebuild` without either variable before a store build. Check your `.env` and EAS profiles for the older one.

To check a store build, count the SDK's marker in its JS bundle: `main.jsbundle` inside the `.app`, or `assets/index.android.bundle` in the unzipped APK. The count must be `0`. A Hermes bundle is binary, and `grep` prints nothing for a binary file without `-a`, so keep the `-a`:

```sh
grep -a -c __KEEPSNAPPY_HOOK__ main.jsbundle
```

## Keys

[Keys](https://keepsnappy.com/docs/keys.md) says what each KeepSnappy key does, where you get it, where it goes, and how to replace or stop it.

All KeepSnappy docs for agents: https://keepsnappy.com/llms.txt
