|
1 | | -# sift-react-native |
| 1 | +# Sift React Native SDK Documentation |
2 | 2 |
|
3 | | -A React Native wrapper for Sift iOS and Android SDKs |
| 3 | +A comprehensive React Native wrapper for Sift iOS and Android SDKs, enabling fraud prevention and digital trust & safety in your mobile applications. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +1. [Overview](#overview) |
| 8 | +2. [Installation](#installation) |
| 9 | +3. [Platform Setup](#platform-setup) |
| 10 | +4. [API Reference](#api-reference) |
| 11 | +5. [Usage Examples](#usage-examples) |
| 12 | +6. [Configuration](#configuration) |
| 13 | +7. [Troubleshooting](#troubleshooting) |
| 14 | +8. [Contributing](#contributing) |
| 15 | + |
| 16 | +## Overview |
| 17 | + |
| 18 | +Sift is the leader in Digital Trust & Safety, empowering organizations of all sizes to unlock new revenue without risk using machine learning. This React Native SDK provides a unified interface to integrate Sift's fraud prevention capabilities across both iOS and Android platforms. |
4 | 19 |
|
5 | 20 | ## Installation |
6 | 21 |
|
| 22 | +### Prerequisites |
7 | 23 |
|
8 | | -```sh |
| 24 | +- React Native 0.60+ |
| 25 | +- iOS 11.0+ (for iOS) |
| 26 | +- Android API 21+ (for Android) |
| 27 | +- Node.js 20+ |
| 28 | + |
| 29 | +### Install the Package |
| 30 | + |
| 31 | +```bash |
9 | 32 | npm install sift-react-native |
| 33 | +# or |
| 34 | +yarn add sift-react-native |
| 35 | +``` |
| 36 | + |
| 37 | +### iOS Setup |
| 38 | + |
| 39 | +#### 1. Add Sift Pod to Podfile |
| 40 | + |
| 41 | +Add the Sift pod to your `ios/Podfile`: |
| 42 | + |
| 43 | +```ruby |
| 44 | +target 'YourAppName' do |
| 45 | + # ... other pods |
| 46 | + pod 'Sift' |
| 47 | +end |
| 48 | +``` |
| 49 | + |
| 50 | +#### 2. Install CocoaPods Dependencies |
| 51 | + |
| 52 | +Navigate to your iOS directory and install pods: |
| 53 | + |
| 54 | +```bash |
| 55 | +cd ios |
| 56 | +pod install |
| 57 | +``` |
| 58 | + |
| 59 | +### Android Setup |
| 60 | + |
| 61 | +#### 1. Add Sift Dependency |
| 62 | + |
| 63 | +The Android dependency is automatically included via the module's `build.gradle`: |
| 64 | + |
| 65 | +```gradle |
| 66 | +dependencies { |
| 67 | + implementation "com.siftscience:sift-android:1.3.0" |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +## Platform Setup |
| 72 | + |
| 73 | +### React Native Configuration |
| 74 | + |
| 75 | +#### 1. Import the Module |
| 76 | + |
| 77 | +```typescript |
| 78 | +import SiftReactNative from 'sift-react-native'; |
| 79 | +``` |
| 80 | + |
| 81 | +#### 2. Initialize Sift |
| 82 | + |
| 83 | +Configure Sift with your account credentials: |
| 84 | + |
| 85 | +```typescript |
| 86 | +// Basic configuration |
| 87 | +SiftReactNative.setSiftConfig( |
| 88 | + 'your-account-id', // Account ID from Sift Console |
| 89 | + 'your-beacon-key', // Beacon Key from Sift Console |
| 90 | + true, // Disallow location collection (optional) |
| 91 | + 'https://api3.siftscience.com/v3/accounts/%s/mobile_events' // Server URL format |
| 92 | +); |
| 93 | +``` |
| 94 | + |
| 95 | +#### 3. Set User Context |
| 96 | + |
| 97 | +```typescript |
| 98 | +// Set user ID for tracking |
| 99 | +SiftReactNative.setUserId('user-123'); |
| 100 | + |
| 101 | +// Clear user ID when user logs out |
| 102 | +SiftReactNative.unsetUserId(); |
| 103 | +``` |
| 104 | + |
| 105 | +## API Reference |
| 106 | + |
| 107 | +### Methods |
| 108 | + |
| 109 | +#### `setSiftConfig(accountId, beaconKey, disallowCollectingLocationData, serverUrlFormat)` |
| 110 | + |
| 111 | +Initializes the Sift SDK with your account configuration. |
| 112 | + |
| 113 | +**Parameters:** |
| 114 | +- `accountId` (string): Your Sift account ID |
| 115 | +- `beaconKey` (string): Your Sift beacon key |
| 116 | +- `disallowCollectingLocationData` (boolean): Whether to disable location collection |
| 117 | +- `serverUrlFormat` (string): Custom server URL format (optional) |
| 118 | + |
| 119 | +**Example:** |
| 120 | +```typescript |
| 121 | +SiftReactNative.setSiftConfig( |
| 122 | + 'your-account-id', |
| 123 | + 'your-beacon-key', |
| 124 | + false, // Allow location collection |
| 125 | + 'https://api3.siftscience.com/v3/accounts/%s/mobile_events' |
| 126 | +); |
| 127 | +``` |
| 128 | + |
| 129 | +#### `setUserId(userId)` |
| 130 | + |
| 131 | +Associates the current session with a specific user ID. |
| 132 | + |
| 133 | +**Parameters:** |
| 134 | +- `userId` (string): Unique identifier for the user |
| 135 | + |
| 136 | +**Example:** |
| 137 | +```typescript |
| 138 | +SiftReactNative.setUserId('user-12345'); |
| 139 | +``` |
| 140 | + |
| 141 | +#### `unsetUserId()` |
| 142 | + |
| 143 | +Removes the user ID association from the current session. |
| 144 | + |
| 145 | +**Example:** |
| 146 | +```typescript |
| 147 | +SiftReactNative.unsetUserId(); |
10 | 148 | ``` |
11 | 149 |
|
| 150 | +#### `upload()` |
12 | 151 |
|
13 | | -## Usage |
| 152 | +Manually triggers data upload to Sift servers. |
14 | 153 |
|
| 154 | +**Example:** |
| 155 | +```typescript |
| 156 | +SiftReactNative.upload(); |
| 157 | +``` |
15 | 158 |
|
16 | | -```js |
17 | | -import { multiply } from 'sift-react-native'; |
| 159 | +#### `onHostResume()` |
18 | 160 |
|
19 | | -// ... |
| 161 | +Call this method when your app resumes from background. |
20 | 162 |
|
21 | | -const result = multiply(3, 7); |
| 163 | +**Example:** |
| 164 | +```typescript |
| 165 | +SiftReactNative.onHostResume(); |
22 | 166 | ``` |
23 | 167 |
|
| 168 | +#### `onHostPause()` |
| 169 | + |
| 170 | +Call this method when your app goes to background. |
24 | 171 |
|
25 | | -## Contributing |
| 172 | +**Example:** |
| 173 | +```typescript |
| 174 | +SiftReactNative.onHostPause(); |
| 175 | +``` |
26 | 176 |
|
27 | | -- [Development workflow](CONTRIBUTING.md#development-workflow) |
28 | | -- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request) |
29 | | -- [Code of conduct](CODE_OF_CONDUCT.md) |
| 177 | +## Usage Examples |
| 178 | + |
| 179 | +### Basic Integration |
| 180 | + |
| 181 | +```typescript |
| 182 | +import React, { useEffect } from 'react'; |
| 183 | +import SiftReactNative from 'sift-react-native'; |
| 184 | + |
| 185 | +const App = () => { |
| 186 | + useEffect(() => { |
| 187 | + // Initialize Sift when app starts |
| 188 | + SiftReactNative.setSiftConfig( |
| 189 | + 'your-account-id', |
| 190 | + 'your-beacon-key', |
| 191 | + false, // Allow location collection |
| 192 | + 'https://api3.siftscience.com/v3/accounts/%s/mobile_events' |
| 193 | + ); |
| 194 | + }, []); |
| 195 | + |
| 196 | + const handleUserLogin = (userId: string) => { |
| 197 | + SiftReactNative.setUserId(userId); |
| 198 | + SiftReactNative.upload(); |
| 199 | + }; |
| 200 | + |
| 201 | + const handleUserLogout = () => { |
| 202 | + SiftReactNative.unsetUserId(); |
| 203 | + }; |
| 204 | + |
| 205 | + return ( |
| 206 | + // Your app components |
| 207 | + ); |
| 208 | +}; |
| 209 | +``` |
30 | 210 |
|
31 | 211 | ## License |
32 | 212 |
|
33 | | -MIT |
| 213 | +MIT License - see [LICENSE](LICENSE) file for details. |
| 214 | + |
| 215 | +## Support |
| 216 | + |
| 217 | +For technical support and questions: |
| 218 | + |
| 219 | +- **Documentation**: [Sift Developer Docs](https://developers.sift.com) |
| 220 | +- **Issues**: [GitHub Issues](https://github.com/SiftScience/sift-react-native/issues) |
| 221 | +- **Email**: support@sift.com |
34 | 222 |
|
35 | 223 | --- |
36 | 224 |
|
37 | | -Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
| 225 | +Made with ❤️ by the Sift team |
0 commit comments