Skip to content

Commit d8abcb1

Browse files
author
weiqiangliu
committed
Release 2.2.1
1 parent fd8c9b0 commit d8abcb1

16 files changed

+380
-92
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
SensorsAnalytics SDK 是国内第一家开源商用版用户行为采集 SDK,目前支持代码埋点、全埋点、App 点击图、可视化全埋点等。目前已累计有 1500 多家付费客户,2500+ 的 App 集成使用,作为 App 数据采集利器,致力于帮助客户挖掘更多的商业价值,为其精准运营和业务支撑提供了可靠的数据来源。其采集全面而灵活、性能良好,并一直保持稳定的迭代,经受住了时间和客户的考验。
1616

1717
## 基本要求
18-
App 元素点击事件要求 React Native 0.23 ~ 0.66;
18+
App 元素点击事件要求 React Native 0.23 ~ 0.66;
1919
App 页面浏览事件要求 React Navigation ^2.0 ~ ^5.0;
20-
App 可视化全埋点要求 React Native 0.46 ~ 0.66;
20+
App 可视化全埋点要求 React Native 0.46 ~ 0.66;
2121
App 点击事件自定义属性要求 React Native 0.46 ~ 0.66。
2222

2323
## 集成方式
@@ -42,9 +42,9 @@ react-native link sensorsdata-analytics-react-native
4242
}
4343
```
4444

45-
#### 4. 执行 npm install 命令
45+
#### 4. 执行 npm 命令
4646
```sh
47-
npm install
47+
npm run-script postinstall
4848
```
4949

5050
### 详细文档请参考:[Android & iOS SDK 在 React Native 中使用说明](https://www.sensorsdata.cn/manual/sdk_reactnative.html)

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

SensorsDataRNHook.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,24 @@ sensorsdataHookClickableRN = function (reset = false) {
823823
var saProps = eachProgress(saElement);
824824
var ReactNative = require('react-native');
825825
var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
826-
dataModule && dataModule.saveViewProperties && dataModule.saveViewProperties(${tagName}, true , saProps);
826+
827+
if(dataModule && dataModule.saveRootViewProperties) {
828+
var saRootTag;
829+
if(typeof nativeTopRootTag !== 'undefined') {
830+
saRootTag = nativeTopRootTag;
831+
} else if(typeof rootContainerInstance !== 'undefined') {
832+
saRootTag = rootContainerInstance;
833+
} else if(typeof renderExpirationTime !== 'undefined') {
834+
saRootTag = renderExpirationTime;
835+
} else if(typeof renderLanes !== 'undefined') {
836+
saRootTag = renderLanes;
837+
}
838+
if (saRootTag && (typeof saRootTag === 'number')) {
839+
dataModule.saveRootViewProperties(${tagName}, true , saProps, saRootTag);
840+
return;
841+
}
842+
}
843+
dataModule && dataModule.saveViewProperties && dataModule.saveViewProperties(${tagName}, true , saProps);
827844
}
828845
}`;
829846
var call = addTryCatch(functionBody);

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.2.0";
31+
public static final String VERSION = "2.2.1";
3232
@Override
3333
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
3434
List<NativeModule> modules = new ArrayList<>();

ios/RNSensorsAnalyticsModule.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#import "SAReactNativeManager.h"
3333
#import "SAReactNativeEventProperty.h"
3434

35-
NSString *const kSAReactNativePluginVersion = @"react_native:2.2.0";
35+
NSString *const kSAReactNativePluginVersion = @"react_native:2.2.1";
3636

3737
@implementation RNSensorsAnalyticsModule
3838

