This SDK provides a library of utilities to allow the connection of your application to Forage Analytics (www.forage-analytics.com).
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-beta @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-beta @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
To obtain a unique app key, simply sign-up at app.forage-analytics.com.
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-beta';
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);
The Forage SDK consists of 5 additional methods;
Sets a unique User ID for a session.
Example:
Forage.setUserId('User1');
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’
});
Track screen changes inside of your application.
Examples:
trackScreen('Product A - View');
trackScreen('Checkout Screen');
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');