SDK Initialization¶
This article covers the initialization of the Flutter SDK and its runtime capabilities.
Basic Configuration¶
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Local environment deployment, Datakit deployment
await FTMobileFlutter.sdkConfig(
datakitUrl: datakitUrl,
);
// Using public network DataWay
await FTMobileFlutter.sdkConfig(
datawayUrl: datawayUrl,
cliToken: cliToken,
);
}
| Field | Type | Required | Description |
|---|---|---|---|
| datakitUrl | String | Yes | The reporting URL address for local environment deployment (Datakit). Example: http://10.0.0.1:9529, default port is 9529. The device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl |
| datawayUrl | String | Yes | The reporting URL address for public network DataWay. Obtain it from the [RUM] application. Example: https://open.dataway.url. The device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl |
| cliToken | String | Yes | Authentication token, must be configured together with datawayUrl |
| debug | bool | No | Sets whether to allow log printing, default is false |
| env | String | No | Environment configuration, default is prod. Any string, recommended to use a single word, e.g., test |
| envType | enum EnvType | No | Environment configuration, default is EnvType.prod. Note: Configure only one of env and envType |
| autoSync | bool | No | Whether to automatically sync collected data to the server, default is true. When false, use FTMobileFlutter.flushSyncData() to manage data synchronization manually |
| syncPageSize | enum | No | Sets the number of entries per sync request. SyncPageSize.mini 5 entries, SyncPageSize.medium 10 entries, SyncPageSize.large 50 entries, default is SyncPageSize.medium |
| customSyncPageSize | number | No | Sets the number of entries per sync request, range [5, ). Larger number means data synchronization consumes more computing resources |
| syncSleepTime | number | No | Sets the sync interval time, range [0,5000], default is not set |
| globalContext | object | No | Adds custom tags. For addition rules, refer to Conflict Field Description |
| serviceName | String | No | Service name |
| customHttpOverrides | HttpOverrides | No | Custom HTTP Overrides. When HTTP auto-collection is enabled, if the project has already customized HttpOverrides.global, pass the custom implementation via this parameter. The SDK will reuse this implementation in the collection pipeline |
| enableLimitWithDbSize | boolean | No | Enable using DB to limit data size, default 100MB, unit Byte, default is off. When enabled, logCacheLimitCount and rumCacheLimitCount will become invalid. Supported from SDK version 0.5.3-pre.2 |
| dbCacheLimit | number | No | DB cache limit size, range [30MB, ), default 100MB, unit byte, supported from SDK version 0.5.3-pre.2 |
| dbCacheDiscard | string | No | Sets the data discard rule in the database. FTDBCacheDiscard.discard discards new data (default), FTDBCacheDiscard.discardOldest discards old data. Supported from SDK version 0.5.3-pre.2 |
| enableLimitWithCacheSize | boolean | No | Enable using cache size to limit data size. Android uses total cache size limit; iOS maps to DB cache size limit. When enabled, cacheLimit is used first; if not set, dbCacheLimit is used for compatibility |
| cacheLimit | number | No | Cache limit size, unit byte. Corresponds to total cache size on Android; corresponds to DB cache limit on iOS |
| cacheDiscard | enum FTCacheDiscard | No | Sets the cache data discard rule. Android uses cache discard policy; iOS maps to 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 enabling FileStore |
| fileDataStoreShadow | boolean | No | Android: Whether to synchronously write to FileStore when using SQLite read path |
| compressIntakeRequests | boolean | No | Deflate compression for upload sync data, supported from SDK version 0.5.3-pre.2, default is off |
| enableDataIntegerCompatible | boolean | No | Recommended to enable when coexisting with Web data, used to handle Web data type storage compatibility issues. Default enabled from version 0.5.4-pre.1 |
| dataModifier | Map |
No | Modifies a single field. For usage examples, see Data Collection Desensitization |
| lineDataModifier | Map |
No | Modifies a single piece of data. For usage examples, see Data Collection Desensitization |
| enableDataFilter | boolean | No | Whether to enable SDK-side DataKit compatible filtering rules. Default follows native SDK configuration |
| dataFilters | Map |
No | Local DataKit compatible filtering rules, grouped by data type, currently supports logging and rum |
| enableRemoteConfiguration | boolean | No | Whether to enable remote configuration. When enabled, the SDK will fetch remote configuration at configured intervals and apply it to the current runtime |
| remoteConfigMiniUpdateInterval | number | No | Minimum update interval for remote configuration, must be used with enableRemoteConfiguration |
| remoteConfigOverrideRules | List | No | Remote configuration local override rules, used for debugging or overriding remote configuration results in specific scenarios |
| iOSGroupIdentifiers | List |
No | iOS App Group identifier list, used for sharing cache data between Extension and main App |
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 ext addition rules, refer to Conflict Field Description.
Runtime Capabilities¶
Actively Sync Data¶
Manual data synchronization is only required when
autoSync: false.