@zeronative/firebase-perf
Firebase Performance Monitoring in zero-native apps, on Android and iOS, with RN Firebase’s perf() API. Most apps need no
JS. By itself it sends:
- The app start (Firebase’s own trace).
- Every
fetch: a network trace (time, response code, sizes) from an interceptor on core’s fetch client. Firebase sees the URL with no query and no fragment, since those may hold tokens or personal data. - Every screen: a trace per top route,
screen_<route>, withframes,frames_slow(over 16 ms, not counting frozen ones) andframes_frozen(over 700 ms). The app is one Activity, so Firebase’s own screen traces would all be one screen. zn_bundleon every trace: the running bundle, to compare OTA bundles.
No Gradle plugin is needed (Firebase’s firebase-perf Gradle plugin only rewrites bytecode for apps that use plain
OkHttp; zero-native’s fetch already goes through the interceptor).
Add it
Section titled “Add it”- Firebase as for
@zeronative/firebase-app. - In
settings.gradle.kts::plugin-firebase-perf→../plugins/firebase-perf/android. - In the app’s
build.gradle.kts:implementation(project(":plugin-firebase-perf")). - In
Application.onCreate, with the other plugins, before the first fetch:A fetch made before it (very rare) means no network traces in that process; the plugin logs one line.ZnPlugins.register(this, PerfPlugin())// Your own URL rule (null: no trace for it), or no screen traces:ZnPlugins.register(this, PerfPlugin(url = { u -> if (u.host == "api.example.com") "${u.scheme}://${u.host}${u.encodedPath}" else null }))
It starts at the first launch, before any consent. From the first start it collects the app start, the screen
traces and every fetch (the URL without the query and fragment), plus device data that Firebase adds. To keep it off
until the user agrees, put this in the app’s <application> and call setPerformanceCollectionEnabled(true) after the
yes (the flag is Firebase’s own; this plugin does not read or change it):
<meta-data android:name="firebase_performance_collection_enabled" android:value="false" />.
Do this for a DPDP / consent check before real users. (Analytics also collects before consent by default, Pavan’s call;
see its README.)
Permissions: none of its own (Firebase adds INTERNET and ACCESS_NETWORK_STATE). To see traces in logcat while
testing: <meta-data android:name="firebase_performance_logcat_enabled" android:value="true" /> (the sample does).
Add it on iOS
Section titled “Add it on iOS”- Firebase as for
@zeronative/firebase-app(GoogleService-Info.plistin the app). - The Swift package’s
ZnPluginFirebasePerfproduct (zero-native-firebase,ios/packages/firebase), or in a CMake build the Firebase SDK (bun run tools/fetch-firebase-apple.ts) andplugins/firebase-perf/ios. - In the app’s Info.plist, so Firebase’s own URLSession and UIKit hooks stay off whatever the order below (the SDK
turns them on by itself as soon as it is linked, even with no PerfPlugin):
<key>firebase_performance_instrumentation_enabled</key><false/>(the sample has it). - Register it first, before
FirebaseAppPluginand the other Firebase plugins (Firebase reads the switch for its own hooks when it starts, andFirebaseAppPluginstarts it):ZnPlugins.register(PerfPlugin(), FirebaseAppPlugin(), AnalyticsPlugin(), ...)PerfPlugin(screens: false) // no screen_<route> traces (and no display link)PerfPlugin(url: { u in u.host == "api.example.com" ? "https://\(u.host!)\(u.path)" : nil }) // your URL rule, as AndroidPerfPlugin(automatic: true) // Firebase's own network and view controller traces, see below
iOS differences:
- Network traces come from an observer on core’s fetch (
ZnFetch.addObserver), as Android’s interceptor: the sameurloption (default: no query, fragment, user or password;nilleaves a request out) andzn_bundle. Register the plugin before the first fetch. Two small differences: the response size is the body received (unzipped), where Android sends itsContent-Length; a method Firebase doesn’t know (PROPPATCH,REPORT) gets no trace. A call that ends with no response (offline, a timeout, an abort) stops with no code, which Firebase counts as a network error.PerfPlugin(automatic: true)(iOS only, off by default) turns on Firebase’s own hooks as well: every URLSession request is traced, core’sfetchagain (twice then) and also images, OTA downloads and Firebase’s own calls, with the URL without query, fragment, user and password, nourloption and nozn_bundle. They also bring Firebase’s view controller screen traces (_st_ZnScreenController: one view controller for every route; read thescreen_<route>ones). The switch is kept on the phone: registered afterFirebaseAppPlugin, a change applies from the next start. - Frames come from a display link, as in Firebase iOS. It ticks at every screen refresh whether or not anything
was drawn, so
framescounts refreshes (a still screen adds about 60 a second; Android counts only drawn frames): compareframes_slowandframes_frozenbetween screens and bundles, not with Android.frames_slowis a frame longer than 1/59 s (so a ProMotion frame that misses 120 Hz isn’t slow),frames_frozenlonger than 700 ms; a frozen frame isn’t also slow. The link runs while the app is in front, so a still screen doesn’t drop to a lower refresh rate (some battery);screens: falseturns it off. - Consent:
firebase_performance_collection_enabled= NO in the app’s Info.plist, thensetPerformanceCollectionEnabled(true)after the yes.-FIRDebugEnabledas a launch argument logs each trace.
Use it
Section titled “Use it”import { Perf } from "@zeronative/firebase-perf"
await Perf.trace("receipt_render", async (t) => { await t.putAttribute("kind", "pdf") await renderReceipt()})
const t = await Perf.startTrace("checkout_load")t.incrementMetric("retries")await t.stop()Each call answers and never rejects. A bad name answers false with a console warning.
| Call | Answers | What it does |
|---|---|---|
status() |
{ available, enabled } |
|
setPerformanceCollectionEnabled(on) |
true / false | Kept across starts |
isPerformanceCollectionEnabled |
boolean | The last value seen |
startTrace(name) |
Trace |
1–100 characters, no space at either end, not starting with _ |
trace(name, fn) |
fn’s result |
Starts, runs, stops (also when fn throws) |
Trace.putMetric(name, n) / incrementMetric(name, by = 1) |
true / false | Whole numbers |
Trace.putAttribute(name, value) / removeAttribute(name) |
true / false | 5 at most; names 40 characters; values cut to 100 |
Trace.stop() |
true / false | Sends it. A trace never stopped is never sent |
RN Firebase’s names work for ported code: perf().startTrace(...), getPerformance(). Not built: newHttpMetric
(every fetch is traced already), newScreenTrace.
Do and don’t
Section titled “Do and don’t”- Do register it before anything fetches. Why: core’s fetch client is built once, at the first fetch.
- Don’t put personal data in trace names, attributes or URL paths you let through. Why: everyone with console
access sees them. The default URL rule drops the query; a path with a phone number in it still shows: use
url. - Do read
frames_slowandframes_frozenper screen, and comparezn_bundlevalues after an OTA. - Know: traces reach the console some minutes later.
- Know: URL paths are kept. An id in a path (
/orders/12345) goes to Firebase. Only the query and fragment are cut. Use theurloption to shorten such paths. - Know: other plugins’ fetches and the OTA check also go through the interceptor, because it sits on core’s shared
client (
ZnFetch.addInterceptor,docs/fetch.md§5).
| Dependency | Version | Why |
|---|---|---|
com.google.firebase:firebase-perf |
from the BoM (35.1.0) | Performance Monitoring |
The sample’s release APK: 15.21 MB before, 15.35 MB with it (+0.14 MB, 2026-11-04).