Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 35c1f5b

Browse files
Support Firebase Performance Monitoring #370
1 parent fd0d46d commit 35c1f5b

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NativeScript Firebase plugin
22

3+
[![Build Status][build-status]][build-url]
34
[![NPM version][npm-image]][npm-url]
45
[![Downloads][downloads-image]][npm-url]
56
[![Twitter Follow][twitter-image]][twitter-url]
@@ -24,6 +25,7 @@
2425
* [Crash Reporting / Crashlytics](docs/CRASHREPORTING.md)
2526
* [Invites and Dynamic Links](docs/INVITES_DYNAMICLINKS.md)
2627
* [ML Kit](docs/ML_KIT.md)
28+
* [Performance Monitoring](docs/PERFORMANCE_MONITORING.md)
2729
* [Realtime Database](docs/DATABASE.md)
2830
* [Remote Config](docs/REMOTECONFIG.md)
2931
* [Storage](docs/STORAGE.md)

docs/FUNCTIONS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ To add this feature to your project, either:
1919
In both cases, remove the `/platforms` folder afterwards so the required native library will be added upon the next build.
2020

2121

22-
## Functions
22+
## API
2323
You can use either the Web API syntax (easy for interoperability with a web version of your app), or our custom native syntax.
2424
Use whichever syntax you like most - the underlying implementation is the same.
2525

26-
### httpsCallable
26+
### `httpsCallable`
2727
This example uses the Cloud Function as [implemented here](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/ff95c77c7b09acf66654f53c52e8ae0c8d7b1c78/demo/firebasefunctions/functions/src/index.ts#L15-L19).
2828

2929
<details>

docs/PERFORMANCE_MONITORING.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)