Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 61 additions & 63 deletions packages/firebase-crashlytics/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@

# @nativescript/firebase-crashlytics

* [Intro](#Intro)
* [Installation](#Installation)
* [Use @nativescript/firebase-crashlytics](#use-nativescriptfirebase-crashlytics)
* [Log a crash context](#log-a-crash-context)
* [Set crash attributes for more context data](#set-crash-attributes-for-more-context-data)
* [Test crashlytics](#test-crashlytics)
* [Report errors manually](#report-errors-manually)
* [Manually enable or disable crashlytics collection](#manually-enable-or-disable-crashlytics-collection
* [API](#API)
* [Crashlytics](#Crashlytics)
* [Properties](#Properties)
* [Methods](#Methods)
* [License](#License)

- [Intro](#Intro)
- [Installation](#Installation)
- [Use @nativescript/firebase-crashlytics](#use-nativescriptfirebase-crashlytics)
- [Log a crash context](#log-a-crash-context)
- [Set crash attributes for more context data](#set-crash-attributes-for-more-context-data)
- [Test crashlytics](#test-crashlytics)
- [Report errors manually](#report-errors-manually)
- [Manually enable or disable crashlytics collection](#manually-enable-or-disable-crashlytics-collection
- [API](#API)
- [Crashlytics](#Crashlytics)
- [Properties](#Properties)
- [Methods](#Methods)
- [License](#License)

A plugin that allows you to add [Firebase Crashlytics](https://firebase.google.com/docs/crashlytics) to your NativeScript app.

Expand All @@ -28,21 +26,19 @@ Crashlytics helps you to collect analytics and details about crashes and errors

[![image](https://img.youtube.com/vi/k_mdNRZzd30/hqdefault.jpg)](https://www.youtube.com/watch?v=k_mdNRZzd30)


## Installation
## Installation

Install the plugin by running the following command in the root directory of your project.

```cli
npm install @nativescript/firebase-crashlytics
```

## Use @nativescript/firebase-crashlytics

## Use @nativescript/firebase-crashlytics

### Log a crash context
### Log a crash context

Use the `log` method throughout your app to accumulate extra context for possible crashes that can happen.
Use the `log` method throughout your app to accumulate extra context for possible crashes that can happen.

```ts
import { firebase } from '@nativescript/firebase-core';
Expand All @@ -54,7 +50,7 @@ crashlytics.log('User signed in.');

### Set crash attributes for more context data

For additional context, Crashlytics also offers various methods to set attributes for the crash report.
For additional context, Crashlytics also offers various methods to set attributes for the crash report.

- To set a single attribute, call the `setAttribute` method passing it the attribute name as the first argument and its value as the second argument.

Expand All @@ -65,8 +61,8 @@ import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x
const crashlytics = firebase().crashlytics();

crashlytics().setAttribute('credits', String(user.credits));

```

- To set multiple attributes at once, call the `setAttributes` method with an object containing the attributes.

```ts
Expand All @@ -76,15 +72,17 @@ import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x
const crashlytics = firebase().crashlytics();

crashlytics().setAttributes({
role: 'admin',
followers: '13',
email: user.email,
username: user.username,
role: 'admin',
followers: '13',
email: user.email,
username: user.username,
});
```

You can use set methods to set predefined attributes, but you can also set your own custom attributes.

- You can also set the user ID. To do that call the `setUserId` method on `firebase().crashlytics()`
- You can also set the user ID. To do that call the `setUserId` method on `firebase().crashlytics()`

```ts
import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x
Expand All @@ -94,17 +92,17 @@ const crashlytics = firebase().crashlytics();
crashlytics.setUserId(user.uid);
```

### Test crashlytics
### Test crashlytics

To test Crashlytics for your app, call the `crash` method to force a crash and in Firebase Console, see if the crash is logged.

```ts
firebase().crashlytics().crash()
firebase().crashlytics().crash();
```

### Report errors manually
### Report errors manually

Crashlytics also supports sending JavaScript stack traces to the Firebase console. This can be used in any situation where an error occurs but is caught by your code to recover gracefully.
Crashlytics also supports sending JavaScript stack traces to the Firebase console. This can be used in any situation where an error occurs but is caught by your code to recover gracefully.

To send a stack trace, pass a JavaScript Error to the `recordError` method.

Expand All @@ -116,18 +114,18 @@ import { firebase } from '@nativescript/firebase-core';
firebase().crashlytics().log('Updating user count.');

try {
if (users) {
someMethodToCatch();
}
if (users) {
someMethodToCatch();
}
} catch (error) {
crashlytics().recordError(error);
console.log(error);
crashlytics().recordError(error);
console.log(error);
}
```

### Manually enable or disable crashlytics collection
### Manually enable or disable crashlytics collection

As Crashlytics will be sending certain information regarding the user, users may want to opt out of the crash reporting. To disable crashlytics collection, call the `setCrashlyticsCollectionEnabled` method on `firebase().crashlytics()` passing it `false` This can be done throughout the app with a simple method call to setCrashlyticsCollectionEnabled:
As Crashlytics will be sending certain information regarding the user, users may want to opt out of the crash reporting. To disable crashlytics collection, call the `setCrashlyticsCollectionEnabled` method on `firebase().crashlytics()` passing it `false` This can be done throughout the app with a simple method call to setCrashlyticsCollectionEnabled:

```ts
import { firebase } from '@nativescript/firebase-core';
Expand All @@ -137,33 +135,33 @@ firebase().crashlytics().setCrashlyticsCollectionEnabled(false);

## API

### Crashlytics
### Crashlytics

The Crashlytics class has the following members.

#### Properties

| Property | Type | Description
|----------|------|------------
| `ios` | | _readonly_
| `android` | _readonly_
| `app` | [FirebaseApp]()| _readonly_

#### Methods

| Method | Returns | Description
|----------|------|------------
| `checkForUnsentReports()` | `Promise<boolean>`
| `crash()` | `void`
| `deleteUnsentReports()` | `
| `didCrashOnPreviousExecution()` | `boolean`
| `log(message: string)` | `void`
| `recordError(error: any)` | `void`
| `sendUnsentReports()` | `void`
| `setAttribute(name: string, value: string | number | boolean)` | `void`
| `setAttributes(attributes: { [key: string]: string | number | boolean })` | `void`
| `setCrashlyticsCollectionEnabled(enabled: boolean)` | `void`
| `setUserId(userId: string)` | `void`
#### Properties

| Property | Type | Description |
| --------- | --------------- | ----------- |
| `ios` | | _readonly_ |
| `android` | _readonly_ |
| `app` | [FirebaseApp]() | _readonly_ |

#### Methods

| Method | Returns | Description |
| --------------------------------------------------------------------------- | ------------------ | ----------- |
| `checkForUnsentReports()` | `Promise<boolean>` | |
| `crash()` | `void` | |
| `deleteUnsentReports()` | `void` | |
| `didCrashOnPreviousExecution()` | `boolean` | |
| `log(message: string)` | `void` | |
| `recordError(error: any)` | `void` | |
| `sendUnsentReports()` | `void` | |
| `setAttribute(name: string, value: string \| number \| boolean)` | `void` | |
| `setAttributes(attributes: { [key: string]: string \| number \| boolean })` | `void` | |
| `setCrashlyticsCollectionEnabled(enabled: boolean)` | `void` | |
| `setUserId(userId: string)` | `void` | |

## License

Expand Down