# Overview

The `react-native-ts-accountprotection` is a React Native module for Mosaic [Fraud Prevention](/guides/risk/overview) on Android and iOS.

When initialized, the module automatically starts collecting and submitting telemetry data to Mosaic—including information about the user journey, device data, and user interactions. Once specific user actions are performed on the client side (such as login), Fraud Prevention should be called to track those action events and obtain action tokens. The data collected can then be queried for recommendations using the [Recommendations](/openapi/risk/recommendations.openapi) backend API.

## Installation

Install the module from npm:


```bash
npm install react-native-ts-accountprotection
```

## Platform configuration

Android
### build.gradle

In your `app/build.gradle` file, add the following:


```gradle
repositories {
  google()
  maven {
    url 'https://transmit.jfrog.io/artifactory/transmit-security-gradle-release-local/'
  }
}

dependencies {
  implementation "com.ts.sdk:accountprotection:3.+"
}
```

### strings.xml

Update your `strings.xml` file with your credentials:


```xml
<resources>
    <string name="transmit_security_client_id">"CLIENT_ID"</string>
    <string name="transmit_security_base_url">https://api.transmitsecurity.io/risk-collect/</string>
</resources>
```

iOS
### CocoaPods

Navigate to your iOS project directory and run `pod install`.

### TransmitSecurity.plist

Create a `TransmitSecurity.plist` file in your native iOS Xcode project:


```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>credentials</key>
    <dict>
        <key>baseUrl</key>
        <string>https://api.transmitsecurity.io/risk-collect/</string>
        <key>clientId</key>
        <string>[CLIENT_ID]</string>
    </dict>
</dict>
</plist>
```

Use the appropriate base URL for your environment:

| Environment | Base URL |
|  --- | --- |
| US | `https://api.transmitsecurity.io/risk-collect/` |
| EU | `https://api.eu.transmitsecurity.io/risk-collect/` |
| Canada | `https://api.ca.transmitsecurity.io/risk-collect/` |
| Australia | `https://api.au.transmitsecurity.io/risk-collect/` |
| Custom domain | `https://<your_custom_domain>/risk-collect/` |


## Initialization

Android
On Android, the SDK is initialized in the native layer. Open your `MainApplication.kt` file and add:


```kotlin
import com.transmit.accountprotection.TSAccountProtection

class MainApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    TSAccountProtection.initializeSDK(this.applicationContext)
  }
}
```

iOS
On iOS, the SDK can be initialized from the React Native layer or the native layer.

**From React Native (using plist configuration):**


```javascript
import React, { useEffect } from 'react';
import { Platform } from 'react-native';
import { initializeSDKIOS } from 'react-native-ts-accountprotection';

function App() {
  useEffect(() => {
    if (Platform.OS === 'ios') {
      initializeSDKIOS();
    }
  }, []);

  // ...
}
```

**From React Native (with explicit parameters):**


```javascript
import React, { useEffect } from 'react';
import { Platform } from 'react-native';
import { initializeIOS } from 'react-native-ts-accountprotection';

function App() {
  useEffect(() => {
    if (Platform.OS === 'ios') {
      initializeIOS(
        'YOUR_CLIENT_ID', // Required
        'https://api.transmitsecurity.io/risk-collect/', // Required
        {
          enableTrackingBehavioralData: true, // Optional. Defaults to true
          enableLocationEvents: true // Optional. Defaults to false
        },
        'optional-user-id' // Optional: Set user ID during initialization
      );
    }
  }, []);

  // ...
}
```

### initializeIOS parameters

| Parameter | Type | Required | Description |
|  --- | --- | --- | --- |
| `clientId` | `string` | Yes | Your client ID from the Admin Portal |
| `baseUrl` | `string` | Yes | The base URL for your environment (see table below) |
| `options` | `object` | No | Optional configuration object (see below) |
| `userId` | `string` | No | Set the user ID during initialization if already known |


Use the appropriate base URL for your environment:

| Environment | Base URL |
|  --- | --- |
| US | `https://api.transmitsecurity.io/risk-collect/` |
| EU | `https://api.eu.transmitsecurity.io/risk-collect/` |
| Canada | `https://api.ca.transmitsecurity.io/risk-collect/` |
| Australia | `https://api.au.transmitsecurity.io/risk-collect/` |
| Custom domain | `https://<your_custom_domain>/risk-collect/` |


**Options object:**

| Property | Type | Default | Description |
|  --- | --- | --- | --- |
| `enableTrackingBehavioralData` | `boolean` | `true` | Enables collection of behavioral data such as user interactions and navigation patterns |
| `enableLocationEvents` | `boolean` | `false` | Enables reporting device location during SDK initialization and when the app moves to the foreground. The user must consent to sharing location in advance (see [Track geolocation](/guides/risk/report_geolocation)). |


## Next steps

For a complete end-to-end integration walkthrough, see the [React Native module quick start](/guides/risk/quick_start_react_native).