Skip to content

Commit 44a5066

Browse files
author
chenru
committed
Release 2.0.2
1 parent 266bafa commit 44a5066

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

README.md

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

1111
## 基本要求
1212
App 元素点击事件要求 React Native 0.23 ~ 0.61.5;
13-
App 页面浏览事件要求 React Navigation ^2.0 ~ ^4.0;
13+
App 页面浏览事件要求 React Navigation ^2.0 ~ ^4.0;
1414
App 可视化全埋点要求 React Native 0.46 ~ 0.60。
1515

1616
## 集成方式

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
public class RNSensorsAnalyticsPackage implements ReactPackage {
18-
public static final String VERSION = "2.0.1";
18+
public static final String VERSION = "2.0.2";
1919
@Override
2020
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
2121
List<NativeModule> modules = new ArrayList<>();

ios/SAReactNativeManager.m

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,26 @@
3636
#import "SAReactNativeswizzler.h"
3737
#import <objc/runtime.h>
3838

39+
40+
@interface UIView(SAReactNative)
41+
@property (nonatomic, copy) NSDictionary *sa_reactnative_screenProperties;
42+
@end
43+
44+
@implementation UIView(SAReactNative)
45+
46+
- (NSDictionary *)sa_reactnative_screenProperties {
47+
return objc_getAssociatedObject(self, @"SensorsAnalyticsRNScreenProperties");
48+
}
49+
50+
- (void)setSa_reactnative_screenProperties:(NSDictionary *)sa_reactnative_screenProperties {
51+
objc_setAssociatedObject(self, @"SensorsAnalyticsRNScreenProperties", sa_reactnative_screenProperties, OBJC_ASSOCIATION_COPY_NONATOMIC);
52+
}
53+
54+
@end
55+
3956
@interface SAReactNativeManager ()
4057

41-
@property (nonatomic, copy) NSString *currentScreenName;
42-
@property (nonatomic, copy) NSString *currentTitle;
58+
@property (nonatomic, copy) NSDictionary *screenProperties;
4359
@property (nonatomic, strong) NSSet *ignoreClasses;
4460
@property (nonatomic, strong) NSMutableSet *clickableViewTags;
4561
@property (nonatomic, assign) BOOL isRootViewVisible;
@@ -167,14 +183,18 @@ - (instancetype)init {
167183

168184
#pragma mark - visualize
169185
- (NSDictionary *)visualizeProperties {
170-
return _isRootViewVisible ? [self screenProperties] : nil;
186+
return _isRootViewVisible ? self.screenProperties : nil;
171187
}
172188

173189
- (BOOL)clickableForView:(UIView *)view {
174190
if ([_ignoreClasses containsObject:NSStringFromClass(view.class)]) {
175191
return NO;
176192
}
177-
return [_clickableViewTags containsObject:view.reactTag];
193+
BOOL clickable = [_clickableViewTags containsObject:view.reactTag];
194+
if (clickable) {
195+
view.sa_reactnative_screenProperties = self.screenProperties;
196+
}
197+
return clickable;
178198
}
179199

180200
- (BOOL)prepareView:(NSNumber *)reactTag clickable:(BOOL)clickable paramters:(NSDictionary *)paramters {
@@ -198,8 +218,7 @@ - (void)trackViewClick:(NSNumber *)reactTag {
198218
dispatch_async(dispatch_get_main_queue(), ^{
199219
UIView *view = [[SAReactNativeManager sharedInstance] viewForTag:reactTag];
200220
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
201-
NSDictionary *screenProperties = [self screenProperties];
202-
[properties addEntriesFromDictionary:screenProperties];
221+
[properties addEntriesFromDictionary:self.screenProperties];
203222
properties[@"$element_content"] = [view.accessibilityLabel stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
204223

205224
[[SensorsAnalyticsSDK sharedInstance] trackViewAppClick:view withProperties:[properties copy]];
@@ -213,8 +232,11 @@ - (void)trackViewScreen:(nullable NSString *)url properties:(nullable NSDictiona
213232
return;
214233
}
215234
NSString *screenName = properties[@"$screen_name"] ?: url;
216-
NSString *title = properties[@"$title"];
217-
NSDictionary *pageProps = [self viewScreenProperties:screenName title:title];
235+
NSString *title = properties[@"$title"] ?: screenName;
236+
NSMutableDictionary *pageProps = [NSMutableDictionary dictionary];
237+
pageProps[@"$screen_name"] = screenName;
238+
pageProps[@"$title"] = title;
239+
self.screenProperties = pageProps;
218240

219241
if (autoTrack && ![[SensorsAnalyticsSDK sharedInstance] isAutoTrackEnabled]) {
220242
return;
@@ -268,17 +290,4 @@ - (UIView *)viewForTag:(NSNumber *)reactTag {
268290
return [manager viewForReactTag:reactTag];
269291
}
270292

271-
- (NSDictionary *)viewScreenProperties:(NSString *)screenName title:(NSString *)title {
272-
_currentScreenName = screenName;
273-
_currentTitle = title ?: screenName;
274-
return [self screenProperties];
275-
}
276-
277-
- (NSDictionary *)screenProperties {
278-
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
279-
properties[@"$screen_name"] = _currentScreenName;
280-
properties[@"$title"] = _currentTitle;
281-
return [properties copy];
282-
}
283-
284293
@end

package.json

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

0 commit comments

Comments
 (0)