Integrated Documentation (Flutter plugin)
|
Collect
- Before using, please readdata model、Android SDK Using Guideand iOS SDK Using Guide
- Flutter plugin update log, see Release Notes
- Flutter Full Tracking update log, see Release Notes
1. Integration of Sensors Analytics SDK Flutter plugin
1.1. import plugin
In Flutter project pubspec.yaml file dependencies add sensors_analytics_flutter_plugin dependencies.
dependencies: # 添加神策 flutter plugin sensors_analytics_flutter_plugin: ^2.3.0
Excute flutter pub get Command install plugin.
flutter pub get
Dependencies between the SDK versions of the Flutter plugin and Android and iOS:
Flutter plugin version | Android available SDK version range | Range of available SDK versions for iOS |
---|---|---|
v2.3.0 <= Flutter plugin version | v6.6.0 <= SDK version | v4.5.0 <= SDK version |
v2.2.0 <= Flutter plugin version <=v2.2.2 | v6.5.1 <= SDK version <= v6.5.5 | v4.4.6 <= SDK version <= v4.4.8 |
v2.1.0 <= Flutter plugin version <=v2.1.1 | v6.0.0 <= SDK version <= v6.5.0 | v4.0.0 <= SDK version <= v4.4.5 |
v1.0.5 <= Flutter plugin version <=v2.0.4 | v4.4.0 <= SDK version <= v5.4.7 | v2.1.17 <= SDK version <= v3.1.9 |
v1.0.0 <= Flutter plugin version <=v1.0.4 | SDK version <= v4.3.7 | SDK version <= v2.1.15 |
2. Flutter plugin initialization
2.1. Get project data receiving URL
- Each project has a separate data receiving URL
- Please use the administrator account to obtain the data receiving URL for the respective project
2.2. Initialize SDK
Starting from Flutter plugin v2.1.0, initialization is supported on the Flutter side. The following is an example:
SensorsAnalyticsFlutterPlugin.init( serverUrl: "<#数据接收地址#>", autoTrackTypes: <SAAutoTrackType>{ SAAutoTrackType.APP_START, SAAutoTrackType.APP_VIEW_SCREEN, SAAutoTrackType.APP_CLICK, SAAutoTrackType.APP_END }, enableLog: true, visualized: VisualizedConfig(autoTrack: true, properties: true), android: AndroidConfig(maxCacheSize: 32 * 1024 * 1024, jellybean: true, subProcessFlush: true), ios: IOSConfig(maxCacheSize: 10000));
Note: Normally, initialization only needs to be done once on the native side or the Flutter side. If you choose to initialize on the Flutter side, there is no need to initialize again on the native side.
2.2.1. Explanation of init() method parameters
Parameter type | Parameter description | Parameter description | Remark |
---|---|---|---|
serverUrl | String? | Data Receiving URL | |
enableLog | bool | Whether to display logs | |
autoTrackTypes | Set<SAAutoTrackType>? | Full-track collection types |
Note: Currently only effective for native, not for Flutter full-track! |
flushInterval | int | Set minimum interval between two event reports | Default is 15 seconds, minimum is 5 seconds, in milliseconds |
flushBulksize | int | Set the maximum number of entries that trigger a flush in the local cache | Default is 100, minimum is 50 |
networkTypes | Set<SANetworkType>? | Set the reported network conditions | TYPE_NONE, TYPE_2G, TYPE_3G, TYPE_4G, TYPE_WIFI, TYPE_5G, TYPE_ALL |
encrypt | bool | Enable encryption | Only support RSA + AES |
javaScriptBridge | bool | Support H5 bridging | Default is false |
android | AndroidConfig? | Android-specific Configuration
| android:{ |
ios | IOSConfig? | iOS-specific Configuration
| ios:{ |
visualized | VisualizedConfig? | Visualization-related Configuration
| visualized{ |
heatMap | bool | Click map switch Click analysis configuration, Flutter does not currently support click analysis, this configuration will affect Native, convenient for delayed initialization of mixed compilation projects | Default false Note: Flutter currently does not support these operations and only works for native |
globalProperties | Map? | Configure global common properties | Its priority is lower than static common properties |
- If the App has compliance requirements, please refer to Compliance Description;
- The above is initialized in the Flutter code. The old version of the plugin does not support this initialization method. If you need to initialize on the native side, please refer to the Android SDK User Guide and iOS SDK User Guide.
3. Configure Scheme
3.1. Get the project Scheme
- The Scheme of the project needs to be obtained by the administrator account
- Multiple project Schemes can be configured in the App project
3.2. Add Scheme in the App
When using the Senspark system's Debug real-time view, visual full-linking, and other functions that require scanning, it is used to launch the page. For Android and iOS platforms, the configuration methods are different:
- Configure Scheme for Android platform (link needs to be configured here)
- Configure Scheme for iOS platform (link needs to be configured here)
4. SDK basic configuration
4.1. User Association
The purpose of user association is to uniquely identify users and improve the accuracy of user behavior analysis. At present, we provide simple user association and global user association to support different business scenarios.
4.2. Set the event public properties
Attributes that need to be added for all events can be passed after initializing the SDK and useregisterSuperProperties() register the property as a public property. See the detailed usage documentationBasic API function introduction.
4.3. Record activation event
Can call trackAppInstall() method record activation events, and calling this method multiple times only triggers the activation event on the first call. See the detailed usage documentationChannel tracking and advertising.
4.4. Code Tracking trace event
After initialize SDK, we can use track() method track user behavior events and adds custom properties to events. See the detailed usage documentationBasic API function introduction.
5. Debugging Displays event information
The enableLog parameter can be set to true when initialized by the init() method. Or call
import 'package:sensors_analytics_flutter_plugin/sensors_analytics_flutter_plugin.dart'; ... SensorsAnalyticsFlutterPlugin.enableLog(true/false) //方法来开启或关闭日志。
In Logcat(Android)or Xcode(iOS) filter SA. keywords:
- When the tracking event is successfully triggered, the SDK will output the beginning of track event event data.
- When the tracking event fails to trigger, the SDK will output the corresponding error cause
- When event data fails to be reported, the SDK will output Event Data at the beginning of the valid message.
- When event data fails to be reported, the SDK will output Event Data at the beginning of the invalid message and output the cause of the error.
Note: The content of this document is a technical document that provides details on how to use the Sensors product and does not include sales terms; the specific content of enterprise procurement products and technical services shall be subject to the commercial procurement contract.