From 90bda7cfe88d2fcc5f6a5593b3c6f1b39629bfa0 Mon Sep 17 00:00:00 2001 From: chenru Date: Mon, 1 Mar 2021 20:12:50 +0800 Subject: [PATCH] Release 2.0.8 --- RNSensorsAnalyticsModule.podspec | 2 +- SensorsDataRNHook.js | 13 ++++- .../com/sensorsdata/analytics/RNAgent.java | 5 +- .../analytics/RNSensorsAnalyticsModule.java | 7 ++- .../analytics/RNSensorsAnalyticsPackage.java | 2 +- .../analytics/RNSensorsDataModule.java | 5 ++ .../property/LibMethodInterceptor.java | 43 ++++++++++++++ .../property/PluginVersionInterceptor.java | 47 ++++++++++++++++ .../analytics/property/RNPropertyManager.java | 47 ++++++++++++++++ ios/RNSensorsAnalyticsModule.h | 22 ++++++-- ios/RNSensorsAnalyticsModule.m | 39 ++++++++++--- .../project.pbxproj | 6 ++ ios/RNSensorsDataModule.h | 20 +++++-- ios/RNSensorsDataModule.m | 18 +++++- ios/SAReactNativeCategory.h | 2 +- ios/SAReactNativeCategory.m | 2 +- ios/SAReactNativeEventProperty.h | 38 +++++++++++++ ios/SAReactNativeEventProperty.m | 56 +++++++++++++++++++ ios/SAReactNativeManager.h | 2 +- ios/SAReactNativeManager.m | 15 +++-- ios/SAReactNativeswizzler.h | 15 ++++- ios/SAReactNativeswizzler.m | 4 +- package.json | 2 +- 23 files changed, 373 insertions(+), 39 deletions(-) create mode 100644 android/src/main/java/com/sensorsdata/analytics/property/LibMethodInterceptor.java create mode 100644 android/src/main/java/com/sensorsdata/analytics/property/PluginVersionInterceptor.java create mode 100644 android/src/main/java/com/sensorsdata/analytics/property/RNPropertyManager.java create mode 100644 ios/SAReactNativeEventProperty.h create mode 100644 ios/SAReactNativeEventProperty.m diff --git a/RNSensorsAnalyticsModule.podspec b/RNSensorsAnalyticsModule.podspec index 024c80f..bab317b 100644 --- a/RNSensorsAnalyticsModule.podspec +++ b/RNSensorsAnalyticsModule.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "RNSensorsAnalyticsModule" - s.version = "2.0.7" + s.version = "2.0.8" s.summary = "The official React Native SDK of Sensors Analytics." s.description = <<-DESC 神策分析 RN 组件 diff --git a/SensorsDataRNHook.js b/SensorsDataRNHook.js index e9bfdb6..2bdde18 100644 --- a/SensorsDataRNHook.js +++ b/SensorsDataRNHook.js @@ -90,6 +90,17 @@ var sensorsdataSwitchHookCode = "if(this.props.onChange != null || this.props.on +" })(this); /* SENSORSDATA HOOK */}"; var sensorsdataImportReactNativeHookCode ="import ReactNative from 'react-native';\n"; var sensorsdataNavigation5HookCode = ` + + function getCurrentRouteName(){ + let state = getRootState(); + if (state === undefined) { + return undefined; + } + while (state.routes[state.index].state !== undefined) { + state = state.routes[state.index].state as NavigationState; + } + return state.routes[state.index].name; + } function getParams(state:any):any{ if(!state){ return null; @@ -113,7 +124,7 @@ var sensorsdataNavigation5HookCode = ` trackViewScreen(route.state); return; } - var screenName = getCurrentRoute()?.name; + var screenName = getCurrentRouteName(); var params = getParams(state); var saProperties = {}; if (params) { diff --git a/android/src/main/java/com/sensorsdata/analytics/RNAgent.java b/android/src/main/java/com/sensorsdata/analytics/RNAgent.java index 0b76a93..0cb7ed0 100644 --- a/android/src/main/java/com/sensorsdata/analytics/RNAgent.java +++ b/android/src/main/java/com/sensorsdata/analytics/RNAgent.java @@ -25,6 +25,7 @@ import com.sensorsdata.analytics.RNSensorsAnalyticsModule; import com.sensorsdata.analytics.utils.RNViewUtils; import com.sensorsdata.analytics.data.SAViewProperties; +import com.sensorsdata.analytics.property.RNPropertyManager; import com.facebook.react.uimanager.JSTouchDispatcher; import com.facebook.react.uimanager.events.EventDispatcher; @@ -75,7 +76,7 @@ public static void trackViewScreen(String url, JSONObject properties, boolean is if (isAuto && SensorsDataAPI.sharedInstance().isAutoTrackEventTypeIgnored(SensorsDataAPI.AutoTrackEventType.APP_VIEW_SCREEN)) { return; } - SensorsDataAPI.sharedInstance().trackViewScreen(url, properties); + SensorsDataAPI.sharedInstance().trackViewScreen(url, RNPropertyManager.mergeProperty(properties, isAuto)); }catch(Exception e){ SALog.printStackTrace(e); } @@ -108,7 +109,7 @@ public static void trackViewClick(int viewId){ viewProperties.properties.remove("ignore"); SensorsDataUtils.mergeJSONObject(viewProperties.properties, properties); } - SensorsDataAPI.sharedInstance().trackViewAppClick(clickView, properties); + SensorsDataAPI.sharedInstance().trackViewAppClick(clickView, RNPropertyManager.mergeProperty(properties ,true)); } } catch (Exception e) { SALog.printStackTrace(e); diff --git a/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsModule.java b/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsModule.java index b010d73..e2b7fb7 100755 --- a/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsModule.java +++ b/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsModule.java @@ -30,6 +30,7 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; import com.sensorsdata.analytics.android.sdk.SensorsDataAPI; +import com.sensorsdata.analytics.property.RNPropertyManager; import com.sensorsdata.analytics.utils.RNUtils; import org.json.JSONObject; @@ -95,7 +96,7 @@ public String getName() { @ReactMethod public void track(String eventName, ReadableMap properties) { try { - SensorsDataAPI.sharedInstance().track(eventName, RNUtils.convertToJSONObject(properties)); + SensorsDataAPI.sharedInstance().track(eventName, RNPropertyManager.mergeProperty(RNUtils.convertToJSONObject(properties))); } catch (Exception e) { e.printStackTrace(); Log.e(LOGTAG, e.toString() + ""); @@ -167,7 +168,7 @@ public void trackTimerBegin(String eventName) { @ReactMethod public void trackTimerEnd(String eventName, ReadableMap properties) { try { - SensorsDataAPI.sharedInstance().trackTimerEnd(eventName, RNUtils.convertToJSONObject(properties)); + SensorsDataAPI.sharedInstance().trackTimerEnd(eventName, RNPropertyManager.mergeProperty(RNUtils.convertToJSONObject(properties))); } catch (Exception e) { e.printStackTrace(); Log.e(LOGTAG, e.toString() + ""); @@ -211,7 +212,7 @@ public void clearTrackTimer() { @ReactMethod public void login(String loginId) { try { - SensorsDataAPI.sharedInstance().login(loginId); + SensorsDataAPI.sharedInstance().login(loginId, RNPropertyManager.mergeProperty(null)); } catch (Exception e) { e.printStackTrace(); Log.e(LOGTAG, e.toString() + ""); diff --git a/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java b/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java index 5b7ef02..bfc0497 100644 --- a/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java +++ b/android/src/main/java/com/sensorsdata/analytics/RNSensorsAnalyticsPackage.java @@ -28,7 +28,7 @@ import java.util.List; public class RNSensorsAnalyticsPackage implements ReactPackage { - public static final String VERSION = "2.0.7"; + public static final String VERSION = "2.0.8"; @Override public List createNativeModules(ReactApplicationContext reactContext) { List modules = new ArrayList<>(); diff --git a/android/src/main/java/com/sensorsdata/analytics/RNSensorsDataModule.java b/android/src/main/java/com/sensorsdata/analytics/RNSensorsDataModule.java index acf83b7..cf3796c 100755 --- a/android/src/main/java/com/sensorsdata/analytics/RNSensorsDataModule.java +++ b/android/src/main/java/com/sensorsdata/analytics/RNSensorsDataModule.java @@ -26,8 +26,11 @@ import com.facebook.react.bridge.ReadableMap; import com.sensorsdata.analytics.android.sdk.SensorsDataAPI; import com.sensorsdata.analytics.android.sdk.SALog; +import com.sensorsdata.analytics.property.LibMethodInterceptor; import com.sensorsdata.analytics.utils.RNUtils; import com.sensorsdata.analytics.utils.RNViewUtils; +import com.sensorsdata.analytics.property.RNPropertyManager; +import com.sensorsdata.analytics.property.PluginVersionInterceptor; import org.json.JSONObject; @@ -54,6 +57,8 @@ public RNSensorsDataModule(ReactApplicationContext reactContext) { } RNAgent.ignoreView(); + RNPropertyManager.addInterceptor(new PluginVersionInterceptor()); + RNPropertyManager.addInterceptor(new LibMethodInterceptor()); } private static final String MODULE_NAME = "RNSensorsDataModule"; diff --git a/android/src/main/java/com/sensorsdata/analytics/property/LibMethodInterceptor.java b/android/src/main/java/com/sensorsdata/analytics/property/LibMethodInterceptor.java new file mode 100644 index 0000000..7280e7b --- /dev/null +++ b/android/src/main/java/com/sensorsdata/analytics/property/LibMethodInterceptor.java @@ -0,0 +1,43 @@ +/* + * Created by chenru on 2021/01/05. + * Copyright 2015-2021 Sensors Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.sensorsdata.analytics.property; + +import com.sensorsdata.analytics.property.RNPropertyManager.Interceptor; + +import org.json.JSONObject; + +public class LibMethodInterceptor implements Interceptor { + + public JSONObject proceed(JSONObject properties, boolean isAuto) { + if (properties == null) { + properties = new JSONObject(); + } + try { + if (!"autoTrack".equals(properties.optString("$lib_method"))) { + if (isAuto) { + properties.put("$lib_method", "autoTrack"); + } else { + properties.put("$lib_method", "code"); + } + } + } catch (Exception ignored) { + + } + return properties; + } +} diff --git a/android/src/main/java/com/sensorsdata/analytics/property/PluginVersionInterceptor.java b/android/src/main/java/com/sensorsdata/analytics/property/PluginVersionInterceptor.java new file mode 100644 index 0000000..253049d --- /dev/null +++ b/android/src/main/java/com/sensorsdata/analytics/property/PluginVersionInterceptor.java @@ -0,0 +1,47 @@ +/* + * Created by chenru on 2020/12/27. + * Copyright 2015-2021 Sensors Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.sensorsdata.analytics.property; + +import com.sensorsdata.analytics.RNSensorsAnalyticsPackage; +import com.sensorsdata.analytics.property.RNPropertyManager.Interceptor; + +import org.json.JSONArray; +import org.json.JSONObject; + +public class PluginVersionInterceptor implements Interceptor { + private static boolean isMergePluginVersion = false; + + public JSONObject proceed(JSONObject properties, boolean isAuto){ + if(!isMergePluginVersion){ + if(properties == null){ + properties = new JSONObject(); + }else if(properties.has("$lib_plugin_version")){ + return properties; + } + try{ + JSONArray array = new JSONArray(); + array.put("react_native:" + RNSensorsAnalyticsPackage.VERSION); + properties.put("$lib_plugin_version",array); + }catch (Exception ignored){ + //ignore + } + isMergePluginVersion = true; + } + return properties; + } +} \ No newline at end of file diff --git a/android/src/main/java/com/sensorsdata/analytics/property/RNPropertyManager.java b/android/src/main/java/com/sensorsdata/analytics/property/RNPropertyManager.java new file mode 100644 index 0000000..53ef1b7 --- /dev/null +++ b/android/src/main/java/com/sensorsdata/analytics/property/RNPropertyManager.java @@ -0,0 +1,47 @@ +/* + * Created by chenru on 2020/12/27. + * Copyright 2015-2021 Sensors Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.sensorsdata.analytics.property; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class RNPropertyManager { + + public static List interceptors = new ArrayList<>(); + + public static void addInterceptor(Interceptor interceptor){ + interceptors.add(interceptor); + } + + public static JSONObject mergeProperty(JSONObject properties){ + return mergeProperty(properties, false); + } + + public static JSONObject mergeProperty(JSONObject properties, boolean isAuto){ + for(Interceptor interceptor:interceptors){ + properties = interceptor.proceed(properties, isAuto); + } + return properties; + } + + interface Interceptor{ + JSONObject proceed(JSONObject properties, boolean isAuto); + } +} \ No newline at end of file diff --git a/ios/RNSensorsAnalyticsModule.h b/ios/RNSensorsAnalyticsModule.h index 969424d..1a5a4f4 100644 --- a/ios/RNSensorsAnalyticsModule.h +++ b/ios/RNSensorsAnalyticsModule.h @@ -3,16 +3,30 @@ // RNSensorsAnalyticsModule // // Created by 肖彦敏 on 2017/4/14. -// Copyright © 2017年 Facebook. All rights reserved. +// Copyright © 2017-2021 Sensors Data Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. // #import -#if __has_include("RCTBridgeModule.h") -#import "RCTBridgeModule.h" -#else +#if __has_include() #import +#else +#import "RCTBridgeModule.h" #endif +extern NSString *const kSAReactNativePluginVersion; + @interface RNSensorsAnalyticsModule : NSObject @end diff --git a/ios/RNSensorsAnalyticsModule.m b/ios/RNSensorsAnalyticsModule.m index 07f4a30..3f9dcf4 100644 --- a/ios/RNSensorsAnalyticsModule.m +++ b/ios/RNSensorsAnalyticsModule.m @@ -3,18 +3,36 @@ // RNSensorsAnalyticsModule // // Created by 肖彦敏 on 2017/4/14. -// Copyright © 2017年 Facebook. All rights reserved. +// Copyright © 2017-2021 Sensors Data Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. // -#import "RNSensorsAnalyticsModule.h" -#import "SAReactNativeManager.h" +#if ! __has_feature(objc_arc) +#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag on this file. +#endif -#if __has_include("SensorsAnalyticsSDK.h") -#import "SensorsAnalyticsSDK.h" -#else +#if __has_include() #import +#else +#import "SensorsAnalyticsSDK.h" #endif +#import "RNSensorsAnalyticsModule.h" +#import "SAReactNativeManager.h" +#import "SAReactNativeEventProperty.h" + +NSString *const kSAReactNativePluginVersion = @"react_native:2.0.8"; @implementation RNSensorsAnalyticsModule @@ -36,7 +54,8 @@ @implementation RNSensorsAnalyticsModule RCT_EXPORT_METHOD(track:(NSString *)event withProperties:(NSDictionary *)propertyDict){ @try { - [[SensorsAnalyticsSDK sharedInstance] track:event withProperties:propertyDict]; + NSDictionary *properties = [SAReactNativeEventProperty eventProperties:propertyDict]; + [[SensorsAnalyticsSDK sharedInstance] track:event withProperties:properties]; } @catch (NSException *exception) { NSLog(@"[RNSensorsAnalytics] error:%@",exception); } @@ -97,7 +116,8 @@ @implementation RNSensorsAnalyticsModule */ RCT_EXPORT_METHOD(trackTimerEnd:(NSString *)event withProperties:(NSDictionary *)propertyDict){ @try { - [[SensorsAnalyticsSDK sharedInstance] trackTimerEnd:event withProperties:propertyDict]; + NSDictionary *properties = [SAReactNativeEventProperty eventProperties:propertyDict]; + [[SensorsAnalyticsSDK sharedInstance] trackTimerEnd:event withProperties:properties]; } @catch (NSException *exception) { NSLog(@"[RNSensorsAnalytics] error:%@",exception); } @@ -165,7 +185,8 @@ @implementation RNSensorsAnalyticsModule */ RCT_EXPORT_METHOD(login:(NSString *)loginId){ @try { - [[SensorsAnalyticsSDK sharedInstance] login:loginId]; + NSDictionary *properties = [SAReactNativeEventProperty eventProperties:nil]; + [[SensorsAnalyticsSDK sharedInstance] login:loginId withProperties:properties]; } @catch (NSException *exception) { NSLog(@"[RNSensorsAnalytics] error:%@",exception); } diff --git a/ios/RNSensorsAnalyticsModule.xcodeproj/project.pbxproj b/ios/RNSensorsAnalyticsModule.xcodeproj/project.pbxproj index 1401ece..ede410e 100644 --- a/ios/RNSensorsAnalyticsModule.xcodeproj/project.pbxproj +++ b/ios/RNSensorsAnalyticsModule.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ A18E9FB421A6AEDD00A66E41 /* RNSensorsAnalyticsModule.m in Sources */ = {isa = PBXBuildFile; fileRef = A18E9FB221A6AEDD00A66E41 /* RNSensorsAnalyticsModule.m */; }; FC045CC2246D191C007117C1 /* SAReactNativeswizzler.m in Sources */ = {isa = PBXBuildFile; fileRef = FC045CC1246D191C007117C1 /* SAReactNativeswizzler.m */; }; FC39004C244715AE00F486A7 /* SAReactNativeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FC39004B244715AE00F486A7 /* SAReactNativeManager.m */; }; + FC6EF7A9259DA6A40099EEB5 /* SAReactNativeEventProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = FC6EF7A8259DA6A40099EEB5 /* SAReactNativeEventProperty.m */; }; FC9EE671243731C000C45D16 /* RNSensorsDataModule.m in Sources */ = {isa = PBXBuildFile; fileRef = FC9EE670243731C000C45D16 /* RNSensorsDataModule.m */; }; FCD3CF2B25466B7800758260 /* SAReactNativeCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = FCD3CF2A25466B7800758260 /* SAReactNativeCategory.m */; }; /* End PBXBuildFile section */ @@ -34,6 +35,8 @@ FC045CC1246D191C007117C1 /* SAReactNativeswizzler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAReactNativeswizzler.m; sourceTree = ""; }; FC39004A244715AE00F486A7 /* SAReactNativeManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SAReactNativeManager.h; sourceTree = ""; }; FC39004B244715AE00F486A7 /* SAReactNativeManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAReactNativeManager.m; sourceTree = ""; }; + FC6EF7A7259DA6A40099EEB5 /* SAReactNativeEventProperty.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SAReactNativeEventProperty.h; sourceTree = ""; }; + FC6EF7A8259DA6A40099EEB5 /* SAReactNativeEventProperty.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAReactNativeEventProperty.m; sourceTree = ""; }; FC9EE66F243731C000C45D16 /* RNSensorsDataModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSensorsDataModule.h; sourceTree = ""; }; FC9EE670243731C000C45D16 /* RNSensorsDataModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSensorsDataModule.m; sourceTree = ""; }; FCD3CF2925466B7800758260 /* SAReactNativeCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAReactNativeCategory.h; sourceTree = ""; }; @@ -60,6 +63,8 @@ FC9EE670243731C000C45D16 /* RNSensorsDataModule.m */, FC39004A244715AE00F486A7 /* SAReactNativeManager.h */, FC39004B244715AE00F486A7 /* SAReactNativeManager.m */, + FC6EF7A7259DA6A40099EEB5 /* SAReactNativeEventProperty.h */, + FC6EF7A8259DA6A40099EEB5 /* SAReactNativeEventProperty.m */, FCD3CF2925466B7800758260 /* SAReactNativeCategory.h */, FCD3CF2A25466B7800758260 /* SAReactNativeCategory.m */, FC045CC0246D191C007117C1 /* SAReactNativeswizzler.h */, @@ -135,6 +140,7 @@ A18E9FB421A6AEDD00A66E41 /* RNSensorsAnalyticsModule.m in Sources */, FC045CC2246D191C007117C1 /* SAReactNativeswizzler.m in Sources */, FC39004C244715AE00F486A7 /* SAReactNativeManager.m in Sources */, + FC6EF7A9259DA6A40099EEB5 /* SAReactNativeEventProperty.m in Sources */, FCD3CF2B25466B7800758260 /* SAReactNativeCategory.m in Sources */, FC9EE671243731C000C45D16 /* RNSensorsDataModule.m in Sources */, ); diff --git a/ios/RNSensorsDataModule.h b/ios/RNSensorsDataModule.h index ebd206c..6d8c510 100644 --- a/ios/RNSensorsDataModule.h +++ b/ios/RNSensorsDataModule.h @@ -3,15 +3,27 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/4/3. -// Copyright © 2020 ziven.mac. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. // #import -#if __has_include("RCTBridgeModule.h") -#import "RCTBridgeModule.h" -#else +#if __has_include() #import +#else +#import "RCTBridgeModule.h" #endif NS_ASSUME_NONNULL_BEGIN diff --git a/ios/RNSensorsDataModule.m b/ios/RNSensorsDataModule.m index 0471e8a..a77d28a 100644 --- a/ios/RNSensorsDataModule.m +++ b/ios/RNSensorsDataModule.m @@ -3,8 +3,24 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/4/3. -// Copyright © 2020 ziven.mac. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. // +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#if ! __has_feature(objc_arc) +#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag on this file. +#endif #import "RNSensorsDataModule.h" #import "SAReactNativeManager.h" diff --git a/ios/SAReactNativeCategory.h b/ios/SAReactNativeCategory.h index 3b918d2..8f60c2b 100644 --- a/ios/SAReactNativeCategory.h +++ b/ios/SAReactNativeCategory.h @@ -3,7 +3,7 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/10/26. -// Copyright © 2020 Sensors Data Co., Ltd. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/ios/SAReactNativeCategory.m b/ios/SAReactNativeCategory.m index 799b38f..3faf93d 100644 --- a/ios/SAReactNativeCategory.m +++ b/ios/SAReactNativeCategory.m @@ -3,7 +3,7 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/10/26. -// Copyright © 2020 Sensors Data Co., Ltd. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/ios/SAReactNativeEventProperty.h b/ios/SAReactNativeEventProperty.h new file mode 100644 index 0000000..e9a9c0b --- /dev/null +++ b/ios/SAReactNativeEventProperty.h @@ -0,0 +1,38 @@ +// +// SAReactNativeEventProperty.h +// RNSensorsAnalyticsModule +// +// Created by 彭远洋 on 2020/12/31. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SAReactNativeEventProperty : NSObject + +/// 事件属性中添加 $lib_method 和 $lib_plugin_version 属性,$lib_method 默认为 code +/// @param properties 事件自定义属性 ++ (NSDictionary *)eventProperties:(nullable NSDictionary *)properties; + +/// 事件属性中添加 $lib_method 和 $lib_plugin_version 属性 +/// @param properties 事件自定义属性 +/// @param isAuto 设置为 YES 时 $lib_method 为 autoTrack,为 NO 时 $lib_method 为 code ++ (NSDictionary *)eventProperties:(nullable NSDictionary *)properties isAuto:(BOOL)isAuto; + +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/SAReactNativeEventProperty.m b/ios/SAReactNativeEventProperty.m new file mode 100644 index 0000000..d50bc96 --- /dev/null +++ b/ios/SAReactNativeEventProperty.m @@ -0,0 +1,56 @@ +// +// SAReactNativeEventProperty.m +// RNSensorsAnalyticsModule +// +// Created by 彭远洋 on 2020/12/31. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#if ! __has_feature(objc_arc) +#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag on this file. +#endif + +#import "SAReactNativeEventProperty.h" +#import "RNSensorsAnalyticsModule.h" + +NSString *const kSALibPluginVersionKey = @"$lib_plugin_version"; + +@implementation SAReactNativeEventProperty + ++ (NSDictionary *)eventProperties:(NSDictionary *)properties { + return [self eventProperties:properties isAuto:NO]; +} + ++ (NSDictionary *)eventProperties:(NSDictionary *)properties isAuto:(BOOL)isAuto { + NSMutableDictionary *result = [NSMutableDictionary dictionary]; + [result addEntriesFromDictionary:properties]; + NSString *libMethod = @"code"; + if (isAuto || [result[@"$lib_method"] isEqualToString:@"autoTrack"]) { + // 当自定义属性中设置的 $lib_method 为 autoTrack 时有效,其他内容时 $lib_method 为 code + // isAuto:当触发事件为全埋点时,$lib_method 为 autoTrack 且不可修改 + libMethod = @"autoTrack"; + } + result[@"$lib_method"] = libMethod; + if (result[kSALibPluginVersionKey]) { + return result; + } + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + result[kSALibPluginVersionKey] = @[kSAReactNativePluginVersion]; + }); + return result; +} + +@end diff --git a/ios/SAReactNativeManager.h b/ios/SAReactNativeManager.h index 2bb9727..7a02e72 100644 --- a/ios/SAReactNativeManager.h +++ b/ios/SAReactNativeManager.h @@ -3,7 +3,7 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/3/16. -// Copyright © 2020 Sensors Data Co., Ltd. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/ios/SAReactNativeManager.m b/ios/SAReactNativeManager.m index dfc45d3..d6bd8d1 100644 --- a/ios/SAReactNativeManager.m +++ b/ios/SAReactNativeManager.m @@ -3,7 +3,7 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/3/16. -// Copyright © 2020 Sensors Data Co., Ltd. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,12 +24,13 @@ #import "SAReactNativeManager.h" #import "SAReactNativeCategory.h" +#import "SAReactNativeEventProperty.h" #import -#if __has_include("SensorsAnalyticsSDK.h") -#import "SensorsAnalyticsSDK.h" -#else +#if __has_include() #import +#else +#import "SensorsAnalyticsSDK.h" #endif #pragma mark - Constants @@ -191,7 +192,8 @@ - (void)trackViewClick:(NSNumber *)reactTag { properties[kSAEventElementContentProperty] = content; [properties addEntriesFromDictionary:self.screenProperties]; [properties addEntriesFromDictionary:viewProperties.properties]; - [[SensorsAnalyticsSDK sharedInstance] trackViewAppClick:view withProperties:[properties copy]]; + NSDictionary *newProps = [SAReactNativeEventProperty eventProperties:properties isAuto:YES]; + [[SensorsAnalyticsSDK sharedInstance] trackViewAppClick:view withProperties:newProps]; }); } @@ -226,7 +228,8 @@ - (void)trackViewScreen:(nullable NSString *)url properties:(nullable NSDictiona dispatch_async(dispatch_get_main_queue(), ^{ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [[SensorsAnalyticsSDK sharedInstance] trackViewScreen:url withProperties:[eventProps copy]]; + NSDictionary *properties = [SAReactNativeEventProperty eventProperties:eventProps isAuto:autoTrack]; + [[SensorsAnalyticsSDK sharedInstance] trackViewScreen:url withProperties:properties]; #pragma clang diagnostic pop }); } diff --git a/ios/SAReactNativeswizzler.h b/ios/SAReactNativeswizzler.h index c46ee1c..9424788 100644 --- a/ios/SAReactNativeswizzler.h +++ b/ios/SAReactNativeswizzler.h @@ -3,7 +3,20 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/5/14. -// Copyright © 2020 ziven.mac. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// // #import diff --git a/ios/SAReactNativeswizzler.m b/ios/SAReactNativeswizzler.m index 47e1c92..f231f04 100644 --- a/ios/SAReactNativeswizzler.m +++ b/ios/SAReactNativeswizzler.m @@ -3,13 +3,13 @@ // RNSensorsAnalyticsModule // // Created by 彭远洋 on 2020/5/14. -// Copyright © 2020 ziven.mac. All rights reserved. +// Copyright © 2020-2021 Sensors Data Co., Ltd. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/package.json b/package.json index c363fa7..0bbb521 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sensorsdata-analytics-react-native", - "version": "2.0.7", + "version": "2.0.8", "private": false, "description": "神策分析 RN 组件", "main": "index.js",