Skip to content

Commit 90bda7c

Browse files
author
chenru
committed
Release 2.0.8
1 parent 736f853 commit 90bda7c

23 files changed

+373
-39
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 = "2.0.7"
4+
s.version = "2.0.8"
55
s.summary = "The official React Native SDK of Sensors Analytics."
66
s.description = <<-DESC
77
神策分析 RN 组件

SensorsDataRNHook.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ var sensorsdataSwitchHookCode = "if(this.props.onChange != null || this.props.on
9090
+" })(this); /* SENSORSDATA HOOK */}";
9191
var sensorsdataImportReactNativeHookCode ="import ReactNative from 'react-native';\n";
9292
var sensorsdataNavigation5HookCode = `
93+
94+
function getCurrentRouteName(){
95+
let state = getRootState();
96+
if (state === undefined) {
97+
return undefined;
98+
}
99+
while (state.routes[state.index].state !== undefined) {
100+
state = state.routes[state.index].state as NavigationState;
101+
}
102+
return state.routes[state.index].name;
103+
}
93104
function getParams(state:any):any{
94105
if(!state){
95106
return null;
@@ -113,7 +124,7 @@ var sensorsdataNavigation5HookCode = `
113124
trackViewScreen(route.state);
114125
return;
115126
}
116-
var screenName = getCurrentRoute()?.name;
127+
var screenName = getCurrentRouteName();
117128
var params = getParams(state);
118129
var saProperties = {};
119130
if (params) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.sensorsdata.analytics.RNSensorsAnalyticsModule;
2626
import com.sensorsdata.analytics.utils.RNViewUtils;
2727
import com.sensorsdata.analytics.data.SAViewProperties;
28+
import com.sensorsdata.analytics.property.RNPropertyManager;
2829

