Skip to content

Commit

Permalink
Release 4.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jg zhu authored and jg zhu committed Dec 18, 2021
1 parent 8c571be commit 22de274
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 54 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SensorsAnalyticsSDK"
s.version = "4.1.1"
s.version = "4.1.2"
s.summary = "The official iOS SDK of Sensors Analytics."
s.homepage = "http://www.sensorsdata.cn"
s.source = { :git => 'https://github.com/sensorsdata/sa-sdk-ios.git', :tag => "v#{s.version}" }
Expand Down
6 changes: 0 additions & 6 deletions SensorsAnalyticsSDK/AutoTrack/AppClick/UIView+AutoTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
@interface UIImageView (AutoTrack) <SAAutoTrackViewProperty>
@end

@interface UITextField (AutoTrack) <SAAutoTrackViewProperty>
@end

@interface UITextView (AutoTrack) <SAAutoTrackViewProperty>
@end

@interface UISearchBar (AutoTrack) <SAAutoTrackViewProperty>
@end

Expand Down
45 changes: 0 additions & 45 deletions SensorsAnalyticsSDK/AutoTrack/AppClick/UIView+AutoTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,6 @@ - (NSString *)sensorsdata_elementContent {
}
}

if ([[self nextResponder] isKindOfClass:UITextField.class] && ![self isKindOfClass:UIButton.class]) {
/* 兼容输入框的元素采集
UITextField 本身是一个容器,包括 UITextField 的元素内容,文字是直接渲染到 view 的
层级结构如下
UITextField
_UITextFieldRoundedRectBackgroundViewNeue
UIFieldEditor(UIScrollView 的子类,只有编辑状态才包含此层)
_UITextFieldCanvasView 或 _UISearchTextFieldCanvasView (UIView 的子类)
_UITextFieldClearButton (可能存在)
*/
UITextField *textField = (UITextField *)[self nextResponder];
return [textField sensorsdata_elementContent];
}
if ([NSStringFromClass(self.class) isEqualToString:@"_UITextFieldCanvasView"] || [NSStringFromClass(self.class) isEqualToString:@"_UISearchTextFieldCanvasView"]) {

UITextField *textField = (UITextField *)[self nextResponder];
do {
if ([textField isKindOfClass:UITextField.class]) {
return [textField sensorsdata_elementContent];
}
} while ((textField = (UITextField *)[textField nextResponder]));

return nil;
}
NSMutableArray<NSString *> *elementContentArray = [NSMutableArray array];
for (UIView *subview in self.subviews) {
// 忽略隐藏控件
Expand Down Expand Up @@ -186,27 +162,6 @@ - (NSString *)sensorsdata_elementPosition {

@end

@implementation UITextField (AutoTrack)

- (NSString *)sensorsdata_elementContent {
if (self.text) {
return self.text;
} else if (self.placeholder) {
return self.placeholder;
}
return super.sensorsdata_elementContent;
}

@end

@implementation UITextView (AutoTrack)

- (NSString *)sensorsdata_elementContent {
return self.text ?: super.sensorsdata_elementContent;
}

@end

@implementation UISearchBar (AutoTrack)

- (NSString *)sensorsdata_elementContent {
Expand Down
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#import "SAApplication.h"
#import "SAEventTrackerPluginManager.h"

#define VERSION @"4.1.1"
#define VERSION @"4.1.2"

void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ - (NSString *)analysisPropertyWithView:(UIView *)view propertyConfig:(SAVisualPr
// 获取元素内容,主线程执行
__block NSString *content = nil;
dispatch_sync(dispatch_get_main_queue(), ^{
content = view.sensorsdata_elementContent;
content = view.sensorsdata_propertyContent;
});

if (content.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@
@interface UITabBar (SAVisualProperties)
- (void)sensorsdata_visualize_setSelectedItem:(UITabBarItem *)selectedItem;
@end


#pragma mark - 属性内容
@interface UIView (PropertiesContent)

@property (nonatomic, copy, readonly) NSString *sensorsdata_propertyContent;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
#import "UIView+SAVisualProperties.h"
#import "SAVisualizedManager.h"
#import <objc/runtime.h>
#import "SAAutoTrackUtils.h"

static void *const kSAViewNodePropertyName = (void *)&kSAViewNodePropertyName;

#pragma mark -
@implementation UIView (SAVisualProperties)

- (void)sensorsdata_visualize_didMoveToSuperview {
Expand Down Expand Up @@ -164,3 +166,191 @@ - (void)sensorsdata_visualize_setSelectedItem:(UITabBarItem *)selectedItem {
}

@end

#pragma mark -
@implementation UIView (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
if ([self isKindOfClass:NSClassFromString(@"RTLabel")]) { // RTLabel:https://github.com/honcheng/RTLabel
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if ([self respondsToSelector:NSSelectorFromString(@"text")]) {
NSString *title = [self performSelector:NSSelectorFromString(@"text")];
if (title.length > 0) {
return title;
}
}
return nil;
}
if ([self isKindOfClass:NSClassFromString(@"YYLabel")]) { // RTLabel:https://github.com/ibireme/YYKit
if ([self respondsToSelector:NSSelectorFromString(@"text")]) {
NSString *title = [self performSelector:NSSelectorFromString(@"text")];
if (title.length > 0) {
return title;
}
}
return nil;
#pragma clang diagnostic pop
}
if ([SAAutoTrackUtils isKindOfRNView:self]) { // RN 元素,https://reactnative.dev
NSString *content = [self.accessibilityLabel stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (content.length > 0) {
return content;
}
}

if ([self isKindOfClass:NSClassFromString(@"WXView")]) { // WEEX 元素,http://doc.weex.io/zh/docs/components/a.html
NSString *content = [self.accessibilityValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (content.length > 0) {
return content;
}
}

if ([[self nextResponder] isKindOfClass:UITextField.class] && ![self isKindOfClass:UIButton.class]) {
/* 兼容输入框的元素采集
UITextField 本身是一个容器,包括 UITextField 的元素内容,文字是直接渲染到 view 的
层级结构如下
UITextField
_UITextFieldRoundedRectBackgroundViewNeue
UIFieldEditor(UIScrollView 的子类,只有编辑状态才包含此层)
_UITextFieldCanvasView 或 _UISearchTextFieldCanvasView (UIView 的子类)
_UITextFieldClearButton (可能存在)
*/
UITextField *textField = (UITextField *)[self nextResponder];
return [textField sensorsdata_propertyContent];
}
if ([NSStringFromClass(self.class) isEqualToString:@"_UITextFieldCanvasView"] || [NSStringFromClass(self.class) isEqualToString:@"_UISearchTextFieldCanvasView"]) {

UITextField *textField = (UITextField *)[self nextResponder];
do {
if ([textField isKindOfClass:UITextField.class]) {
return [textField sensorsdata_propertyContent];
}
} while ((textField = (UITextField *)[textField nextResponder]));

return nil;
}

NSMutableArray<NSString *> *elementContentArray = [NSMutableArray array];
for (UIView *subview in self.subviews) {
// 忽略隐藏控件
if (subview.isHidden || subview.sensorsAnalyticsIgnoreView) {
continue;
}
NSString *temp = subview.sensorsdata_propertyContent;
if (temp.length > 0) {
[elementContentArray addObject:temp];
}
}
if (elementContentArray.count > 0) {
return [elementContentArray componentsJoinedByString:@"-"];
}

return nil;
}

@end

@implementation UILabel (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return self.text ?: super.sensorsdata_propertyContent;
}

@end

@implementation UIImageView (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
NSString *imageName = self.image.sensorsAnalyticsImageName;
if (imageName.length > 0) {
return [NSString stringWithFormat:@"%@", imageName];
}
return super.sensorsdata_propertyContent;
}

@end


@implementation UITextField (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
if (self.text) {
return self.text;
} else if (self.placeholder) {
return self.placeholder;
}
return super.sensorsdata_propertyContent;
}

@end

@implementation UITextView (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return self.text ?: super.sensorsdata_propertyContent;
}

@end

@implementation UISearchBar (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return self.text ?: super.sensorsdata_propertyContent;
}

@end

#pragma mark - UIControl

@implementation UIButton (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
NSString *text = self.titleLabel.text;
if (!text) {
text = super.sensorsdata_propertyContent;
}
return text;
}

@end

@implementation UISwitch (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return self.on ? @"checked" : @"unchecked";
}

@end

@implementation UIStepper (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return [NSString stringWithFormat:@"%g", self.value];
}

@end

@implementation UISegmentedControl (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return self.selectedSegmentIndex == UISegmentedControlNoSegment ? [super sensorsdata_propertyContent] : [self titleForSegmentAtIndex:self.selectedSegmentIndex];
}

@end

@implementation UIPageControl (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return [NSString stringWithFormat:@"%ld", (long)self.currentPage];
}

@end

@implementation UISlider (PropertiesContent)

- (NSString *)sensorsdata_propertyContent {
return [NSString stringWithFormat:@"%f", self.value];
}

@end

0 comments on commit 22de274

Please sign in to comment.