Skip to content

Commit

Permalink
README.md file added
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillkurko committed Sep 5, 2022
1 parent 114c0c0 commit 15ddd96
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# react-native-session-stats

Package provides context that stores information about user session. Next information is available - `timeSpent`, `sessionCount` and `lastSessionEnd`. Package can be used for internal analytics, as well as for implementing UI user will interact with. Some possible use cases are:
- show user session time;
- show popup, based on session count or session time;
- log out user after specified session time;
- send warning push notifications on session end.

## Install

```
// npm usage
npm i @kkurko/react-native-session-stats
// yarn usage
yarn add @kkurko/react-native-session-stats
```

## Usage

The `SessionStats` component takes two props: `onSessionStart` is fired when the app's state changes to `active`, `onSessionEnd`, when it changes to `inactive` or `background`.

```javascript
import SessionStats from '@kkurko/react-native-session-stats';

// ...

<SessionStats
onSessionStart={({
timeSpent, // total time spent, in seconds
sessionCount, // number of sessions as of at opening the app
lastSessionEnd, // timestamp of the last session end
}) => { /* ... */ }}
onSessionEnd={({
timeSpent, // total time spent in seconds
sessionCount, // and number of sessions as of at closing the app
lastSessionEnd, // timestamp of the last session end
sessionDuration, // the length of the ending session, in seconds
}) => { /* ... */ }}
/>
```

`SessionStats` is used as a context provider

```javascript
import SessionStats from '@kkurko/react-native-session-stats';

// ...

<SessionStats>
<App />
<SessionStats/>
```

Values are available via `useSessionStats` hook:

```javascript
import { useSessionStats } from '@kkurko/react-native-session-stats';

const SomeComponent = () => {
const { timeSpent, sessionCount, lastSessionEnd } = useSessionStats();
//...
};
```


or via `sessionStatsContext` and `useContext` hook:

```javascript
import { useContext } from 'react';
import { sessionStatsContext } from '@kkurko/react-native-session-stats';

const SomeComponent = () => {
const { timeSpent, sessionCount, lastSessionEnd } = useContext(sessionStatsContext);
//...
};
```

0 comments on commit 15ddd96

Please sign in to comment.