Added in plugin version 7.3.0
With Firebase Performance Monitoring you get insights into how your app performs from your users' point of view, with automatic and customized performance tracing.
To add this feature to your project, either:
- Remove
firebase.nativescript.json
from the root of the project and runnpm i
, or - Edit that file and add
"performance_monitoring": true
.
In both cases, remove the /platforms
folder afterwards so the required native library will be added upon the next build.
To interact with a started trace, we're remembering it in the property firebaseTrace
:
import { performance as firebasePerformance } from "nativescript-plugin-firebase";
import { FirebaseTrace } from "nativescript-plugin-firebase/performance/performance";
const firebaseTrace: FirebaseTrace = firebasePerformance.startTrace("myTrace");
Now you can call several functions on the remembered trace object, read on below. And don't forget to use trace.stop
.
if (firebaseTrace) {
firebaseTrace.setValue("foo", "bar");
}
if (firebaseTrace) {
firebaseTrace.getValue("foo");
}
if (firebaseTrace) {
const attributes = firebaseTrace.getAttributes();
console.log(`trace attributes: ${attributes}`);
}
if (firebaseTrace) {
const attributes = firebaseTrace.removeAttribute("foo");
}
if (firebaseTrace) {
const incrementBy = 1;
const attributes = firebaseTrace.incrementMetric("foo_metric", incrementBy);
}
To stop the trace, call stop
on the remembered trace object:
if (firebaseTrace) {
firebaseTrace.stop();
firebaseTrace = undefined;
}