2930
import com.facebook.react.uimanager.JSTouchDispatcher;
3031
import com.facebook.react.uimanager.events.EventDispatcher;
@@ -75,7 +76,7 @@ public static void trackViewScreen(String url, JSONObject properties, boolean is
7576
if (isAuto && SensorsDataAPI.sharedInstance().isAutoTrackEventTypeIgnored(SensorsDataAPI.AutoTrackEventType.APP_VIEW_SCREEN)) {
7677
return;
7778
}
78-
SensorsDataAPI.sharedInstance().trackViewScreen(url, properties);
79+
SensorsDataAPI.sharedInstance().trackViewScreen(url, RNPropertyManager.mergeProperty(properties, isAuto));
7980
}catch(Exception e){
8081
SALog.printStackTrace(e);
8182
}
@@ -108,7 +109,7 @@ public static void trackViewClick(int viewId){
108109
viewProperties.properties.remove("ignore");
109110
SensorsDataUtils.mergeJSONObject(viewProperties.properties, properties);
110111
}
111-
SensorsDataAPI.sharedInstance().trackViewAppClick(clickView, properties);
112+
SensorsDataAPI.sharedInstance().trackViewAppClick(clickView, RNPropertyManager.mergeProperty(properties ,true));
112113
}
113114
} catch (Exception e) {
114115
SALog.printStackTrace(e);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.facebook.react.bridge.ReadableMap;
3131
import com.facebook.react.bridge.WritableMap;
3232
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
33+
import com.sensorsdata.analytics.property.RNPropertyManager;
3334
import com.sensorsdata.analytics.utils.RNUtils;
3435

3536
import org.json.JSONObject;
@@ -95,7 +96,7 @@ public String getName() {
9596
@ReactMethod
9697
public void track(String eventName, ReadableMap properties) {
9798
try {
98-
SensorsDataAPI.sharedInstance().track(eventName, RNUtils.convertToJSONObject(properties));
99+
SensorsDataAPI.sharedInstance().track(eventName, RNPropertyManager.mergeProperty(RNUtils.convertToJSONObject(properties)));
99100
} catch (Exception e) {
100101
e.printStackTrace();
101102
Log.e(LOGTAG, e.toString() + "");
@@ -167,7 +168,7 @@ public void trackTimerBegin(String eventName) {
167168
@ReactMethod
168169
public void trackTimerEnd(String eventName, ReadableMap properties) {
169170
try {
170-
SensorsDataAPI.sharedInstance().trackTimerEnd(eventName, RNUtils.convertToJSONObject(properties));
171+
SensorsDataAPI.sharedInstance().trackTimerEnd(eventName, RNPropertyManager.mergeProperty(RNUtils.convertToJSONObject(properties)));
171172
} catch (Exception e) {
172173
e.printStackTrace();
173174
Log.e(LOGTAG, e.toString() + "");
@@ -211,7 +212,7 @@ public void clearTrackTimer() {
211212
@ReactMethod
212213
public void login(String loginId) {
213214
try {
214-
SensorsDataAPI.sharedInstance().login(loginId);
215+
SensorsDataAPI.sharedInstance().login(loginId, RNPropertyManager.mergeProperty(null));
215216
} catch (Exception e) {
216217
e.printStackTrace();
217218
Log.e(LOGTAG, e.toString() + "");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.List;
2929

3030
public class RNSensorsAnalyticsPackage implements ReactPackage {
31-
public static final String VERSION = "2.0.7";
31+
public static final String VERSION = "2.0.8";
3232
@Override
3333
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
3434
List<NativeModule> modules = new ArrayList<>();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
import com.facebook.react.bridge.ReadableMap;
2727
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
2828
import com.sensorsdata.analytics.android.sdk.SALog;
29+
import com.sensorsdata.analytics.property.LibMethodInterceptor;
2930
import com.sensorsdata.analytics.utils.RNUtils;
3031
import com.sensorsdata.analytics.utils.RNViewUtils;
32+
import com.sensorsdata.analytics.property.RNPropertyManager;
33+
import com.sensorsdata.analytics.property.PluginVersionInterceptor;
3134

3235
import org.json.JSONObject;
3336

@@ -54,6 +57,8 @@ public RNSensorsDataModule(ReactApplicationContext reactContext) {
5457

5558
}
5659
RNAgent.ignoreView();
60+
RNPropertyManager.addInterceptor(new PluginVersionInterceptor());
61+
RNPropertyManager.addInterceptor(new LibMethodInterceptor());
5762
}
5863

5964
private static final String MODULE_NAME = "RNSensorsDataModule";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Created by chenru on 2021/01/05.
3+
* Copyright 2015-2021 Sensors Data Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.sensorsdata.analytics.property;
19+
20+
import com.sensorsdata.analytics.property.RNPropertyManager.Interceptor;
21+
22+
import org.json.JSONObject;
23+
24+
public class LibMethodInterceptor implements Interceptor {
25+
26+
public JSONObject proceed(JSONObject properties, boolean isAuto) {
27+
if (properties == null) {
28+
properties = new JSONObject();
29+
}
30+
try {
31+
if (!"autoTrack".equals(properties.optString("$lib_method"))) {
32+
if (isAuto) {
33+
properties.put("$lib_method", "autoTrack");
34+
} else {
35+
properties.put("$lib_method", "code");
36+
}
37+
}
38+
} catch (Exception ignored) {
39+
40+
}
41+
return properties;
42+
}
43+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Created by chenru on 2020/12/27.
3+
* Copyright 2015-2021 Sensors Data Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.sensorsdata.analytics.property;
19+
20+
import com.sensorsdata.analytics.RNSensorsAnalyticsPackage;
21+
import com.sensorsdata.analytics.property.RNPropertyManager.Interceptor;
22+
23+
import org.json.JSONArray;
24+
import org.json.JSONObject;
25+
26+
public class PluginVersionInterceptor implements Interceptor {
27+
private static boolean isMergePluginVersion = false;
28+
29+
public JSONObject proceed(JSONObject properties, boolean isAuto){
30+
if(!isMergePluginVersion){
31+
if(properties == null){
32+
properties = new JSONObject();
33+
}else if(properties.has("$lib_plugin_version")){
34+
return properties;
35+
}
36+
try{
37+
JSONArray array = new JSONArray();
38+
array.put("react_native:" + RNSensorsAnalyticsPackage.VERSION);
39+
properties.put("$lib_plugin_version",array);
40+
}catch (Exception ignored){
41+
//ignore
42+
}
43+
isMergePluginVersion = true;
44+
}
45+
return properties;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Created by chenru on 2020/12/27.
3+
* Copyright 2015-2021 Sensors Data Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.sensorsdata.analytics.property;
19+
20+
import org.json.JSONObject;
21+
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
public class RNPropertyManager {
26+
27+
public static List<Interceptor> interceptors = new ArrayList<>();
28+
29+
public static void addInterceptor(Interceptor interceptor){
30+
interceptors.add(interceptor);
31+
}
32+
33+
public static JSONObject mergeProperty(JSONObject properties){
34+
return mergeProperty(properties, false);
35+
}
36+
37+
public static JSONObject mergeProperty(JSONObject properties, boolean isAuto){
38+
for(Interceptor interceptor:interceptors){
39+
properties = interceptor.proceed(properties, isAuto);
40+
}
41+
return properties;
42+
}
43+
44+
interface Interceptor{
45+
JSONObject proceed(JSONObject properties, boolean isAuto);
46+
}
47+
}

ios/RNSensorsAnalyticsModule.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,30 @@
33
// RNSensorsAnalyticsModule
44
//
55
// Created by 肖彦敏 on 2017/4/14.
6-
// Copyright © 2017年 Facebook. All rights reserved.
6+
// Copyright © 2017-2021 Sensors Data Co., Ltd. All rights reserved.
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
719
//
820

921
#import <Foundation/Foundation.h>
10-
#if __has_include("RCTBridgeModule.h")
11-
#import "RCTBridgeModule.h"
12-
#else
22+
#if __has_include(<React/RCTBridgeModule.h>)
1323
#import <React/RCTBridgeModule.h>
24+
#else
25+
#import "RCTBridgeModule.h"
1426
#endif
1527

28+
extern NSString *const kSAReactNativePluginVersion;
29+
1630
@interface RNSensorsAnalyticsModule : NSObject<RCTBridgeModule>
1731

1832
@end

0 commit comments

Comments
 (0)