Skip to content

Commit d7cd9f2

Browse files
authored
docs(firebase-crashlytics): update (#190)
1 parent c5c16a4 commit d7cd9f2

File tree

1 file changed

+114
-19
lines changed

1 file changed

+114
-19
lines changed
Lines changed: 114 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,116 @@
1-
# @nativescript/firebase-crashlytics
2-
3-
```cli
4-
npm install @nativescript/firebase-crashlytics
5-
```
6-
7-
## What does it do
1+
<!-- vscode-markdown-toc -->
2+
* 1. [Intro](#Intro)
3+
* 2. [Installation](#Installation)
4+
* 3. [Use @nativescript/firebase-crashlytics](#Usenativescriptfirebase-crashlytics)
5+
* 3.1. [Log a crash context](#Logacrashcontext)
6+
* 3.2. [Set crash attributes for more context data](#Setcrashattributesformorecontextdata)
7+
* 3.3. [Test crashlytics](#Testcrashlytics)
8+
* 3.4. [Report errors manually](#Reporterrorsmanually)
9+
* 3.5. [Manually enable or disable crashlytics collection](#Manuallyenableordisablecrashlyticscollection)
10+
* 4. [API](#API)
11+
* 4.1. [Crashlytics](#Crashlytics)
12+
* 4.1.1. [Properties](#Properties)
13+
* 4.1.2. [Methods](#Methods)
14+
* 5. [License](#License)
15+
16+
<!-- vscode-markdown-toc-config
17+
numbering=true
18+
autoSave=true
19+
/vscode-markdown-toc-config -->
20+
<!-- /vscode-markdown-toc --># @nativescript/firebase-crashlytics
21+
22+
## 1. <a name='Intro'></a>Intro
23+
24+
A plugin that allows you to add [Firebase Crashlytics](https://firebase.google.com/docs/crashlytics) to your NativeScript app.
25+
26+
> **Note:** Use this plugin with the [@nativescript/firebase-core](../firebase-core/) plugin to initialize Firebase.
827
928
Crashlytics helps you to collect analytics and details about crashes and errors that occur in your app. It does this through three aspects:
1029

11-
- **Logs**: Log events in your app to be sent with the crash report for context if your app crashes.
30+
- **Logs**: Log events in your app to be sent with the crash report for context when your app crashes.
1231
- **Crash reports**: Every crash is automatically turned into a crash report and sent.
1332
- **Stack traces**: Even when an error is caught and your app recovers, the JavaScript stack trace can still be sent.
1433

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

17-
## Usage
36+
## 2. <a name='Installation'></a>Installation
1837

19-
Use the log method throughout your app to accumulate extra context for possible crashes that can happen. For additional context, Crashlytics also offers various methods to set attributes for the crash report. You can also test Crashlytics by forcing a crash through the crash method.
38+
Install the plugin by running the following command in the root directory of your project.
2039

21-
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 own code to recover gracefully. To send a stack trace, pass a JavaScript Error to the recordError method.
40+
```cli
41+
npm install @nativescript/firebase-crashlytics
42+
```
2243

23-
### Crash Attributes
44+
## 3. <a name='Usenativescriptfirebase-crashlytics'></a>Use @nativescript/firebase-crashlytics
2445

25-
There are various methods to set attributes for the crash report, in order to provide analytics for crashes and help you review them. You can use set methods to set predefined attributes, but you can also set your own custom attributes.
46+
### 3.1. <a name='Logacrashcontext'></a>Log a crash context
47+
Use the `log` method throughout your app to accumulate extra context for possible crashes that can happen.
2648

2749
```ts
2850
import { firebase } from '@nativescript/firebase-core';
2951
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x
3052

3153
const crashlytics = firebase().crashlytics();
3254
crashlytics.log('User signed in.');
33-
crashlytics.setUserId(user.uid);
55+
```
56+
57+
### 3.2. <a name='Setcrashattributesformorecontextdata'></a>Set crash attributes for more context data
58+
59+
For additional context, Crashlytics also offers various methods to set attributes for the crash report.
60+
61+
- 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.
62+
63+
```ts
64+
import { firebase } from '@nativescript/firebase-core';
65+
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x
66+
67+
const crashlytics = firebase().crashlytics();
68+
3469
crashlytics().setAttribute('credits', String(user.credits));
70+
71+
```
72+
- To set multiple attributes at once, call the `setAttributes` method with an object containing the attributes.
73+
74+
```ts
75+
import { firebase } from '@nativescript/firebase-core';
76+
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x
77+
78+
const crashlytics = firebase().crashlytics();
79+
3580
crashlytics().setAttributes({
3681
role: 'admin',
3782
followers: '13',
3883
email: user.email,
3984
username: user.username,
4085
});
4186
```
87+
You can use set methods to set predefined attributes, but you can also set your own custom attributes.
88+
89+
- You can also set the user ID. To do that call the `setUserId` method on `firebase().crashlytics()`
90+
```ts
91+
import { firebase } from '@nativescript/firebase-core';
92+
import '@nativescript/firebase-crashlytics'; // only needs to be imported 1x
93+
94+
const crashlytics = firebase().crashlytics();
95+
96+
crashlytics.setUserId(user.uid);
97+
```
98+
99+
### 3.3. <a name='Testcrashlytics'></a>Test crashlytics
100+
101+
To test Crashlytics for your app, call the `crash` method to force a crash and in Firebase Console, see if the crash is logged.
102+
103+
```ts
104+
firebase().crashlytics().crash()
105+
```
106+
107+
### 3.4. <a name='Reporterrorsmanually'></a>Report errors manually
108+
109+
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.
42110

43-
### Error Reports
111+
To send a stack trace, pass a JavaScript Error to the `recordError` method.
44112

45-
Even if you catch unexpected errors, in order for your app to recover and behave smoothly you can still report them through Crashlytics using the recordError method. This will also provide you with the associated stack trace.
113+
Even if you catch unexpected errors, for your app to recover and behave smoothly you can still report them through Crashlytics using the `recordError` method. This will also provide you with the associated stack trace.
46114

47115
```ts
48116
import { firebase } from '@nativescript/firebase-core';
@@ -59,16 +127,43 @@ try {
59127
}
60128
```
61129

62-
### Opt-out
130+
### 3.5. <a name='Manuallyenableordisablecrashlyticscollection'></a>Manually enable or disable crashlytics collection
63131

64-
As Crashlytics will be sending certain information regarding the user, users may want to opt-out of the crash reporting. This can be done throughout the app with a simple method call to setCrashlyticsCollectionEnabled:
132+
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:
65133

66134
```ts
67135
import { firebase } from '@nativescript/firebase-core';
68136

69137
firebase().crashlytics().setCrashlyticsCollectionEnabled(false);
70138
```
71139

72-
## License
140+
## 4. <a name='API'></a>API
141+
### 4.1. <a name='Crashlytics'></a>Crashlytics
142+
143+
The Crashlytics class has the following members.
144+
#### 4.1.1. <a name='Properties'></a>Properties
145+
| Property | Type | Description
146+
|----------|------|------------
147+
| `ios` | | _readonly_
148+
| `android` | _readonly_
149+
| `app` | [FirebaseApp]()| _readonly_
150+
151+
152+
#### 4.1.2. <a name='Methods'></a>Methods
153+
| Method | Returns | Description
154+
|----------|------|------------
155+
| `checkForUnsentReports()` | `Promise<boolean>`
156+
| `crash()` | `void`
157+
| `deleteUnsentReports()` | `
158+
| `didCrashOnPreviousExecution()` | `boolean`
159+
| `log(message: string)` | `void`
160+
| `recordError(error: any)` | `void`
161+
| `sendUnsentReports()` | `void`
162+
| `setAttribute(name: string, value: string | number | boolean)` | `void`
163+
| `setAttributes(attributes: { [key: string]: string | number | boolean })` | `void`
164+
| `setCrashlyticsCollectionEnabled(enabled: boolean)` | `void`
165+
| `setUserId(userId: string)` | `void`
166+
167+
## 5. <a name='License'></a>License
73168

74169
Apache License Version 2.0

0 commit comments

Comments
 (0)