@@ -17,131 +17,20 @@ dependencies:
1717```
1818
1919
20- [ Flutter 官网文档] ( https://flutter.io/docs )
21- ## 2. Android 端
22- 在程序的入口 ** Application** 的 ` onCreate() ` 中调用 ` SensorsDataAPI.sharedInstance() ` 初始化 SDK:
20+ [ 具体使用请参考文档] ( https://www.sensorsdata.cn/manual/sdk_flutter.html )
2321
24- ``` java
25- import io.flutter.app.FlutterApplication ;
26- import android.content.Context ;
27- import android.content.pm.ApplicationInfo ;
28- import android.content.pm.PackageInfo ;
29- import android.content.pm.PackageManager ;
30- import com.sensorsdata.analytics.android.sdk.SensorsDataAPI ;
31- import org.json.JSONObject ;
32- import java.util.ArrayList ;
33- import java.util.List ;
22+ ## License
3423
35- public class App extends FlutterApplication {
24+ Copyright 2015-2020 Sensors Data Inc.
3625
37- // debug 模式的数据接收地址 (测试,测试项目)
38- final static String SA_SERVER_URL_DEBUG = " 【测试项目】数据接收地址" ;
26+ Licensed under the Apache License, Version 2.0 (the "License");
27+ you may not use this file except in compliance with the License.
28+ You may obtain a copy of the License at
3929
40- // release 模式的数据接收地址(发版,正式项目)
41- final static String SA_SERVER_URL_RELEASE = " 【正式项目】数据接收地址" ;
30+ http://www.apache.org/licenses/LICENSE-2.0
4231
43- // SDK Debug 模式选项
44- // SensorsDataAPI.DebugMode.DEBUG_OFF - 关闭 Debug 模式
45- // SensorsDataAPI.DebugMode.DEBUG_ONLY - 打开 Debug 模式,校验数据,但不进行数据导入
46- // SensorsDataAPI.DebugMode.DEBUG_AND_TRACK - 打开 Debug 模式,校验数据,并将数据导入到 Sensors Analytics 中
47- // TODO 注意!请不要在正式发布的 App 中使用 DEBUG_AND_TRACK /DEBUG_ONLY 模式! 请使用 DEBUG_OFF 模式!!!
48-
49- // debug 时,初始化 SDK 使用测试项目数据接收 URL 、使用 DEBUG_AND_TRACK 模式;release 时,初始化 SDK 使用正式项目数据接收 URL 、使用 DEBUG_OFF 模式。
50- private boolean isDebugMode;
51-
52- @Override
53- public void onCreate () {
54- super . onCreate();
55- // 在 Application 的 onCreate 初始化神策 SDK
56- initSensorsDataSDK(this );
57- }
58-
59- /**
60- * 初始化 SDK 、开启自动采集
61- */
62- private void initSensorsDataSDK (Context context ) {
63- try {
64- // 初始化 SDK
65- SensorsDataAPI . sharedInstance(
66- context, // 传入 Context
67- (isDebugMode = isDebugMode(context)) ? SA_SERVER_URL_DEBUG : SA_SERVER_URL_RELEASE , // 数据接收的 URL
68- isDebugMode ? SensorsDataAPI . DebugMode . DEBUG_AND_TRACK : SensorsDataAPI . DebugMode . DEBUG_OFF ); // Debug 模式选项
69-
70- // 打开自动采集, 并指定追踪哪些 AutoTrack 事件
71- List<SensorsDataAPI . AutoTrackEventType > eventTypeList = new ArrayList<> ();
72- eventTypeList. add(SensorsDataAPI . AutoTrackEventType . APP_START );// $AppStart(启动事件)
73- eventTypeList. add(SensorsDataAPI . AutoTrackEventType . APP_END );// $AppEnd(退出事件)
74- SensorsDataAPI . sharedInstance(). enableAutoTrack(eventTypeList);
75- } catch (Exception e) {
76- e. printStackTrace();
77- }
78- }
79-
80- /**
81- * @param context App 的 Context
82- * @return debug return true,release return false
83- * 用于判断是 debug 包,还是 relase 包
84- */
85- public static boolean isDebugMode (Context context ) {
86- try {
87- ApplicationInfo info = context. getApplicationInfo();
88- return (info. flags & ApplicationInfo . FLAG_DEBUGGABLE ) != 0 ;
89- } catch (Exception e) {
90- e. printStackTrace();
91- return false ;
92- }
93- }
94- }
95-
96- ```
97-
98- ## 3. iOS 端
99-
100- 在程序的入口(如 AppDelegate.m )中引入 ` SensorsAnalyticsSDK.h ` ,并在初始化方法(如 ` - application:didFinishLaunchingWithOptions:launchOptions ` )中调用 ` startWithConfigOptions: ` 主线程同步初始化 SDK。
101-
102-
103- ``` objective-c
104- #import " SensorsAnalyticsSDK.h"
105-
106- #ifdef DEBUG
107- #define SA_SERVER_URL @"<#【测试项目】数据接收地址#>"
108- #else
109- #define SA_SERVER_URL @"<#【正式项目】数据接收地址#>"
110- #endif
111-
112- - (BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
113-
114- [self initSensorsAnalyticsWithLaunchOptions:launchOptions];
115- return YES;
116- }
117-
118- - (void )initSensorsAnalyticsWithLaunchOptions:(NSDictionary *)launchOptions {
119- // 设置神策 SDK 自动采集 options(Flutter 项目只支持 App 启动、退出自动采集)
120- SAConfigOptions *options = [[SAConfigOptions alloc] initWithServerURL:SA_SERVER_URL launchOptions:launchOptions];
121- options.autoTrackEventType = SensorsAnalyticsEventTypeAppStart | SensorsAnalyticsEventTypeAppEnd;
122- // 需要在主线程中初始化 SDK
123- [SensorsAnalyticsSDK startWithConfigOptions:options];
124- }
125- ```
126-
127- ## 4. Flutter 中使用插件
128- 在具体 dart 文件中导入 ` sensors_analytics_flutter_plugin.dart `
129-
130- ``` dart
131- import 'package:sensors_analytics_flutter_plugin/sensors_analytics_flutter_plugin.dart';
132- ```
133- ### 4.1 埋点事件
134-
135- 例如,触发事件名为 AddToFav ,对应的事件属性有:ProductID 和 UserLevel 的事件:
136-
137- ``` dart
138- SensorsAnalyticsFlutterPlugin.track("AddToFav",{"ProductID":123456,"UserLevel":"VIP"});
139- ```
140-
141- ### 4.2 设置用户属性
142-
143- 例如,设置用户 Age 属性:
144-
145- ``` dart
146- SensorsAnalyticsFlutterPlugin.profileSet({"Age":18});
147- ```
32+ Unless required by applicable law or agreed to in writing, software
33+ distributed under the License is distributed on an "AS IS" BASIS,
34+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35+ See the License for the specific language governing permissions and
36+ limitations under the License.
0 commit comments