Quick Tracking Statistics SDK Flutter Plug-in Integration Description
Integrate the Flutter plug-in
Environment preparation
qt_common_sdk: ^2.1.0
| --- Depends on the native iOS 1.5.8.PX version
| --- Depends on the native Android 1.6.3.PX version
Manually integrate the SDK
Download the project git library: flutter-ananlytics-plugin, delete the project directory. git hidden directory.
copy the android, ios, and lib folders and the pubspec.yaml configuration file under this project root directory to your flutter project.
Add the plug-in dependency to the pubspec.yaml file of your flutter project.
# Local dependencies
qt_common_sdk:
path: ../Online Dependency
Add dependencies to the pubspec.yaml file.
# Online dependencies
dependencies:
qt_common_sdk: ^2.1.0Import inbound rules
import 'package:qt_common_sdk/qt_common_sdk.dart';Plug-in SDK initialization
Integrate ApsaraVideo MediaBox SDK for Android
Add the App class to the Android host project of your flutter project by referring to the App.java file in the example Android host project in this project (example/android/app/src/main/java/com/aliyun/qt_common_sdk_example/App.java). Note that this class must be a subclass of the io.flutter.app.FlutterApplication class. In the onCreate lifecycle function of the App class, call the pre-initialization method QtConfigure.preInit of the native statistics SDK and pass in the appkey and channel parameters.

In addition, you need to add the "android:name" attribute to the application configuration in the Android host project AndroidManifest.xml manifest file, and its value is the newly added App class. The following figure shows the result.