ios/RNSensorsAnalyticsModule.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
452E43642758986E0074530B /* SAReactNativeSwizzler.m in Sources */ = {isa = PBXBuildFile; fileRef = 452E43612758986E0074530B /* SAReactNativeSwizzler.m */; };
11+
4532EFF7275E319600D57554 /* SAReactNativeRootViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4532EFF6275E319600D57554 /* SAReactNativeRootViewManager.m */; };
1012
A18E9FB421A6AEDD00A66E41 /* RNSensorsAnalyticsModule.m in Sources */ = {isa = PBXBuildFile; fileRef = A18E9FB221A6AEDD00A66E41 /* RNSensorsAnalyticsModule.m */; };
1113
FC39004C244715AE00F486A7 /* SAReactNativeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FC39004B244715AE00F486A7 /* SAReactNativeManager.m */; };
1214
FC6EF7A9259DA6A40099EEB5 /* SAReactNativeEventProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = FC6EF7A8259DA6A40099EEB5 /* SAReactNativeEventProperty.m */; };
@@ -27,6 +29,10 @@
2729
/* End PBXCopyFilesBuildPhase section */
2830

2931
/* Begin PBXFileReference section */
32+
452E43612758986E0074530B /* SAReactNativeSwizzler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAReactNativeSwizzler.m; sourceTree = "<group>"; };
33+
452E43622758986E0074530B /* SAReactNativeSwizzler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAReactNativeSwizzler.h; sourceTree = "<group>"; };
34+
4532EFF5275E319600D57554 /* SAReactNativeRootViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAReactNativeRootViewManager.h; sourceTree = "<group>"; };
35+
4532EFF6275E319600D57554 /* SAReactNativeRootViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAReactNativeRootViewManager.m; sourceTree = "<group>"; };
3036
A18E9FA621A6AB4300A66E41 /* libRNSensorsAnalyticsModule.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNSensorsAnalyticsModule.a; sourceTree = BUILT_PRODUCTS_DIR; };
3137
A18E9FB221A6AEDD00A66E41 /* RNSensorsAnalyticsModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSensorsAnalyticsModule.m; sourceTree = "<group>"; };
3238
A18E9FB321A6AEDD00A66E41 /* RNSensorsAnalyticsModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSensorsAnalyticsModule.h; sourceTree = "<group>"; };
@@ -54,6 +60,10 @@
5460
A18E9F9D21A6AB4300A66E41 = {
5561
isa = PBXGroup;
5662
children = (
63+
4532EFF5275E319600D57554 /* SAReactNativeRootViewManager.h */,
64+
4532EFF6275E319600D57554 /* SAReactNativeRootViewManager.m */,
65+
452E43622758986E0074530B /* SAReactNativeSwizzler.h */,
66+
452E43612758986E0074530B /* SAReactNativeSwizzler.m */,
5767
A18E9FB321A6AEDD00A66E41 /* RNSensorsAnalyticsModule.h */,
5868
A18E9FB221A6AEDD00A66E41 /* RNSensorsAnalyticsModule.m */,
5969
FC9EE66F243731C000C45D16 /* RNSensorsDataModule.h */,
@@ -136,7 +146,9 @@
136146
FC39004C244715AE00F486A7 /* SAReactNativeManager.m in Sources */,
137147
FC6EF7A9259DA6A40099EEB5 /* SAReactNativeEventProperty.m in Sources */,
138148
FCD3CF2B25466B7800758260 /* SAReactNativeCategory.m in Sources */,
149+
452E43642758986E0074530B /* SAReactNativeSwizzler.m in Sources */,
139150
FC9EE671243731C000C45D16 /* RNSensorsDataModule.m in Sources */,
151+
4532EFF7275E319600D57554 /* SAReactNativeRootViewManager.m in Sources */,
140152
);
141153
runOnlyForDeploymentPostprocessing = 0;
142154
};

ios/RNSensorsDataModule.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,26 @@ @implementation RNSensorsDataModule
5252
[[SAReactNativeManager sharedInstance] trackViewScreen:url properties:properties autoTrack:YES];
5353
}
5454

