# Overview

The `cordova_ts_account_protection_plugin` is a Cordova 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

- Cordova CLI 12.0 or higher (tested with cordova-ios 8.x and cordova-android 14.x)
- iOS 13.0 or higher, Xcode 16 or higher
- Android API level 24 (Android 7.0) or higher
- Node.js LTS


## Installation

Add the plugin to your project from the published plugin repository:

```bash
cordova plugin add https://github.com/TransmitSecurity/cordova_ts_account_protection_plugin.git#v0.1.0
cordova platform add ios android
cordova prepare ios android
```

On iOS, the plugin resolves the native Fraud Prevention SDK through Swift Package Manager. On Android, it pulls the SDK from the Transmit Security Maven repository.

## Platform configuration

Android
The plugin adds the `INTERNET`, `ACCESS_NETWORK_STATE`, and `ACCESS_FINE_LOCATION` permissions to the manifest and resolves the Fraud Prevention SDK from the Transmit Security Maven repository.

### strings.xml

Add your credentials to `res/values/strings.xml`:

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

iOS
The native SDK is included via Swift Package Manager and is resolved by Xcode on the first build.

### TransmitSecurity.plist

Create a `TransmitSecurity.plist` file and add it to your iOS app:

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

Reference the plist in `config.xml`:

```xml
<platform name="ios">
    <preference name="deployment-target" value="13.0" />
    <resource-file src="resources/ios/TransmitSecurity.plist" target="TransmitSecurity.plist" />
</platform>
```

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

The plugin exposes the `cordova.drs` object once the `deviceready` event has fired.

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

```javascript
document.addEventListener('deviceready', function () {
  cordova.drs.initializeSDK();
});
```

**With explicit parameters:**

```javascript
cordova.drs.initialize(
  '[CLIENT_ID]',
  'https://api.transmitsecurity.io/risk-collect/',
  { enableLocationEvents: true },
  null // optional userId
);
```

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


**Options object:**

| Property | Type | Default | Description |
|  --- | --- | --- | --- |
| `enableLocationEvents` | `boolean` | `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 [Cordova plugin quick start](/guides/risk/quick_start_cordova).