Skip to content

Commit aadb4fe

Browse files
author
yangzhankun
committed
add methods
1 parent 6a091e5 commit aadb4fe

File tree

4 files changed

+108
-23
lines changed

4 files changed

+108
-23
lines changed

RNSensorsAnalyticsModule.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = "RNSensorsAnalyticsModule"
4-
s.version = "1.1.2"
4+
s.version = "1.1.3"
55
s.summary = "The official React Native SDK of Sensors Analytics."
66
s.description = <<-DESC
77
神策分析 RN 组件

android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsModule.java

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
1313
import org.json.JSONObject;
1414
import com.facebook.react.bridge.Promise;
15+
import com.facebook.react.bridge.ReadableArray;
16+
import java.util.HashSet;
1517

1618

1719

@@ -37,7 +39,6 @@ public RNSensorsAnalyticsModule(ReactApplicationContext reactContext) {
3739
}
3840

3941
private static final String MODULE_NAME = "RNSensorsAnalyticsModule";
40-
private static final String MODULE_VERSION = "1.1.0";
4142
private static final String LOGTAG = "SA.RN";
4243

4344
/**
@@ -93,7 +94,7 @@ private JSONObject convertToJSONObject(ReadableMap properties) {
9394
* <Button
9495
* title="Button"
9596
* onPress={()=>
96-
* SensorsDataAPI_Android.track("RN_AddToFav",{"ProductID":123456,"UserLevel":"VIP"})}>
97+
* RNSensorsAnalyticsModule.track("RN_AddToFav",{"ProductID":123456,"UserLevel":"VIP"})}>
9798
* </Button>
9899
*/
99100
@ReactMethod
@@ -117,7 +118,7 @@ public void track(String eventName, ReadableMap properties) {
117118
* <Button
118119
* title="Button"
119120
* onPress={()=>
120-
* SensorsDataAPI_Android.trackTimerStart("viewTimer")}>
121+
* RNSensorsAnalyticsModule.trackTimerStart("viewTimer")}>
121122
* </Button>
122123
*/
123124
@ReactMethod
@@ -141,7 +142,7 @@ public void trackTimerStart(String eventName) {
141142
* <Button
142143
* title="Button"
143144
* onPress={()=>
144-
* SensorsDataAPI_Android.trackTimerBegin("viewTimer")}>
145+
* RNSensorsAnalyticsModule.trackTimerBegin("viewTimer")}>
145146
* </Button>
146147
*/
147148
@ReactMethod
@@ -165,7 +166,7 @@ public void trackTimerBegin(String eventName) {
165166
* <Button
166167
* title="Button"
167168
* onPress={()=>
168-
* SensorsDataAPI_Android.trackTimerEnd("viewTimer",{"ProductID":123456,"UserLevel":"VIP"})}>
169+
* RNSensorsAnalyticsModule.trackTimerEnd("viewTimer",{"ProductID":123456,"UserLevel":"VIP"})}>
169170
* </Button>
170171
*/
171172
@ReactMethod
@@ -188,7 +189,7 @@ public void trackTimerEnd(String eventName, ReadableMap properties) {
188189
* <Button
189190
* title="Button"
190191
* onPress={()=>
191-
* SensorsDataAPI_Android.clearTrackTimer()}>
192+
* RNSensorsAnalyticsModule.clearTrackTimer()}>
192193
* </Button>
193194
*/
194195
@ReactMethod
@@ -209,7 +210,7 @@ public void clearTrackTimer() {
209210
* <Button
210211
* title="Button"
211212
* onPress={()=>
212-
* SensorsDataAPI_Android.login("[email protected]")}>
213+
* RNSensorsAnalyticsModule.login("[email protected]")}>
213214
* </Button>
214215
*/
215216
@ReactMethod
@@ -229,7 +230,7 @@ public void login(String loginId) {
229230
* <Button
230231
* title="Button"
231232
* onPress={()=>
232-
* SensorsDataAPI_Android.logout()}>
233+
* RNSensorsAnalyticsModule.logout()}>
233234
* </Button>
234235
*/
235236
@ReactMethod
@@ -254,7 +255,7 @@ public void logout() {
254255
* <Button
255256
* title="Button"
256257
* onPress={()=>
257-
* SensorsDataAPI_Android.trackInstallation("AppInstall",{"$utm_source":"渠道A","$utm_campaign":"广告A"})}>
258+
* RNSensorsAnalyticsModule.trackInstallation("AppInstall",{"$utm_source":"渠道A","$utm_campaign":"广告A"})}>
258259
* </Button>
259260
*/
260261
@ReactMethod
@@ -282,7 +283,7 @@ public void trackInstallation(String eventName, ReadableMap properties) {
282283
* <Button
283284
* title="Button"
284285
* onPress={()=>
285-
* SensorsDataAPI_Android.trackViewScreen(null,{"$title":"RN主页","$screen_name":"cn.sensorsdata.demo.RNHome"})}>
286+
* RNSensorsAnalyticsModule.trackViewScreen(null,{"$title":"RN主页","$screen_name":"cn.sensorsdata.demo.RNHome"})}>
286287
* </Button>
287288
*/
288289
@ReactMethod
@@ -304,7 +305,7 @@ public void trackViewScreen(String url, ReadableMap properties) {
304305
* <Button
305306
* title="Button"
306307
* onPress={()=>
307-
* SensorsDataAPI_Android.profileSet({"sex":"男"})}>
308+
* RNSensorsAnalyticsModule.profileSet({"sex":"男"})}>
308309
* </Button>
309310
*/
310311
@ReactMethod
@@ -329,7 +330,7 @@ public void profileSet(ReadableMap properties) {
329330
* <Button
330331
* title="Button"
331332
* onPress={()=>
332-
* SensorsDataAPI_Android.profileSetOnce({"sex":"男"})}>
333+
* RNSensorsAnalyticsModule.profileSetOnce({"sex":"男"})}>
333334
* </Button>
334335
*/
335336
@ReactMethod
@@ -356,7 +357,7 @@ public void profileSetOnce(ReadableMap properties) {
356357
* <Button
357358
* title="Button"
358359
* onPress={()=>
359-
* SensorsDataAPI_Android.profileIncrement("money",10)}>
360+
* RNSensorsAnalyticsModule.profileIncrement("money",10)}>
360361
* </Button>
361362
*/
362363
@ReactMethod
@@ -369,25 +370,29 @@ public void profileIncrement(String property, Double value) {
369370
}
370371
}
371372

