Skip to content

Commit aac0c6e

Browse files
authored
add registerSuperProperties methods
1 parent 84fddc4 commit aac0c6e

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

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

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public void getDistinctId(Callback successCallback, Callback errorCallback) {
479479
/**
480480
* 导出 getDistinctIdPromise 方法给 RN 使用.
481481
* <p>
482-
* 删除当前这个用户的所有记录.
482+
* Promise 方式,获取 distinctId
483483
* <p>
484484
* RN 中使用示例:
485485
* async getDistinctIdPromise() {
@@ -505,7 +505,7 @@ public void getDistinctIdPromise(Promise promise){
505505
/**
506506
* 导出 getAnonymousIdPromise 方法给 RN 使用.
507507
* <p>
508-
* 删除当前这个用户的所有记录.
508+
* Promise 方式 getAnonymousId 获取匿名 ID.
509509
* <p>
510510
* RN 中使用示例:
511511
* async getAnonymousIdPromise() {
@@ -522,4 +522,69 @@ public void getAnonymousIdPromise(Promise promise){
522522
promise.reject("getDistinctId fail",e);
523523
}
524524
}
525+
526+
/**
527+
* 导出 registerSuperProperties 方法给 RN 使用.
528+
*
529+
* @param properties 要设置的公共属性
530+
* <p>
531+
* RN 中使用示例:(设置公共属性 "Platform":"Android")
532+
* <Button
533+
* title="Button"
534+
* onPress={()=>
535+
* RNSensorsAnalyticsModule.registerSuperProperties({"Platform":"Android"})}>
536+
* </Button>
537+
*/
538+
@ReactMethod
539+
public void registerSuperProperties(ReadableMap properties) {
540+
try {
541+
SensorsDataAPI.sharedInstance().registerSuperProperties(convertToJSONObject(properties));
542+
} catch (Exception e) {
543+
e.printStackTrace();
544+
Log.e(LOGTAG, e.toString() + "");
545+
}
546+
}
547+
548+
/**
549+
* 导出 unregisterSuperProperty 方法给 RN 使用.
550+
*
551+
* @param property 要删除的公共属性属性
552+
* <p>
553+
* RN 中使用示例:(删除公共属性 "Platform")
554+
* <Button
555+
* title="Button"
556+
* onPress={()=>
557+
* RNSensorsAnalyticsModule.unregisterSuperProperty("Platform")}>
558+
* </Button>
559+
*/
560+
@ReactMethod
561+
public void unregisterSuperProperty(String property) {
562+
try {
563+
SensorsDataAPI.sharedInstance().unregisterSuperProperty(property);
564+
} catch (Exception e) {
565+
e.printStackTrace();
566+
Log.e(LOGTAG, e.toString() + "");
567+
}
568+
}
569+
570+
/**
571+
* 导出 clearSuperProperties 方法给 RN 使用.
572+
*
573+
* <p>
574+
* RN 中使用示例:(删除所有已设置的公共属性)
575+
* <Button
576+
* title="Button"
577+
* onPress={()=>
578+
* RNSensorsAnalyticsModule.clearSuperProperties()}>
579+
* </Button>
580+
*/
581+
@ReactMethod
582+
public void clearSuperProperties() {
583+
try {
584+
SensorsDataAPI.sharedInstance().clearSuperProperties();
585+
} catch (Exception e) {
586+
e.printStackTrace();
587+
Log.e(LOGTAG, e.toString() + "");
588+
}
589+
}
525590
}

0 commit comments

Comments
 (0)