Skip to content

Commit e7a57da

Browse files
author
yangzhankun
committed
add methods
1 parent b348746 commit e7a57da

File tree

9 files changed

+466
-33
lines changed

9 files changed

+466
-33
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ pubspec.lock
3838

3939
build/
4040

41+
.idea/workspace.xml
42+
.idea
43+
## Directory-based project format:
44+
.idea/
45+
46+
gradle/
47+
gradlew
48+
gradlew.bat
49+
*.iml
4150

4251
# CocoaPods
4352
#

.idea/workspace.xml

Lines changed: 337 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ rootProject.allprojects {
2525
apply plugin: 'com.android.library'
2626

2727
android {
28-
compileSdkVersion 27
28+
29+
try {
30+
compileSdkVersion rootProject.ext.compileSdkVersion
31+
} catch(Exception e){
32+
compileSdkVersion 28
33+
}
2934

3035
defaultConfig {
3136
minSdkVersion 16

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ public void onMethodCall(MethodCall call, Result result) {
6262
case "profileSetOnce":
6363
profileSetOnce(list);
6464
break;
65+
case "registerSuperProperties":
66+
registerSuperProperties(list);
67+
break;
68+
case "unregisterSuperProperty":
69+
unregisterSuperProperty(list);
70+
break;
71+
case "clearSuperProperties":
72+
clearSuperProperties();
73+
break;
6574
case "profileUnset":
6675
profileUnset(list);
6776
break;
@@ -208,6 +217,30 @@ private void trackTimerEnd(List list) {
208217
SensorsDataAPI.sharedInstance().trackTimerEnd(assertEventName((String) list.get(0)), assertProperties((Map) list.get(1)));
209218
}
210219

220+
/**
221+
* registerSuperProperties 设置公共属性
222+
*/
223+
private void registerSuperProperties(List list) {
224+
JSONObject properties = assertProperties((Map) list.get(0));
225+
if (properties == null) {
226+
return;
227+
}
228+
SensorsDataAPI.sharedInstance().registerSuperProperties(properties);
229+
}
230+
231+
/**
232+
* unregisterSuperProperty 删除某个公共属性
233+
*/
234+
private void unregisterSuperProperty(List list) {
235+
SensorsDataAPI.sharedInstance().unregisterSuperProperty((String) list.get(0));
236+
}
237+
238+
/**
239+
* clearSuperProperties 清除本地存储的所有公共属性
240+
*/
241+
private void clearSuperProperties() {
242+
SensorsDataAPI.sharedInstance().clearSuperProperties();
243+
}
211244

212245
private JSONObject assertProperties(Map map) {
213246
if (map != null) {

ios/Classes/SensorsAnalyticsFlutterPlugin.m

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
static NSString* const SensorsAnalyticsFlutterPluginMethodProfileAppend = @"profileAppend";
2222
static NSString* const SensorsAnalyticsFlutterPluginMethodProfileDelete = @"profileDelete";
2323

24+
static NSString* const SensorsAnalyticsFlutterPluginMethodRegisterSuperProperties = @"registerSuperProperties";
25+
static NSString* const SensorsAnalyticsFlutterPluginMethodUnregisterSuperProperty = @"unregisterSuperProperty";
26+
static NSString* const SensorsAnalyticsFlutterPluginMethodClearSuperProperties = @"clearSuperProperties";
2427

2528

2629
@implementation SensorsAnalyticsFlutterPlugin
@@ -116,8 +119,20 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
116119
}else if ([method isEqualToString:SensorsAnalyticsFlutterPluginMethodProfileDelete]){
117120
[self profileDelete];
118121
result(nil);
119-
}
120-
else {
122+
}else if ([method isEqualToString:SensorsAnalyticsFlutterPluginMethodRegisterSuperProperties]){
123+
NSDictionary* propertyDict = arguments[0];
124+
argumentSetNSNullToNil(&propertyDict);
125+
[self registerSuperProperties:propertyDict];
126+
result(nil);
127+
}else if ([method isEqualToString:SensorsAnalyticsFlutterPluginMethodUnregisterSuperProperty]){
128+
NSString* property = arguments[0];
129+
argumentSetNSNullToNil(&property);
130+
[self unregisterSuperProperty:property];
131+
result(nil);
132+
}else if ([method isEqualToString:SensorsAnalyticsFlutterPluginMethodClearSuperProperties]){
133+
[self clearSuperProperties];
134+
result(nil);
135+
}else {
121136
result(FlutterMethodNotImplemented);
122137
}
123138
}
@@ -184,6 +199,18 @@ -(NSString *)getDistinctId{
184199
return SensorsAnalyticsSDK.sharedInstance.distinctId;
185200
}
186201

202+
-(void)registerSuperProperties:(NSDictionary *)propertyDict{
203+
[SensorsAnalyticsSDK.sharedInstance registerSuperProperties:propertyDict];
204+
}
205+
206+
-(void)unregisterSuperProperty:(NSString *)property{
207+
[SensorsAnalyticsSDK.sharedInstance unregisterSuperProperty:property];
208+
}
209+
210+
- (void)clearSuperProperties {
211+
[SensorsAnalyticsSDK.sharedInstance clearSuperProperties];
212+
}
213+
187214
static inline void argumentSetNSNullToNil(id *arg){
188215
*arg = (*arg == NSNull.null) ? nil:*arg;
189216
}

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 = '1.0.0'
6+
s.version = '1.0.1'
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: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,43 +162,43 @@ class SensorsAnalyticsFlutterPlugin {
162162
/// profileUnset
163163
/// 删除一个用户属性.
164164
///
165-
/// @param profilePropertity String 用户属性.
165+
/// @param profileProperty String 用户属性.
166166
///
167167
/// 使用示例:
168168
/// SensorsAnalyticsFlutterPlugin.profileUnset('key1');
169169
///
170-
static void profileUnset(String profilePropertity){
171-
List<dynamic> params = [profilePropertity];
170+
static void profileUnset(String profileProperty){
171+
List<dynamic> params = [profileProperty];
172172
_channel.invokeMethod('profileUnset',params);
173173
}
174174

175175
///
176176
/// profileIncrement
177177
/// 给一个数值类型的Profile增加一个数值. 只能对数值型属性进行操作,若该属性未设置,则添加属性并设置默认值为0
178178
///
179-
/// @param profilePropertity String 用户属性.
179+
/// @param profileProperty String 用户属性.
180180
/// @param number 增加的数值,可以为负数
181181
///
182182
/// 使用示例:
183183
/// SensorsAnalyticsFlutterPlugin.profileIncrement('age',10);
184184
///
185-
static void profileIncrement(String profilePropertity, num number) {
186-
List<dynamic> params = [profilePropertity,number];
185+
static void profileIncrement(String profileProperty, num number) {
186+
List<dynamic> params = [profileProperty,number];
187187
_channel.invokeMethod('profileIncrement',params);
188188
}
189189

190190
///
191191
/// profileAppend
192192
/// 给一个 List 类型的 Profile 增加一些值
193193
///
194-
/// @param profilePropertity String 用户属性.
194+
/// @param profileProperty String 用户属性.
195195
/// @param content List<String> 增加的值,List 中元素必须为 String
196196
///
197197
/// 使用示例:
198198
/// SensorsAnalyticsFlutterPlugin.profileAppend('address',['Beijing','Shanghai']);
199199
///
200-
static void profileAppend(String profilePropertity, List<String> content) {
201-
List<dynamic> params = [profilePropertity,content];
200+
static void profileAppend(String profileProperty, List<String> content) {
201+
List<dynamic> params = [profileProperty,content];
202202
_channel.invokeMethod('profileAppend',params);
203203
}
204204

@@ -223,6 +223,44 @@ class SensorsAnalyticsFlutterPlugin {
223223
///
224224
static void clearKeychainData() {
225225
_channel.invokeMethod('clearKeychainData');
226-
}
226+
}
227227

228+
///
229+
/// registerSuperProperties
230+
/// 设置公共属性
231+
///
232+
/// @param superProperties Map<String,dynamic> 公共属性.
233+
///
234+
/// 使用示例:
235+
/// SensorsAnalyticsFlutterPlugin.registerSuperProperties({'key1':'value1','key2':'value2'});
236+
///
237+
static void registerSuperProperties(Map<String,dynamic> superProperties){
238+
List<dynamic> params = [superProperties];
239+
_channel.invokeMethod('registerSuperProperties',params);
240+
}
241+
242+
///
243+
/// unregisterSuperProperty
244+
/// 删除一个指定的公共属性.
245+
///
246+
/// @param superProperty String 公共属性.
247+
///
248+
/// 使用示例:
249+
/// SensorsAnalyticsFlutterPlugin.unregisterSuperProperty('key1');
250+
///
251+
static void unregisterSuperProperty(String superProperty){
252+
List<dynamic> params = [superProperty];
253+
_channel.invokeMethod('unregisterSuperProperty',params);
254+
}
255+
256+
///
257+
/// clearSuperProperties
258+
/// 删除本地存储的所有公共属性
259+
///
260+
/// 使用示例:
261+
/// SensorsAnalyticsFlutterPlugin.clearSuperProperties();
262+
///
263+
static void clearSuperProperties() {
264+
_channel.invokeMethod('clearSuperProperties');
265+
}
228266
}

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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: 1.0.0
4-
author: "ziven.xiang <ziven.xiang@gmail.com>"
3+
version: 1.0.1
4+
author: "yangzhankun <yzhankun@gmail.com>"
55
homepage: "https://github.com/sensorsdata/sensors_analytics_flutter_plugin"
66

77
environment:

sensors_analytics_flutter_plugin.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
1212
<excludeFolder url="file://$MODULE_DIR$/example/build" />
1313
</content>
14+
<orderEntry type="inheritedJdk" />
1415
<orderEntry type="sourceFolder" forTests="false" />
15-
<orderEntry type="library" name="Dart Packages" level="project" />
1616
<orderEntry type="library" name="Dart SDK" level="project" />
1717
<orderEntry type="library" name="Flutter Plugins" level="project" />
1818
</component>

0 commit comments

Comments
 (0)