Skip to content

Commit dd6ce1d

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 4cb24bd + 7e35007 commit dd6ce1d

File tree

2 files changed

+40
-48
lines changed

2 files changed

+40
-48
lines changed

docs/api/analytics.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,62 @@ own app. The Firebase SDK includes a number of pre-set events which are automati
1919
'user_engagement',
2020
```
2121

22-
#### logEvent(event: string, params?: Object)
22+
#### `logEvent(event: string, params?: Object): void`
2323

24-
Log a custom event with optional params. Can be synchronous or return a Promise
24+
Log a custom event with optional params.
2525

2626
```javascript
27-
firestack.analytics()
28-
.logEvent('clicked_advert', { id: 1337 })
29-
.then(() => {
30-
console.log('Event has been logged successfully');
31-
});
27+
firestack.analytics().logEvent('clicked_advert', { id: 1337 });
3228
```
3329

34-
#### setAnalyticsCollectionEnabled(enabled: boolean)
30+
#### `setAnalyticsCollectionEnabled(enabled: boolean): void`
3531

3632
Sets whether analytics collection is enabled for this app on this device.
3733

3834
```javascript
39-
firestack.analytics()
40-
.setAnalyticsCollectionEnabled(false);
35+
firestack.analytics().setAnalyticsCollectionEnabled(false);
4136
```
4237

43-
#### setCurrentScreen(screenName: string, screenClassOverride: string)
38+
#### `setCurrentScreen(screenName: string, screenClassOverride?: string): void`
4439

4540
Sets the current screen name, which specifies the current visual context in your app.
4641

42+
> Whilst `screenClassOverride` is optional, it is recommended it is always sent as your current class name, for example on Android it will always show as 'MainActivity' if not specified.
43+
4744
```javascript
48-
firestack.analytics()
49-
.setCurrentScreen('user_profile');
45+
firestack.analytics().setCurrentScreen('user_profile');
5046
```
5147

52-
#### setMinimumSessionDuration(miliseconds: number)
48+
#### `setMinimumSessionDuration(miliseconds: number): void`
5349

5450
Sets the minimum engagement time required before starting a session. The default value is 10000 (10 seconds).
5551

5652
```javascript
57-
firestack.analytics()
58-
.setMinimumSessionDuration(15000);
53+
firestack.analytics().setMinimumSessionDuration(15000);
5954
```
6055

61-
#### setSessionTimeoutDuration(miliseconds: number)
56+
#### `setSessionTimeoutDuration(miliseconds: number): void`
6257

6358
Sets the duration of inactivity that terminates the current session. The default value is 1800000 (30 minutes).
6459

6560
```javascript
66-
firestack.analytics()
67-
.setSessionTimeoutDuration(900000);
61+
firestack.analytics().setSessionTimeoutDuration(900000);
6862
```
6963

70-
#### setUserId(id: string)
64+
#### `setUserId(id: string): void`
7165

7266
Gives a user a uniqiue identificaition.
7367

7468
```javascript
7569
const id = firestack.auth().currentUser.uid;
7670

77-
firestack.analytics()
78-
.setUserId(id);
71+
firestack.analytics().setUserId(id);
7972
```
8073

81-
#### setUserProperty(name: string, value: string)
74+
#### `setUserProperty(name: string, value: string): void`
8275

8376
Sets a key/value pair of data on the current user.
8477

8578
```javascript
86-
firestack.analytics()
87-
.setUserProperty('nickname', 'foobar');
79+
firestack.analytics().setUserProperty('nickname', 'foobar');
8880
```

docs/api/authentication.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@ Firestack handles authentication for us out of the box, both with email/password
44

55
> Android requires the Google Play services to installed for authentication to function.
66
7-
## Local Auth
7+
#### [`onAuthStateChanged(event: Function): Function`](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged)
88

9-
#### [onAuthStateChanged(event: Function)](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged)
10-
11-
Listen for changes in the users auth state (logging in and out).
9+
Listen for changes in the users auth state (logging in and out). This method returns a unsubscribe function to stop listening to events. Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
1210

1311
```javascript
14-
firestack.auth().onAuthStateChanged((evt) => {
15-
// evt is the authentication event, it contains an `error` key for carrying the
16-
// error message in case of an error and a `user` key upon successful authentication
17-
if (!evt.authenticated) {
18-
// There was an error or there is no user
19-
console.error(evt.error)
20-
} else {
21-
// evt.user contains the user details
22-
console.log('User details', evt.user);
23-
}
24-
})
25-
.then(() => console.log('Listening for authentication changes'))
26-
```
12+
class Example extends React.Component {
2713

28-
#### offAuthStateChanged()
29-
30-
Remove the `onAuthStateChanged` listener.
31-
This is important to release resources from our app when we don't need to hold on to the listener any longer.
14+
constructor() {
15+
super();
16+
this.unsubscribe = null;
17+
}
18+
19+
componentDidMount() {
20+
this.unsubscribe = firebase.auth().onAuthStateChanged(function(user) {
21+
if (user) {
22+
// User is signed in.
23+
}
24+
});
25+
}
26+
27+
componentWillUnmount() {
28+
if (this.listener) {
29+
this.unsubscribe();
30+
}
31+
}
3232

33-
```javascript
34-
firestack.auth().offAuthStateChanged()
33+
}
3534
```
3635

36+
3737
#### [createUserWithEmailAndPassword(email: string, password: string)](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword)
3838

3939
We can create a user by calling the `createUserWithEmailAndPassword()` function.

0 commit comments

Comments
 (0)