372-
/**
373+
/**
373374
* 导出 profileAppend 方法给 RN 使用.
374375
* <p>
375376
* 给一个列表类型的 Profile 增加一个元素.
376377
*
377378
* @param property 属性名称.
378-
* @param value 新增的元素.
379+
* @param strList 新增的元素.
379380
* <p>
380381
* RN 中使用示例:
381382
* <Button
382383
* title="Button"
383384
* onPress={()=>
384-
* SensorsDataAPI_Android.profileAppend("VIP","Gold")}>
385+
* RNSensorsAnalyticsModule.profileAppend("VIP",["Gold","Diamond"])}>
385386
* </Button>
386387
*/
387388
@ReactMethod
388-
public void profileAppend(String property, String value) {
389+
public void profileAppend(String property, ReadableArray strList) {
389390
try {
390-
SensorsDataAPI.sharedInstance().profileAppend(property, value);
391+
HashSet<String> strSet = new HashSet<>();
392+
for (int i = 0; i < strList.size(); i++) {
393+
strSet.add(strList.getString(i));
394+
}
395+
SensorsDataAPI.sharedInstance().profileAppend(property, strSet);
391396
} catch (Exception e) {
392397
e.printStackTrace();
393398
Log.e(LOGTAG, e.toString() + "");
@@ -405,7 +410,7 @@ public void profileAppend(String property, String value) {
405410
* <Button
406411
* title="Button"
407412
* onPress={()=>
408-
* SensorsDataAPI_Android.profileUnset("sex")}>
413+
* RNSensorsAnalyticsModule.profileUnset("sex")}>
409414
* </Button>
410415
*/
411416
@ReactMethod
@@ -427,7 +432,7 @@ public void profileUnset(String property) {
427432
* <Button
428433
* title="Button"
429434
* onPress={()=>
430-
* SensorsDataAPI_Android.profileDelete()}>
435+
* RNSensorsAnalyticsModule.profileDelete()}>
431436
* </Button>
432437
*/
433438
@ReactMethod
@@ -451,7 +456,7 @@ public void profileDelete() {
451456
* <Button
452457
* title="Button"
453458
* onPress={()=>
454-
* SensorsDataAPI_Android.getDistinctId(success=>{
459+
* RNSensorsAnalyticsModule.getDistinctId(success=>{
455460
* console.log(success)
456461
* },
457462
* error=>{
@@ -587,4 +592,46 @@ public void clearSuperProperties() {
587592
Log.e(LOGTAG, e.toString() + "");
588593
}
589594
}
595+
596+
/**
597+
* 导出 flush 方法给 RN 使用.
598+
*
599+
* <p>
600+
* RN 中使用示例:(强制发送数据到服务端)
601+
* <Button
602+
* title="Button"
603+
* onPress={()=>
604+
* RNSensorsAnalyticsModule.flush()}>
605+
* </Button>
606+
*/
607+
@ReactMethod
608+
public void flush() {
609+
try {
610+
SensorsDataAPI.sharedInstance().flush();
611+
} catch (Exception e) {
612+
e.printStackTrace();
613+
Log.e(LOGTAG, e.toString() + "");
614+
}
615+
}
616+
617+
/**
618+
* 导出 deleteAll 方法给 RN 使用.
619+
*
620+
* <p>
621+
* RN 中使用示例:(删除本地数据库的所有数据!!!请谨慎使用)
622+
* <Button
623+
* title="Button"
624+
* onPress={()=>
625+
* RNSensorsAnalyticsModule.deleteAll()}>
626+
* </Button>
627+
*/
628+
@ReactMethod
629+
public void deleteAll() {
630+
try {
631+
SensorsDataAPI.sharedInstance().deleteAll();
632+
} catch (Exception e) {
633+
e.printStackTrace();
634+
Log.e(LOGTAG, e.toString() + "");
635+
}
636+
}
590637
}

ios/RNSensorsAnalyticsModule.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,5 +629,43 @@ @implementation RNSensorsAnalyticsModule
629629
}
630630
}
631631

632+
/**
633+
* 导出 flush 方法给 RN 使用.
634+
*
635+
* <p>
636+
* RN 中使用示例:(强制发送数据到服务端)
637+
* <Button
638+
* title="Button"
639+
* onPress={()=>
640+
* RNSensorsAnalyticsModule.flush()}>
641+
* </Button>
642+
*/
643+
RCT_EXPORT_METHOD(flush){
644+
@try {
645+
[[SensorsAnalyticsSDK sharedInstance] flush];
646+
} @catch (NSException *exception) {
647+
NSLog(@"[RNSensorsAnalytics] error:%@",exception);
648+
}
649+
}
650+
651+
/**
652+
* 导出 deleteAll 方法给 RN 使用.
653+
*
654+
* <p>
655+
* RN 中使用示例:(删除本地数据库的所有数据!!!请谨慎使用)
656+
* <Button
657+
* title="Button"
658+
* onPress={()=>
659+
* RNSensorsAnalyticsModule.deleteAll()}>
660+
* </Button>
661+
*/
662+
RCT_EXPORT_METHOD(deleteAll){
663+
@try {
664+
[[SensorsAnalyticsSDK sharedInstance] deleteAll];
665+
} @catch (NSException *exception) {
666+
NSLog(@"[RNSensorsAnalytics] error:%@",exception);
667+
}
668+
}
669+
632670
@end
633671

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sensors.data/react-native-sensors-analytics",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"private": false,
55
"description": "神策分析 RN 组件",
66
"main": "index.js",

0 commit comments

Comments
 (0)