React Native wrapper for Sift iOS and Android SDKs
- Install library from npm:
yarn add sift-react-native
or
npm install sift-react-native
No additional setup is required
- Insert the following line in Podfile where new pods are added:
pod 'sift-react-native', :path => '../node_modules/sift-react-native'
- Navigate to the ios directory of the project via terminal and run
pod install
react-native link
-
Append the following lines to
android/settings.gradle
:include ':sift-react-native'
project(':sift-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/sift-react-native/android')
-
Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':sift-react-native')
-
Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.siftreactnative.SiftReactNativePackage;
to the imports at the top of the file - Add
new SiftReactNativePackage()
to the list returned by thegetPackages()
method. Add a comma to the previous item if there's already something there.
Insert the following lines inside the dependencies block in
android/app/build.gradle
:
implementation 'com.android.support:support-v4:27.0.2'
Support will be available soon
First, import the module:
import SiftReactNative from "sift-react-native";
Then, invoke the following method to initialise the SDK:
SiftReactNative.setSiftConfig(accountId, beaconKey, disallowCollectingLocationData, serverUrlFormat);
Where:
- accountId (string, the Account ID that needs to be obtained from Sift console under API Keys tab) required
- beaconKey (string, the Beacon Key that needs to be obtained from Sift console under API Keys tab) required
- disallowCollectingLocationData (boolean, permission to allow collection of location data from device)
Make sure to add location permissions to your application if you want Sift to collect location data. Sift will not request permissions that are not granted by the user from your application.
- serverUrlFormat (string, the format of URL where the data needs to be uploaded)
-- Sample URL format for iOS:
https://api3.siftscience.com/v3/accounts/%@/mobile_events
-- Sample URL format for Android:https://api3.siftscience.com/v3/accounts/%s/mobile_events
NB: This feature is available only in iOS platform
As soon as your application is aware of the user id, set it on the Sift instance using the code below. All subsequent events will include the user id.
SiftReactNative.setUserId(userId);
If the user logs out of your application, you should unset the user id:
SiftReactNative.unsetUserId();
To upload collected events to sift.
SiftReactNative.upload();
NB: This feature is available only in Android platform
To set the page name
SiftReactNative.setPageName("HomePage");
To see sift-react-native
in action you can check out the source in the example
folder.
yarn bootstrap
When the bootstrap is done, you will be able to start the example app by executing one of the following commands:
yarn example ios
yarn example android
MIT