react-native-forage
v0.5.5
Published
This SDK provides a library of utilities to allow the connection of your application to Forage Analytics (_www.forage-analytics.com_).
Downloads
161
Readme
Forage Analytics
This SDK provides a library of utilities to allow the connection of your application to Forage Analytics (www.forage-analytics.com).
Installation
To add Forage to your project, run the following command:
(Please note, Forage uses peer dependencies of other well-known packages in order to give you the best experience)
yarn add react-native-forage @react-native-async-storage/async-storage @react-native-community/netinfo react-native-device-info react-native-localize
// If you use npm instead of yarn
npm i react-native-forage @react-native-async-storage/async-storage @react-native-community/netinfo react-native-device-info react-native-localize
If you are using a React Native version lower than 0.60:
react-native link @react-native-async-storage/async-storage @react-native-community/netinfo
Integration
Obtaining an app key
To obtain a unique app key, simply sign-up at app.forage-analytics.com.
Call Forage.start
Once you have obtained an app key, you can connect your application to Forage and start tracking events via the start method, passing in your app key and the React Native AppState API.
// Import package and dependency
import Forage from 'react-native-forage';
import { AppState } from 'react-native';
// Call Forage.start with your unique app key
// TIP: Don’t forget to pass in AppState
Forage.start(YOUR_APP_KEY_HERE, AppState);
Forage SDK - Optional Methods
The Forage SDK consists of 5 additional methods;
Forage.setUserId(userId: string)
Sets a unique User ID for a session.
Example:
Forage.setUserId('User1');
Forage.trackEvent(eventName: string, properties?: string | number | boolean | object)
Send up any data of any size. Properties are optional.
Examples:
trackEvent('Customer Checkout Press');
trackEvent(‘Item Added to Basket’, {
label: 'Dining Room Chair',
currency: '£',
cost: ‘99.99’,
discount: ‘10%’,
total: ‘90.00’
});
Forage.trackScreen(screenName: string)
Track screen changes inside of your application.
Examples:
trackScreen('Product A - View');
trackScreen('Checkout Screen');
Forage.addTimer(label: string) & Forage.endTimer(label: string)
These can be used together to allow you to track the time that a particular event or action took to complete.
Examples:
startTimer('API X Called');
const data = await callApi();
endTimer('API X Called');