# Functions

## initializeSDK

▸ **initializeSDK**(): `Future`<`bool`>

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

### Returns

`Future`<`bool`>

Indicates if initialization succeeded.

### Example

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

final accountProtection = FlutterTsAccountProtection();
await accountProtection.initializeSDK();
```

## initialize

▸ **initialize**(`clientId`, `baseUrl`, `{configuration, userId}`): `Future`<`bool`>

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 Transmit Security client identifier |
| `baseUrl` | `String` | API base URL for your environment |
| `configuration` | [`TSInitSDKConfiguration?`](/sdk-ref/flutter-ts-accountprotection/interfaces/tsinitsdkconfiguration) | Optional configuration for location tracking |
| `userId` | `String?` | Optional user ID to set during initialization |


### Returns

`Future`<`bool`>

Indicates if initialization succeeded.

### Example

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

final accountProtection = FlutterTsAccountProtection();
await accountProtection.initialize(
  'YOUR_CLIENT_ID',
  'https://api.transmitsecurity.io/risk-collect/',
  configuration: TSInitSDKConfiguration(
    enableLocationEvents: true,
  ),
  userId: 'user-123',
);
```

## triggerAction

▸ **triggerAction**(`action`, `{options, locationConfig, customAttributes}`): `Future`<[`TSSetActionResponse`](/sdk-ref/flutter-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 failure—check `result.success` and use `result.actionToken` when successful.

### Parameters

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


### Returns

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

### Example

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

final accountProtection = FlutterTsAccountProtection();

final response = await accountProtection.triggerAction(
  TSAction.login.name,
  options: TSActionEventOptions(
    correlationId: 'CORRELATION_ID',
    claimedUserId: '91e25bea0c...', // hashed email
    claimedUserIdType: TSClaimedUserIdType.email,
    referenceUserId: 'REFERENCE_USER_ID',
  ),
  locationConfig: TSLocationConfig(mode: 'default'),
  customAttributes: {'userLevel': 'premium'},
);
final actionToken = response.actionToken;
```

## setAuthenticatedUser

▸ **setAuthenticatedUser**(`userId`, `{options}`): `Future`<`bool`>

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, this call requires a foreground Activity—call it after the app UI is running, not during early startup.

### Parameters

| Name | Type | Description |
|  --- | --- | --- |
| `userId` | `String` | Opaque identifier of the user in your system |
| `options` | `Map<String, dynamic>?` | Optional user attributes |


### Returns

`Future`<`bool`>

Indicates if the call succeeded.

### Example

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

final accountProtection = FlutterTsAccountProtection();
await accountProtection.setAuthenticatedUser('user-123');
```

## clearUser

▸ **clearUser**(): `Future`<`bool`>

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

`Future`<`bool`>

Indicates if the call succeeded.

### Example

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

final accountProtection = FlutterTsAccountProtection();
await accountProtection.clearUser();
```

## getSessionToken

▸ **getSessionToken**(): `Future`<`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

`Future`<`String`>

The session token.

### Example

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

final accountProtection = FlutterTsAccountProtection();
final sessionToken = await accountProtection.getSessionToken();
```

## logPageLoad

▸ **logPageLoad**(`pageName`): `Future`<`bool`>

Tracks screen navigation events for behavioral data collection. For automatic page-load tracking, use the built-in `DrsCore.navigationObserver` instead (see [quick start](/guides/risk/quick_start_flutter#step-5-wire-navigation-observer)). Use `logPageLoad` only if you need to report navigation events manually.

### Parameters

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


### Returns

`Future`<`bool`>

Indicates if the call succeeded.

### Example

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

final accountProtection = FlutterTsAccountProtection();
await accountProtection.logPageLoad('LoginScreen');
await accountProtection.logPageLoad('Dashboard');
```

## setLogLevel

▸ **setLogLevel**(`isLogEnabled`): `Future`<`bool`>

Enables or disables verbose plugin logging for debugging purposes.

### Parameters

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


### Returns

`Future`<`bool`>

Indicates if the call succeeded.

### Example

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

final accountProtection = FlutterTsAccountProtection();
await accountProtection.setLogLevel(true); // Enable for debugging
await accountProtection.setLogLevel(false); // Disable for production
```

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