# Functions

All methods are exposed on the `cordova.drs` object, which becomes available once the `deviceready` event has fired.

## initializeSDK

▸ **initializeSDK**(): `Promise`<`void`>

Initializes the plugin using platform-specific configuration files (`TransmitSecurity.plist` on iOS, `strings.xml` values on Android). This is the recommended initialization approach.

### Returns

`Promise`<`void`>

Resolves when initialization succeeds and rejects on failure (missing configuration or SDK error).

### Example

```javascript
document.addEventListener('deviceready', function () {
  cordova.drs.initializeSDK()
    .then(function () {
      console.log('Fraud Prevention SDK initialized');
    })
    .catch(function (err) {
      console.error(err.code, err.message);
    });
});
```

## initialize

▸ **initialize**(`clientId`, `baseUrl`, `options?`, `userId?`): `Promise`<`void`>

Initializes the plugin with explicit parameters. Use this when you need to provide credentials programmatically instead of relying on platform configuration files.

### Parameters

| Name | Type | Description |
|  --- | --- | --- |
| `clientId` | `string` | Your client identifier |
| `baseUrl` | `string` | API base URL for your environment |
| `options?` | [`TSInitSDKConfiguration`](/sdk-ref/cordova-ts-accountprotection/interfaces/tsinitsdkconfiguration) | Optional configuration for location tracking |
| `userId?` | `string` | Optional user ID to set during initialization |


### Returns

`Promise`<`void`>

Resolves when initialization succeeds and rejects on failure.

### Example

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

## triggerAction

▸ **triggerAction**(`action`, `options?`, `locationConfig?`, `customAttributes?`): `Promise`<[`TSSetActionResponse`](/sdk-ref/cordova-ts-accountprotection/interfaces/tssetactionresponse)>

Reports a user action event and returns an action token. The action token should be passed to your backend to fetch risk recommendations via the [Recommendation API](/openapi/risk/recommendations.openapi/other/getriskrecommendation). This method does not throw on SDK rejection—check `result.success` and use `result.actionToken` when successful.

### Parameters

| Name | Type | Description |
|  --- | --- | --- |
| `action` | `string` | The type of user action to report (see [`TSAction`](/sdk-ref/cordova-ts-accountprotection/enums/tsaction) values) |
| `options?` | [`TSActionEventOptions`](/sdk-ref/cordova-ts-accountprotection/interfaces/tsactioneventoptions) | Additional context for the action event |
| `locationConfig?` | [`TSLocationConfig`](/sdk-ref/cordova-ts-accountprotection/interfaces/tslocationconfig) | Controls location data collection for this action (see [Track geolocation](/guides/risk/report_geolocation)) |
| `customAttributes?` | `Object` | Additional contextual data for the action; must match the schema defined in the Portal (see [Custom attributes](/guides/risk/action-attributes)) |


### Returns

`Promise`<[`TSSetActionResponse`](/sdk-ref/cordova-ts-accountprotection/interfaces/tssetactionresponse)>

### Example

```javascript
cordova.drs.triggerAction(
  'login',
  {
    correlationId: 'CORRELATION_ID',
    claimedUserId: '91e25bea0c...', // hashed email
    claimedUserIdType: 'email'
  },
  { mode: 'default' },
  { userLevel: 'premium' }
).then(function (result) {
  if (result.success) {
    console.log('Action Token:', result.actionToken);
  }
});
```

## setAuthenticatedUser

▸ **setAuthenticatedUser**(`userId`, `options?`): `Promise`<`boolean`>

Sets the user context for all subsequent events in the session (or until the user is explicitly cleared). It should be called only after you've fully authenticated the user (including, for example, any 2FA that was required). On Android, call this after the WebView activity is visible.

### Parameters

| Name | Type | Description |
|  --- | --- | --- |
| `userId` | `string` | Opaque identifier of the user in your system |
| `options?` | `Object` | Optional user attributes |


### Returns

`Promise`<`boolean`>

Indicates if the call succeeded.

### Example

```javascript
await cordova.drs.setAuthenticatedUser('user-123', {
  loginMethod: 'password',
  email: 'user@example.com'
});
```

## clearUser

▸ **clearUser**(): `Promise`<`boolean`>

Clears the user context for all subsequent events in the mobile session. The user is automatically cleared once the session expires or in case of a new login action.

### Returns

`Promise`<`boolean`>

Indicates if the call succeeded.

### Example

```javascript
await cordova.drs.clearUser();
```

## getSessionToken

▸ **getSessionToken**(): `Promise`<`string`>

Returns a device session token that can be used to trigger action events via the [Backend API](/guides/risk/quick_start_backendapi). The session token binds user interactions to their device and is required for backend integrations. Call this after plugin initialization and before triggering events.

### Returns

`Promise`<`string`>

The session token.

### Example

```javascript
const sessionToken = await cordova.drs.getSessionToken();
```

## logPageLoad

▸ **logPageLoad**(`pageName`): `Promise`<`void`>

Reports a page-load event for behavioral data collection. The plugin tracks WebView navigation automatically, so use this method only when your app uses a custom SPA router and you want to report explicit page names.

### Parameters

| Name | Type | Description |
|  --- | --- | --- |
| `pageName` | `string` | The name of the screen or page the user navigated to |


### Returns

`Promise`<`void`>

### Example

```javascript
await cordova.drs.logPageLoad('Dashboard');
```

## setLogLevel

▸ **setLogLevel**(`isLogEnabled`): `Promise`<`void`>

Enables or disables verbose plugin logging for debugging purposes.

### Parameters

| Name | Type | Description |
|  --- | --- | --- |
| `isLogEnabled` | `boolean` | Set to `true` to enable debug logging |


### Returns

`Promise`<`void`>

### Example

```javascript
await cordova.drs.setLogLevel(true);
```

style
table th:first-of-type {
    width: 30%;
}
table th:nth-of-type(2) {
    width: 30%;
}
table th:nth-of-type(3) {
    width: 40%;
}