Note that the appkey and channel parameters passed in the pre-initialization must be the same as the first parameter (Android appkey) and the third parameter (Android channel) passed in the SDK formal initialization function QTCommonSdk.initCommon called in the dart code of the flutter project.
To meet the requirements of the Privacy Policy, developers must ensure that in the first cold start scenario after the application is installed, the QTCommonSdk.initCommon API of the Flutter plug-in can be called to initialize the SDK only after the application user agrees to the privacy authorization.
You can call the QTCommonSdk.initCommon API to initialize the SDK when you initialize the first page of Flutter.
Integrate ApsaraVideo MediaBox SDK for iOS
1. Compliance Statement
You must inform the user that you select the SDK service. Add the following terms to the Privacy Policy:
"Our product integration SDK,SDK needs to collect your device identification code (IDFA/IDFV/OPENUDID/GUID/) to provide statistical analysis services, and calibrate the accuracy of report data through geographic location to provide basic anti-cheating capabilities."
2. Compliance initialization
To ensure that your app can meet the compliance requirements of the Ministry of Industry and Information Technology (MIIT) after you integrate the statistics SDK, you must make sure that the initial initialization function is called to initialize the statistics SDK after the user reads your Privacy Policy and obtains the user's authorization during the first cold start of the app. In this case, the SDK collects device information and reports data. Conversely, if the user does not agree with the Privacy Policy authorization, the initialization function cannot be called.
/**Initialize all component products
@ param appKey The appkey applied by the developer.
@ param channel The channel identifier. You can set nil to "App Store".
*/
+ (void)initWithAppkey:(NSString *)appKey channel:(NSString *)channel;Once the App obtains the user authorization of the "Privacy Policy", the developer should ensure that the initialization function is called for subsequent App cold start.
Plug-in API description
The following comments on each API are marked with "Android-specific" or "iOS-specific" for the API or parameter. Please pay attention to the distinction. APIs or parameters that are not specified are common to both Android and iOS.
///
/// Set the primary and alternate domain names for reporting statistics logs. This function must be called before the SDK initializes the function call.
///
/// @param primaryDomain String the primary domain name.
/// @param standbyDomain String the receipt address of the backup domain name for uploading logs by using the backup domain name. The parameter can be null or an empty string. If this parameter is empty, the SDK automatically sets the primary domain name as the backup domain name.
///
///
static void setCustomDomain(String primaryDomain, String standbyDomain)
///
/// Initialize
///
/// @param androidAppkey String the Android appkey applied by the developer. Android-specific, enter
/// @param iosAppkey String the ios appkey that the developer applied for. iOS-specific, enter
/// @param channel String the channel identifier. You can set nil to "App Store".
///
///
static Future<dynamic> initCommon(String androidAppkey, String iosAppkey, String channel)
///
/// The version number of the custom app. By default, the version number is obtained. You can set this parameter only once. We recommend that you call the app before all API calls.
///
/// @param appVersion String the custom version number.
/// @param appVersionCode int the version number of the Android application. This parameter is unique to Android.
///
static void setAppVersion (String appVersion, int appVersionCode)
///
/// Set whether to output the debugging logs of the SDK in the console.
///
/// @param bFlag bool set to flash (no log output); Set to true to output log information for debugging reference.
/// By default, this switch is turned off in the SDK. You must turn off the log switch before the app is officially launched.
///
///
static void setLogEnabled (bool bFlag)
///
/// Custom event
///
/// @param event String the event ID.
/// @param properties Map custom parameters.
///
static void onEvent(String event, Map<String,dynamic> properties)
///
/// @param event String the event ID.
/// @param pageName String the page name.
/// @param properties Map custom parameters.
///
static void onEventWithPage(String event,String pageName, Map<String,dynamic> properties)
///
/// Account statistics logon
///
/// @param userID String user's ID
///
///
static void onProfileSignIn(String userID)
///
/// Account statistics logout
///
///
static void onProfileSignOff ()
///
/// Page statistics: Called when the page starts to be displayed.
///
/// @param viewName String the page name
///
///
static void onPageStart(String viewName)
///
/// Page statistics: called when the page disappears
///
/// @param viewName String the page name
///
///
static void onPageEnd(String viewName)
///
/// Set page properties.
///
/// @param pageName String the page name
/// @param properties Map custom parameters
///
static void setPageProperty(String pageName, Map<String,dynamic> properties)
///
/// Register global attributes
///
/// @param properties Map custom parameters
///
///
static void registerGlobalProperties(Map<String,dynamic> properties)
///
/// Delete a global attribute.
///
/// @param propertyName String the custom parameter key.
///
///
static void unregisterGlobalProperty(String propertyName)
///
/// Obtain global attributes.
///
///
static Future<String>? get getGlobalProperties async
///
/// Obtain a global attribute value.
///
///
static Future<dynamic>? getGlobalProperty(String propertyName) async
///
/// Clear global attributes
///
static void clearGlobalProperties()
///
/// Skips the current page statistics.
///
/// @param pageName String the page name
///
///
static void skipMe(String pageName)
///
/// Set page properties.
///
/// @param pageName String the page name
/// @param properties Map custom parameters
///
static void setPageProperty(String pageName, Map<String,dynamic> properties)
//
// QT JS SDK use the flutter_webview_plugin plug-in to send JS layer statistics to the flutter layer JavascriptChannel API.
// Call this operation. For more information about the sample code, see lines 15 to 23 in example/lib/main.dart.
//
static void onJSCall(String msg)
///
/// If the application withdraws violently by forcibly killing its own process,
/// You need to call this API before committing suicide. This API is unique to Android.
///
///
static void onKillProcess()Instructions for flutter_webview_plugin Plug-in with QT JS SDK Bridge
When the flutter project uses the community flutter_webview_plugin (support version 0.4.0 +) + H5 for hybrid development, if the QuickTracking JS version statistics SDK is integrated in the H5 page, the QT JS SDK statistics can be transmitted to the Android/iOS native statistics SDK by using the onJSCall API, and the native statistics SDK reports the JS SDK statistics.
You must refer to lines 15 to 23 of the example project example/lib/main.dart. Register a JS bridge named 'Umeng4AplusFlutter' for the flutter_webview_plugin plug-in, and then call QTCommonSdk.onJSCall(message.message) in the onMessageReceived: (JavascriptMessage message) callback function;
The following sample code can be found in the example/lib/main.dart file.
// Define a JavaScript bridge channel callback object named 'Umeng4AplusFlutter'.
final Set<JavascriptChannel> jsChannels = [
JavascriptChannel(
name: 'Umeng4AplusFlutter',
onMessageReceived: (JavascriptMessage message) {
// print(message.message);
QTCommonSdk.onJSCall(message.message);
}),
].toSet();
//..........
// Register the js bridge object when the flutter webview plug-in object is enabled.
flutterWebViewPlugin.launch(
selectedUrl,
javascriptChannels: jsChannels,
rect: Rect.fromLTWH(
0.0, 0.0, MediaQuery.of(context).size.width, 300.0),
userAgent: kAndroidUserAgent,
invalidUrlRegex:
r'^(https).+(twitter)', // prevent redirecting to twitter when user click on its icon in flutter website
);Note: You need to call QTConfigure.init to initialize the plug-in. You can view the Appkey on the Management> Application Management> Application Management> Application List page in the statistics background, or select an application in My Products> Settings> Application Information to view the Appkey.