SDK Initialization¶
This document covers Flutter SDK initialization and runtime capabilities.
Basic Configuration¶
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Local environment deployment, DataKit deployment
await FTMobileFlutter.sdkConfig(
datakitUrl: datakitUrl,
);
// Use public DataWay
await FTMobileFlutter.sdkConfig(
datawayUrl: datawayUrl,
cliToken: cliToken,
);
}
| Field | Type | Required | Description |
|---|---|---|---|
| datakitUrl | String | No | Reporting URL for local environment deployment (DataKit). Example: http://10.0.0.1:9529. The default port is 9529. Devices with the SDK installed must be able to access this address. Note: When setting the reporting address, set either datakitUrl or datawayUrl, not both. Starting from SDK 0.5.8, you can leave it unset and configure it later using a runtime method. |
| datawayUrl | String | No | Public DataWay reporting URL, obtained from the [Real User Monitoring (RUM)] app. Example: https://open.dataway.url. Devices with the SDK installed must be able to access this address. Note: When setting the reporting address, set either datakitUrl or datawayUrl, not both. Starting from SDK 0.5.8, you can leave it unset and configure it later using a runtime method. |
| cliToken | String | Required when using DataWay | Authentication token. It must be configured together with datawayUrl. When setting the address later, set it together via setDatawayURL(datawayUrl, cliToken). |
| debug | bool | No | Whether to allow log printing. Default: false. |
| env | String | No | Environment configuration. Default: prod. Any characters are allowed; a single word is recommended, for example test. |
| envType | enum EnvType | No | Environment configuration. Default: EnvType.prod. Note: Configure only one of env and envType. |
| autoSync | bool | No | Whether to automatically sync data to the server after collection. Default: true. When set to false, use FTMobileFlutter.flushSyncData() to manage data synchronization yourself. |
| syncPageSize | enum | No | Set the number of entries per sync request. SyncPageSize.mini: 5 entries, SyncPageSize.medium: 10 entries, SyncPageSize.large: 50 entries. Default: SyncPageSize.medium. |
| customSyncPageSize | number | No | Set the number of entries per sync request. Range: [5, ). A larger number of request entries means data synchronization consumes more computing resources. |
| syncSleepTime | number | No | Set the sync interval. Range: [0,5000]. Not set by default. |
| globalContext | object | No | Add custom tags. For addition rules, see Field Conflict Description. |
| serviceName | String | No | Service name. |
| customHttpOverrides | HttpOverrides | No | Custom HTTP Overrides. When HTTP automatic collection is enabled, if the project has already customized HttpOverrides.global, you can pass the custom implementation through this parameter. The SDK reuses this implementation in the collection pipeline. |
| enableLimitWithDbSize | boolean | No | Enable using the DB to limit data size. Default: 100 MB, in bytes; disabled by default. When enabled, logCacheLimitCount and rumCacheLimitCount become invalid. Supported in SDK 0.5.3-pre.2 and later. |
| dbCacheLimit | number | No | DB cache limit size. Range: [30MB, ). Default: 100 MB, in bytes. Supported in SDK 0.5.3-pre.2 and later. |
| dbCacheDiscard | string | No | Set the data discard rule in the database. FTDBCacheDiscard.discard discards new data (default); FTDBCacheDiscard.discardOldest discards old data. Supported in SDK 0.5.3-pre.2 and later. |
| enableLimitWithCacheSize | boolean | No | Enable using cache size to limit data size. Android uses the total cache size limit; iOS maps this to the DB cache size limit. When enabled, cacheLimit takes precedence; if it is not set, dbCacheLimit is used for compatibility. |
| cacheLimit | number | No | Cache limit size, in bytes. On Android, this corresponds to the total cache size; on iOS, it corresponds to the DB cache limit. |
| cacheDiscard | enum FTCacheDiscard | No | Set the cache data discard rule. Android uses the cache discard policy; iOS maps this to the DB data discard rule. FTCacheDiscard.discard discards new data (default); FTCacheDiscard.discardOldest discards old data. |
| enableFileDataStore | boolean | No | Android: Whether to enable FileStore file caching. |
| needTransformOldCache | boolean | No | Android: Whether to migrate old SQLite cache data when FileStore is enabled. |
| fileDataStoreShadow | boolean | No | Android: Whether to write to FileStore synchronously when using the SQLite read path. |
| compressIntakeRequests | boolean | No | Compress uploaded sync data using deflate. Supported in SDK 0.5.3-pre.2 and later. Enabled by default starting from SDK 0.5.7 and disabled by default before that; set to false to disable. |
| enableDataIntegerCompatible | boolean | No | Recommended when data needs to coexist with Web data. Used to handle Web data type storage compatibility issues. Enabled by default in 0.5.4-pre.1 and later. |
| dataModifier | Map<String,Object> |
No | Modify a single field. For usage examples, see Data Masking. |
| lineDataModifier | Map<String,Map<String,Object>> |
No | Modify a single data record. For usage examples, see Data Masking. |
| enableDataFilter | bool | No | Whether to enable SDK-side blacklist filtering. Default: true. Supports filtering Log and RUM data. Supported in SDK 0.5.7 and later. For usage examples, see Blacklist Filtering. |
| dataFilters | Map<String,List<String>> |
No | Configure in-app blacklist rules. Supports logging and rum data types. Supported in SDK 0.5.7 and later. For rule syntax, see Rule Syntax. |
| enableRemoteConfiguration | bool | No | Whether to enable remote configuration. When enabled, the SDK attempts to pull configuration during automatic updates or active calls, and the call frequency is limited by the minimum update interval. See Dynamic Configuration for details. |
| remoteConfigMiniUpdateInterval | int | No | Minimum update interval for remote configuration, in seconds. Default: 12 hours. Requires enabling enableRemoteConfiguration. See Actively Sync Dynamic Configuration for details. |
| allowWebViewHost | List<String> |
No | List of Hosts allowed for WebView data collection, shared by RUM and Log. When not set, all Hosts are allowed by default; an empty list means no Hosts are allowed. Priority: remote configuration > this basic configuration > legacy RUM configuration entry. Supported starting from SDK 0.5.8. See WebView Data Monitoring for details. |
| remoteConfigOverrideRules | List<Map<String, Object?>> |
No | Local override rules for remote configuration. Adjust the final configuration according to custom environment variables returned by the server. |
| iOSGroupIdentifiers | List<String> |
No | List of iOS App Group identifiers, used for sharing cached data between the Extension and the main app. |
To set the reporting address later or switch it dynamically, see Dynamically Update the Reporting Address.
For how to enable and update it, see Remote Configuration. For supported fields, see Flutter Remote Configuration Fields.
Blacklist Filtering¶
Flutter SDK 0.5.7 and later supports filtering RUM and Log data before data is written to the local cache. This capability is enabled by default. You can disable SDK-side filtering with enableDataFilter: false.
Blacklist rules can be configured centrally in the blacklist of a Guance workspace and automatically pulled by the SDK from DataKit or DataWay. You can also configure them in the app via FTMobileFlutter.sdkConfig(dataFilters: ...). Both methods use the same blacklist filtering capability and can be used together. If any rule matches, the data record is discarded.
Blacklist filtering is executed after lineDataModifier and before the local cache write. If both lineDataModifier and blacklist filtering are configured, filtering rules are evaluated against the modified data.
enableDataFilteronly controls rule pulling and filtering on the SDK side. When set tofalse, the SDK no longer appliesdataFiltersor pulls workspace rules. When reporting through DataKit, the workspace blacklist may still be enforced on the DataKit side.Data Filter applies to the SDK data write pipeline. Too many rules or overly complex regular expressions may affect data write performance. Configure only necessary rules.
await FTMobileFlutter.sdkConfig(
datawayUrl: datawayUrl,
cliToken: cliToken,
enableDataFilter: true,
dataFilters: {
'logging': [
"{ source in [ 'df_rum_ios_log', 'df_rum_android_log' ] and message match [ 'timeout' ] }",
],
'rum': [
"{ resource_status match [ '5..' ] }",
],
},
);
The SDK pulls workspace blacklist rules immediately during initialization. Subsequent pull intervals are based on the pull_interval returned by the server. If the server does not return a valid value, the SDK uses 10 seconds as the fallback interval. pull_interval supports seconds or strings with units, for example 10, 30s, 2m, and 1h.
Rule Syntax¶
The Data Filter rule syntax is basically the same as the blacklist filtering rule syntax. For the complete syntax, see Blacklist Filtering Rules.
The key of dataFilters indicates the data category. The SDK currently supports:
| Category | Description |
|---|---|
logging |
Log data |
rum |
RUM data |
Each rule is expressed as { condition }. If any rule matches, data in that category is filtered. Rules can use the data tag and field fields, as well as the source and measurement data type identifier fields.
For field value formats and operator semantics, see Field Value Format Description and Operator Description in the blacklist filtering rules.
Use the array format for field values in SDK rule strings. Negative operators support not in and not match, and are also compatible with notin, notmatch, and not_in used by server-delivered rules.
User Information Binding and Unbinding¶
Usage¶
/// Bind user
///
/// [userid] User ID
/// [userName] Username
/// [userEmail] User email
/// [userExt] Extended data
static Future<void> bindRUMUserData(String userId,
{String? userName, String? userEmail, Map<String, String>? ext})
/// Unbind user
static Future<void> unbindRUMUserData()
Code Example¶
For rules for adding ext, see Field Conflict Description.
Runtime Capabilities¶
Actively Sync Data¶
You need to manage data synchronization yourself only when
autoSync: false.
Shutdown and Reinitialization¶
Starting from Core SDK 0.5.8 and Session Replay SDK 0.1.1, shutting down the base SDK waits for the integrated Flutter Session Replay to complete cleanup.
Always use FTMobileFlutter.shutDown() to shut down the SDK. It can also be used when Session Replay is not installed. After the returned Future<void> completes, perform subsequent reinitialization operations.
If you need to continue collecting data after shutdown, call FTMobileFlutter.sdkConfig(...) again and configure the required RUM, Log, and Trace settings. When using Session Replay, you also need to call FTSessionReplayManager().setConfig(...) again and ensure that the view to be recorded is wrapped by SessionReplayCapture. Session Replay APIs are imported from the separate package ft_session_replay_flutter.