getInstance static method
Future<ThinkingAnalyticsAPI>
getInstance(
- String appId,
- String serverUrl, {
- String? timeZone,
- ThinkingAnalyticsMode? mode,
- bool? enableEncrypt,
- TASecretKey? secretKey,
Gets instance of ThinkingAnalyticsAPI.
The sdk in native will be initialized with appId
and serverUrl
. The appId
is the APP ID of your project. The
serverUrl
is your own receiver's url. In case of using TA SaaS, the serverUrl
is https://receiver.ta.thinkingdata.cn.
By default, the event time will be serialized using device TimeZone. You can pass a named parameter timeZone
to specify the
default TimeZone in native SDK. The value of timeZone
must be a valid time zone name like: 'UTC', 'Asia/Shanghai', etc.
In addition, you can pass a mode
to set the SDK mode. By default, the mode will be set to ThinkingAnalyticsMode.NORMAL.
NOTE:
- DO NOT use ThinkingAnalyticsMode.DEBUG or ThinkingAnalyticsMode.DEBUG_ONLY in online App.
- The DEBUG mode could not be enabled unless you set your device ID in TA server.
Implementation
static Future<ThinkingAnalyticsAPI> getInstance(
String appId, String serverUrl,
{String? timeZone,
ThinkingAnalyticsMode? mode,
bool? enableEncrypt,
TASecretKey? secretKey}) async {
Map<String, dynamic> config = <String, dynamic>{
'appId': appId,
'serverUrl': serverUrl
};
if (null != timeZone) {
config['timeZone'] = timeZone;
}
if (null != mode) {
config['mode'] = mode.index;
}
config['lib_version'] = _libVersion;
if (null != secretKey) {
config['secretKey'] = {
'publicKey': secretKey.publicKey,
'version': secretKey.version,
'symmetricEncryption': secretKey.symmetricEncryption,
'asymmetricEncryption': secretKey.asymmetricEncryption
};
}
if (null != enableEncrypt) {
config['enableEncrypt'] = enableEncrypt;
}
await _channel.invokeMethod<int>('getInstance', config);
return ThinkingAnalyticsAPI.private(appId);
}