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

Commit

Permalink
Support Firebase Performance Monitoring #370
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Oct 24, 2018
1 parent fd0d46d commit 35c1f5b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# NativeScript Firebase plugin

[![Build Status][build-status]][build-url]
[![NPM version][npm-image]][npm-url]
[![Downloads][downloads-image]][npm-url]
[![Twitter Follow][twitter-image]][twitter-url]
Expand All @@ -24,6 +25,7 @@
* [Crash Reporting / Crashlytics](docs/CRASHREPORTING.md)
* [Invites and Dynamic Links](docs/INVITES_DYNAMICLINKS.md)
* [ML Kit](docs/ML_KIT.md)
* [Performance Monitoring](docs/PERFORMANCE_MONITORING.md)
* [Realtime Database](docs/DATABASE.md)
* [Remote Config](docs/REMOTECONFIG.md)
* [Storage](docs/STORAGE.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ To add this feature to your project, either:
In both cases, remove the `/platforms` folder afterwards so the required native library will be added upon the next build.


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

### httpsCallable
### `httpsCallable`
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).

<details>
Expand Down
84 changes: 84 additions & 0 deletions docs/PERFORMANCE_MONITORING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/performancemonitoring.png" height="85px" alt="Performance Monitoring"/>

> Added in plugin version 7.3.0
## Performance Monitoring?
With Firebase Performance Monitoring you get insights into how your app performs from your users' point of view, with automatic and customized performance tracing.

[Learn more here..](https://firebase.google.com/products/performance/)

## Enabling Performance Monitoring
To add this feature to your project, either:

* Remove `firebase.nativescript.json` from the root of the project and run `npm 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.

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

### `startTrace`
You need to start and stop a trace, so remember the started trace in some property:

```typescript
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`.

### `trace.setValue`

```typescript
if (firebaseTrace) {
firebaseTrace.setValue("foo", "bar");
}
```

### `trace.getValue`

```typescript
if (firebaseTrace) {
firebaseTrace.getValue("foo");
}
```

### `trace.getAttributes`

```typescript
if (firebaseTrace) {
const attributes = firebaseTrace.getAttributes();
console.log(`trace attributes: ${attributes}`);
}
```

### `trace.removeAttribute`

```typescript
if (firebaseTrace) {
const attributes = firebaseTrace.removeAttribute("foo");
}
```

### `trace.incrementMetric`

```typescript
if (firebaseTrace) {
const incrementBy = 1;
const attributes = firebaseTrace.incrementMetric("foo_metric", incrementBy);
}
```

### `trace.stop`
To stop the trace, call `stop` on the remembered trace object:

```typescript
if (firebaseTrace) {
firebaseTrace.stop();
firebaseTrace = undefined;
}
```

0 comments on commit 35c1f5b

Please sign in to comment.