1.2.2 • Published 2 years ago

@kkurko/react-native-session-stats v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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.

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

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

// ...

<SessionStats>
  <App />
<SessionStats/>

Values are available via useSessionStats hook:

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

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

or via sessionStatsContext and useContext hook:

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

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

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago