|
| 1 | +<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/performancemonitoring.png" height="85px" alt="Performance Monitoring"/> |
| 2 | + |
| 3 | +> Added in plugin version 7.3.0 |
| 4 | +
|
| 5 | +## Performance Monitoring? |
| 6 | +With Firebase Performance Monitoring you get insights into how your app performs from your users' point of view, with automatic and customized performance tracing. |
| 7 | + |
| 8 | +[Learn more here..](https://firebase.google.com/products/performance/) |
| 9 | + |
| 10 | +## Enabling Performance Monitoring |
| 11 | +To add this feature to your project, either: |
| 12 | + |
| 13 | +* Remove `firebase.nativescript.json` from the root of the project and run `npm i`, or |
| 14 | +* Edit that file and add `"performance_monitoring": true`. |
| 15 | + |
| 16 | +In both cases, remove the `/platforms` folder afterwards so the required native library will be added upon the next build. |
| 17 | + |
| 18 | +## API |
| 19 | +You can use either the Web API syntax (easy for interoperability with a web version of your app), or our custom native syntax. |
| 20 | +Use whichever syntax you like most - the underlying implementation is the same. |
| 21 | + |
| 22 | +### `startTrace` |
| 23 | +You need to start and stop a trace, so remember the started trace in some property: |
| 24 | + |
| 25 | +```typescript |
| 26 | +import { performance as firebasePerformance } from "nativescript-plugin-firebase"; |
| 27 | +import { FirebaseTrace } from "nativescript-plugin-firebase/performance/performance"; |
| 28 | + |
| 29 | +const firebaseTrace: FirebaseTrace = firebasePerformance.startTrace("myTrace"); |
| 30 | +``` |
| 31 | + |
| 32 | +Now you can call several functions on the remembered trace object, read on below. And don't forget to use `trace.stop`. |
| 33 | + |
| 34 | +### `trace.setValue` |
| 35 | + |
| 36 | +```typescript |
| 37 | +if (firebaseTrace) { |
| 38 | + firebaseTrace.setValue("foo", "bar"); |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +### `trace.getValue` |
| 43 | + |
| 44 | +```typescript |
| 45 | +if (firebaseTrace) { |
| 46 | + firebaseTrace.getValue("foo"); |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +### `trace.getAttributes` |
| 51 | + |
| 52 | +```typescript |
| 53 | +if (firebaseTrace) { |
| 54 | + const attributes = firebaseTrace.getAttributes(); |
| 55 | + console.log(`trace attributes: ${attributes}`); |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### `trace.removeAttribute` |
| 60 | + |
| 61 | +```typescript |
| 62 | +if (firebaseTrace) { |
| 63 | + const attributes = firebaseTrace.removeAttribute("foo"); |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +### `trace.incrementMetric` |
| 68 | + |
| 69 | +```typescript |
| 70 | +if (firebaseTrace) { |
| 71 | + const incrementBy = 1; |
| 72 | + const attributes = firebaseTrace.incrementMetric("foo_metric", incrementBy); |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +### `trace.stop` |
| 77 | +To stop the trace, call `stop` on the remembered trace object: |
| 78 | + |
| 79 | +```typescript |
| 80 | +if (firebaseTrace) { |
| 81 | + firebaseTrace.stop(); |
| 82 | + firebaseTrace = undefined; |
| 83 | +} |
| 84 | +``` |
0 commit comments