# Overview

The `flutter_ts_account_protection` is a Flutter plugin for Mosaic [Fraud Prevention](/guides/risk/overview) on Android and iOS.

When initialized, the plugin 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.

## Requirements

- Flutter 3.0.0 or higher
- iOS 13.0 or higher
- Android API level 24 (Android 7.0) or higher
- Dart 2.17.0 or higher


## Installation

Add the plugin to your `pubspec.yaml`:

```yaml
dependencies:
  flutter_ts_account_protection:
    git:
      url: https://github.com/TransmitSecurity/flutter_ts_account_protection.git
      ref: 1.0.0
```

Then run:

```bash
flutter pub get
```

## Platform configuration

Android
### build.gradle

Add the Transmit Security Maven repository to your module-level `android/build.gradle`:

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

In your `android/app/build.gradle`, set the minimum SDK version:

```gradle
android {
    compileSdkVersion 34
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 34
    }
}
```

### AndroidManifest.xml

Add to your `android/app/src/main/AndroidManifest.xml`:

```xml
<uses-permission android:name="android.permission.INTERNET" />
```

### 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
The iOS SDK requires iOS 13.0 or higher. The native SDK is included via Swift Package Manager—no additional configuration is required.

### TransmitSecurity.plist

Create a `TransmitSecurity.plist` file in `ios/Runner/`:

```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>clientId</key>
    <string>[CLIENT_ID]</string>
    <key>baseUrl</key>
    <string>https://api.transmitsecurity.io/risk-collect</string>
</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

Import the package and create an instance of the plugin:

```dart
import 'package:flutter_ts_account_protection/flutter_ts_account_protection.dart';

final accountProtection = FlutterTsAccountProtection();
```

**Simple initialization (using platform configuration files):**

```dart
await accountProtection.initializeSDK();
```

**With explicit parameters:**

```dart
await accountProtection.initialize(
  'YOUR_CLIENT_ID',
  'https://api.transmitsecurity.io/risk-collect/',
  configuration: TSInitSDKConfiguration(
    enableLocationEvents: true,
  ),
  userId: 'optional-user-id',
);
```

### initialize 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 above) |
| `configuration` | `TSInitSDKConfiguration?` | No | Optional configuration object (see below) |
| `userId` | `String?` | No | Set the user ID during initialization if already known |


**Configuration options:**

| Property | Type | Default | Description |
|  --- | --- | --- | --- |
| `enableLocationEvents` | `bool` | `false` | Enables reporting device location during plugin 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 [Flutter plugin quick start](/guides/risk/quick_start_flutter).