55+
/**
56+
* React Native 保存可点击控件列表信息
57+
* 兼容旧版本 JSBundle 使用
58+
*
59+
*/
60+
RCT_EXPORT_METHOD(saveViewProperties:(NSInteger)reactTag clickable:(BOOL)clickable paramters:(NSDictionary *)paramters) {
61+
[[SAReactNativeManager sharedInstance] prepareView:@(reactTag) clickable:clickable paramters:paramters];
62+
}
63+
5564
/**
5665
* React Native 保存可点击控件列表信息
5766
*
5867
* @param reactTag 当前控件唯一标识符
5968
* @param clickable 当前控件可点击状态
6069
* @param paramters 当前控件自定义参数
70+
* @param rootTag 当前 RN 页面的唯一标识
6171
*
6272
*/
63-
RCT_EXPORT_METHOD(saveViewProperties:(NSInteger)reactTag clickable:(BOOL)clickable paramters:(NSDictionary *)paramters) {
64-
[[SAReactNativeManager sharedInstance] prepareView:@(reactTag) clickable:clickable paramters:paramters];
73+
RCT_EXPORT_METHOD(saveRootViewProperties:(NSInteger)reactTag clickable:(BOOL)clickable paramters:(NSDictionary *)paramters rootTag:(NSInteger)rootTag) {
74+
[[SAReactNativeManager sharedInstance] prepareView:@(reactTag) clickable:clickable paramters:paramters rootTag:@(rootTag)];
6575
}
6676

6777
@end

ios/SAReactNativeCategory.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#import <Foundation/Foundation.h>
2222
#import <UIKit/UIKit.h>
2323

24+
#if __has_include(<React/RCTRootView.h>)
25+
#import <React/RCTRootView.h>
26+
#else
27+
#import "RCTRootView.h"
28+
#endif
29+
2430
NS_ASSUME_NONNULL_BEGIN
2531

2632
#pragma mark - View Property
@@ -42,13 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4248

4349
@end
4450

45-
@interface UIViewController (SAReactNative)
46-
47-
/// 触发页面浏览时, 记录页面信息 (和 RCTRootView 关联: rctRootView.reactViewController)
48-
@property (nonatomic, copy) NSDictionary *sa_reactnative_screenProperties;
49-
50-
/// 用于记录 view 自定义属性 (和 RCTRootView 关联: rctRootView.reactViewController)
51-
@property (nonatomic, copy) NSSet<SAReactNativeViewProperty *> *sa_reactnative_viewProperties;
51+
@interface RCTRootView (SAReactNative)
5252

5353
@end
5454

ios/SAReactNativeCategory.m

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#import "SAReactNativeCategory.h"
2626
#import <objc/runtime.h>
27+
#import "SAReactNativeSwizzler.h"
28+
#import "SAReactNativeRootViewManager.h"
2729

2830
static void *const kSensorsAnalyticsRNScreenPropertiesKey = (void *)&kSensorsAnalyticsRNScreenPropertiesKey;
2931
static void *const kSensorsAnalyticsRNViewPropertiesKey = (void *)&kSensorsAnalyticsRNViewPropertiesKey;
@@ -49,23 +51,46 @@ - (void)setSa_reactnative_screenProperties:(NSDictionary *)sa_reactnative_screen
4951

5052
@end
5153

52-
#pragma mark - UIViewController Category
53-
@implementation UIViewController (SAReactNative)
54+
@implementation RCTRootView (SAReactNative)
5455

55-
- (NSDictionary *)sa_reactnative_screenProperties {
56-
return objc_getAssociatedObject(self, kSensorsAnalyticsRNScreenPropertiesKey);
57-
}
56+
+ (void)load {
57+
static dispatch_once_t onceToken;
58+
dispatch_once(&onceToken, ^{
59+
// React Native 0.66.0 及以后版本的 RCTRootView 指定构造器方法
60+
SEL originalSEL = NSSelectorFromString(@"initWithFrame:bridge:moduleName:initialProperties:");
61+
SEL swizzleSEL = @selector(sa_reactnative_initWithFrame:bridge:moduleName:initialProperties:);
5862

59-
- (void)setSa_reactnative_screenProperties:(NSDictionary *)sa_reactnative_screenProperties {
60-
objc_setAssociatedObject(self, kSensorsAnalyticsRNScreenPropertiesKey, sa_reactnative_screenProperties, OBJC_ASSOCIATION_COPY_NONATOMIC);
63+
if (![RCTRootView instancesRespondToSelector:originalSEL]) {
64+
// React Native 0.66.0 以前版本的 RCTRootView 指定构造器方法
65+
originalSEL = @selector(initWithBridge:moduleName:initialProperties:);
66+
swizzleSEL = @selector(sa_reactnative_initWithBridge:moduleName:initialProperties:);
67+
}
68+
69+
[RCTRootView sa_reactnative_swizzle:originalSEL withSelector:swizzleSEL];
70+
});
6171
}
6272

63-
- (NSSet<SAReactNativeViewProperty *> *)sa_reactnative_viewProperties {
64-
return objc_getAssociatedObject(self, kSensorsAnalyticsRNViewPropertiesKey);
73+
- (instancetype)sa_reactnative_initWithBridge:(RCTBridge *)bridge
74+
moduleName:(NSString *)moduleName
75+
initialProperties:(NSDictionary *)initialProperties {
76+
RCTRootView *rootView = [self sa_reactnative_initWithBridge:bridge
77+
moduleName:moduleName
78+
initialProperties:initialProperties];
79+
[SAReactNativeRootViewManager.sharedInstance addRootView:rootView];
80+
return rootView;
6581
}
6682

67-
- (void)setSa_reactnative_viewProperties:(NSSet<SAReactNativeViewProperty *> *)sa_reactnative_viewProperties {
68-
objc_setAssociatedObject(self, kSensorsAnalyticsRNViewPropertiesKey, sa_reactnative_viewProperties, OBJC_ASSOCIATION_COPY_NONATOMIC);
83+
84+
- (instancetype)sa_reactnative_initWithFrame:(CGRect)frame
85+
bridge:(RCTBridge *)bridge
86+
moduleName:(NSString *)moduleName
87+
initialProperties:(nullable NSDictionary *)initialProperties {
88+
RCTRootView *rootView = [self sa_reactnative_initWithFrame:frame
89+
bridge:bridge
90+
moduleName:moduleName
91+
initialProperties:initialProperties];
92+
[SAReactNativeRootViewManager.sharedInstance addRootView:rootView];
93+
return rootView;
6994
}
7095

7196
@end

ios/SAReactNativeManager.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,26 @@ NS_ASSUME_NONNULL_BEGIN
4444
*/
4545
- (BOOL)clickableForView:(UIView *)view;
4646

47+
/**
48+
@abstract
49+
记录 View 的点击状态及自定义属性 (会关联到当前正在显示的 RCTRootView 上)
50+
51+
@param reactTag React Native 分配的唯一标识符
52+
@param clickable 是否可点击
53+
@param paramters 自定义属性
54+
*/
55+
- (void)prepareView:(NSNumber *)reactTag clickable:(BOOL)clickable paramters:(NSDictionary *)paramters;
56+
4757
/**
4858
@abstract
4959
记录 View 的点击状态及自定义属性
5060
5161
@param reactTag React Native 分配的唯一标识符
5262
@param clickable 是否可点击
5363
@param paramters 自定义属性
54-
@return 可点击控件是否记录成功
64+
@param rootTag RCTRootView 的 reactTag
5565
*/
56-
- (BOOL)prepareView:(NSNumber *)reactTag clickable:(BOOL)clickable paramters:(NSDictionary *)paramters;
66+
- (void)prepareView:(NSNumber *)reactTag clickable:(BOOL)clickable paramters:(NSDictionary *)paramters rootTag:(NSNumber *)rootTag;
5767

5868
/**
5969
@abstract

0 commit comments

Comments
 (0)