Skip to content

Commit 2c17e64

Browse files
author
jg zhu
committed
Release 2.0.4
1 parent 5df754e commit 2c17e64

File tree

9 files changed

+66
-20
lines changed

9 files changed

+66
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.4
2+
3+
* 支持采集全埋点 SDK 版本号
4+
15
## 2.0.3
26

37
* 修复 enableR8 异常日志问题

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
```yml
1818
dependencies:
1919
# 添加神策 flutter plugin
20-
sensors_analytics_flutter_plugin: ^2.0.3
20+
sensors_analytics_flutter_plugin: ^2.0.4
2121
```
2222
2323
执行 flutter packages get 命令安装插件

android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/SensorsAnalyticsFlutterPlugin.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import com.sensorsdata.analytics.android.sdk.SALog;
88
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
99

10+
import org.json.JSONArray;
1011
import org.json.JSONObject;
1112

13+
import java.util.ArrayList;
1214
import java.util.Collection;
1315
import java.util.HashMap;
1416
import java.util.HashSet;
@@ -214,6 +216,17 @@ private void getSuperProperties(Result result) {
214216
while (keys.hasNext()) {
215217
String key = keys.next();
216218
Object value = jsonObject.opt(key);
219+
if (value instanceof JSONArray) {
220+
JSONArray jsonArray = (JSONArray) value;
221+
if (jsonArray.length() != 0) {
222+
ArrayList<Object> newValue = new ArrayList<>();
223+
for (int index = 0; index < jsonArray.length(); index++) {
224+
newValue.add(jsonArray.opt(index));
225+
}
226+
map.put(key, newValue);
227+
continue;
228+
}
229+
}
217230
map.put(key, value);
218231
}
219232
result.success(map);
@@ -323,7 +336,7 @@ private void track(List list) {
323336
* login
324337
*/
325338
private void login(List list) {
326-
SensorsDataAPI.sharedInstance().login((String) list.get(0));
339+
SensorsDataAPI.sharedInstance().login((String) list.get(0), assertProperties((Map) list.get(1)));
327340
}
328341

329342
/**

example/lib/main.dart

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MyApp extends StatefulWidget {
1212
}
1313

1414
class _MyAppState extends State<MyApp> {
15-
String _distinctId = '';
15+
String? _distinctId = '';
1616
var parameters;
1717

1818
@override
@@ -44,7 +44,7 @@ class _MyAppState extends State<MyApp> {
4444

4545
@override
4646
Widget build(BuildContext context) {
47-
dynamic tmpResult;
47+
late dynamic tmpResult;
4848

4949
return MaterialApp(
5050
home: Scaffold(
@@ -66,7 +66,7 @@ class _MyAppState extends State<MyApp> {
6666
leading: Icon(Icons.account_circle),
6767
title: Text('注册成功/登录成功时调用 login '),
6868
onTap: () {
69-
SensorsAnalyticsFlutterPlugin.login('传入你们服务端分配给用户的登录 ID');
69+
SensorsAnalyticsFlutterPlugin.login("sd", {"hello":"world"});
7070
},
7171
),
7272
ListTile(
@@ -85,13 +85,30 @@ class _MyAppState extends State<MyApp> {
8585
title: Text('追踪事件 track'),
8686
onTap: () {
8787
print("======触发事件233");
88+
89+
dynamic a = "aaa";
90+
print(a is String);
91+
String? b= "bbb";
92+
dynamic c = b;
93+
print(c.runtimeType);
94+
print(c is String);
95+
print(c is! String);
96+
print(c is String?);
97+
print("======");
98+
dynamic d = null;
99+
print(d.runtimeType);
100+
print(d is String);
101+
print(d is! String);
102+
print(d is String?);
103+
88104
// SensorsAnalyticsFlutterPlugin.track(
89105
// 'ViewProduct', <String, dynamic>{
90106
// "a_time": DateTime.now(),
91107
// "product_name": "Apple 12 max pro"
92108
// });
93-
var map = {/*r"$lib_plugin_version":["flutter:234"],*/"address":"000000000000"};
94-
SensorsAnalyticsFlutterPlugin.track("hello", map);
109+
List<String?>? list = ["flutter_plugin:12312"];
110+
var map = {r"$lib_plugin_version":list, "address":"000000000000"};
111+
SensorsAnalyticsFlutterPlugin.track("hello", map);
95112
},
96113
),
97114
ListTile(
@@ -286,14 +303,17 @@ class _MyAppState extends State<MyApp> {
286303
ListTile(
287304
title: Text('setsuperproperties'),
288305
onTap: () async {
306+
List<String?>? list = ["flutter_plugin:super_set"];
307+
var map = {r"$lib_plugin_version":list};
289308
SensorsAnalyticsFlutterPlugin.registerSuperProperties(
290-
{"age": 100});
291-
print("getSuperProperties===");
309+
map);
310+
print("setSuperProperties===");
292311
},
293312
),
294313
ListTile(
295314
title: Text('getSuperProperties'),
296315
onTap: () async {
316+
var a = 10;
297317
dynamic map =
298318
await SensorsAnalyticsFlutterPlugin.getSuperProperties();
299319
print("getSuperProperties===$map");

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Demonstrates how to use the sensorsanalyticsflutterplugin plugin.
66
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
77

88
environment:
9-
sdk: ">=2.7.0 <3.0.0"
9+
sdk: '>=2.12.0 <3.0.0'
1010

1111
dependencies:
1212
flutter:

example/test/widget_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void main() {
1919
expect(
2020
find.byWidgetPredicate(
2121
(Widget widget) => widget is Text &&
22-
widget.data.startsWith('Running on:'),
22+
widget.data!.startsWith('Running on:'),
2323
),
2424
findsOneWidget,
2525
);

ios/sensors_analytics_flutter_plugin.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'sensors_analytics_flutter_plugin'
6-
s.version = '2.0.3'
6+
s.version = '2.0.4'
77
s.summary = 'A new flutter plugin project.'
88
s.description = <<-DESC
99
A new flutter plugin project.

lib/sensors_analytics_flutter_plugin.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:flutter/services.dart';
55

66
// This is the official Flutter Plugin for Sensors Analytics.
77
class SensorsAnalyticsFlutterPlugin {
8-
static const String FLUTTER_PLUGIN_VERSION = "2.0.3";
8+
static const String FLUTTER_PLUGIN_VERSION = "2.0.4";
99
static bool hasAddedFlutterPluginVersion = false;
1010

1111
static const MethodChannel _channel =
@@ -26,7 +26,7 @@ class SensorsAnalyticsFlutterPlugin {
2626
/// SensorsAnalyticsFlutterPlugin.track('eventname',{'key1':'value1','key2':'value2'});
2727
///
2828
static void track(String eventName, Map<String, dynamic>? properties) {
29-
properties = properties == null ? null : {...properties};
29+
properties = properties == null ? {} : {...properties};
3030
_convertDateTime(properties);
3131
_setupLibPluginVersion(properties);
3232
List<dynamic> params = [eventName, properties];
@@ -97,8 +97,9 @@ class SensorsAnalyticsFlutterPlugin {
9797
///
9898
static void trackTimerEnd(
9999
String eventName, Map<String, dynamic>? properties) {
100-
properties = properties == null ? null : {...properties};
100+
properties = properties == null ? {} : {...properties};
101101
_convertDateTime(properties);
102+
_setupLibPluginVersion(properties);
102103
List<dynamic> params = [eventName, properties];
103104
_channel.invokeMethod('trackTimerEnd', params);
104105
}
@@ -122,8 +123,11 @@ class SensorsAnalyticsFlutterPlugin {
122123
/// 使用示例:
123124
/// SensorsAnalyticsFlutterPlugin.login('login_id');
124125
///
125-
static void login(String loginId) {
126-
List<String> params = [loginId];
126+
static void login(String loginId, [Map<String, dynamic>? properties]) {
127+
properties = properties == null ? {} : {...properties};
128+
_convertDateTime(properties);
129+
_setupLibPluginVersion(properties);
130+
List<dynamic> params = [loginId, properties];
127131
_channel.invokeMethod('login', params);
128132
}
129133

@@ -149,8 +153,9 @@ class SensorsAnalyticsFlutterPlugin {
149153
/// SensorsAnalyticsFlutterPlugin.trackViewScreen('urlForView',{'key1':'value1','key2':'value2'});
150154
///
151155
static void trackViewScreen(String url, Map<String, dynamic>? properties) {
152-
properties = properties == null ? null : {...properties};
156+
properties = properties == null ? {} : {...properties};
153157
_convertDateTime(properties);
158+
_setupLibPluginVersion(properties);
154159
List<dynamic> params = [url, properties];
155160
_channel.invokeMethod('trackViewScreen', params);
156161
}
@@ -530,7 +535,11 @@ class SensorsAnalyticsFlutterPlugin {
530535
if (properties == null) {
531536
properties = {};
532537
}
533-
List<String>? values = properties[r"$lib_plugin_version"];
538+
dynamic tmp = properties[r"$lib_plugin_version"];
539+
if ((tmp is! List<String>) && (tmp is! List<String?>)) {
540+
properties.remove(r"$lib_plugin_version");
541+
}
542+
dynamic values = properties[r"$lib_plugin_version"];
534543
values = values == null ? [] : [...values];
535544
values.add("flutter_plugin:$FLUTTER_PLUGIN_VERSION");
536545
properties[r"$lib_plugin_version"] = values;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: sensors_analytics_flutter_plugin
22
description: This is the official flutter plugin for Sensors Analytics,with this plugin you can easily collect your app data on Android and iOS.
3-
version: 2.0.3
3+
version: 2.0.4
44
homepage: "https://github.com/sensorsdata/sensors_analytics_flutter_plugin"
55

66
environment:

0 commit comments

Comments
 (0)