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
CODE

Excute flutter pub get Command install plugin.

flutter pub get
CODE

Dependencies between the SDK versions of the Flutter plugin and Android and iOS:

Flutter plugin versionAndroid available SDK version rangeRange of available SDK versions for iOS
v2.3.0 <= Flutter plugin versionv6.6.0 <= SDK versionv4.5.0 <= SDK version
v2.2.0 <= Flutter plugin version <=v2.2.2v6.5.1 <= SDK version <= v6.5.5v4.4.6 <= SDK version <= v4.4.8
v2.1.0 <= Flutter plugin version <=v2.1.1v6.0.0 <= SDK version <= v6.5.0v4.0.0 <= SDK version <= v4.4.5
v1.0.5 <= Flutter plugin version <=v2.0.4v4.4.0 <= SDK version <= v5.4.7v2.1.17 <= SDK version <= v3.1.9
v1.0.0 <= Flutter plugin version <=v1.0.4SDK version <= v4.3.7SDK 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));
CODE

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 typeParameter descriptionParameter descriptionRemark
serverUrlString?Data Receiving URL
enableLogboolWhether to display logs
autoTrackTypesSet&lt;SAAutoTrackType&gt;?Full-track collection types
  • SAAutoTrackType.NONE,
  • SAAutoTrackType.START,
  • SAAutoTrackType.END,
  • SAAutoTrackType.VIEW_SCREEN,
  • SAAutoTrackType.CLICK

Note: Currently only effective for native, not for Flutter full-track!

flushIntervalintSet minimum interval between two event reportsDefault is 15 seconds, minimum is 5 seconds, in milliseconds
flushBulksizeintSet the maximum number of entries that trigger a flush in the local cacheDefault is 100, minimum is 50
networkTypesSet&lt;SANetworkType&gt;?Set the reported network conditionsTYPE_NONE, TYPE_2G, TYPE_3G, TYPE_4G, TYPE_WIFI, TYPE_5G, TYPE_ALL
encryptboolEnable encryptionOnly support RSA + AES
javaScriptBridgeboolSupport H5 bridging

Default is false

android

AndroidConfig?

Android-specific Configuration

  • subProcessFlush: Whether to support data reporting in sub-processes
  • jellybean: Whether to support API level 16 and below versions
  • maxCacheSize: Maximum cache count, in bytes. Default is 32M, which is 32* 1024 * 1024

android:{
  subProcessFlush:true,
  jellybean:true,   
  maxCacheSize:48  * 1024*1024
}

iosIOSConfig?

iOS-specific Configuration

  • maxCacheSize: Maximum cache count, in units. Default value: 10000

ios:{
  maxCacheSize:10000   
}

visualizedVisualizedConfig?

Visualization-related Configuration

  • autoTrack: bool Whether to enable
  • properties: Whether to enable custom property function

visualized{
  autoTrack:true,
  properties:true
}


heatMapbool

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

globalPropertiesMap?Configure global common propertiesIts priority is lower than static common properties
  1. If the App has compliance requirements, please refer to Compliance Description;
  2. 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) //方法来开启或关闭日志。
CODE

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.