Skip to content

Commit

Permalink
fix: growingUniqueTag logic
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Aug 14, 2023
1 parent 5c92f57 commit c42f248
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)viewDidLoad {
#if defined(AUTOTRACKER)
#if defined(SDK3rd)
[[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"点击事件测试" attributes:@{@"greet": @"hello"}];
self.segmentControl.growingUniqueTag = @"language-selector";
self.sendEventButton.growingUniqueTag = @"UniqueTag-SendButton";
[self.sendEventButton growingTrackImpression:@"hello_track_impression"];
[self.view growingTrackImpression:@"self_view_imp_track" attributes:@{@"self_view_key": @"self_view_value"}];
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ - (void)viewDidLoad {
#if defined(AUTOTRACKER)
#if defined(SDK3rd)
[[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"Button测试"];
self.view.growingUniqueTag = @"我是一个特别的view";
#endif
#endif
self.title = @"Buttons & AlertView";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ - (void)checkWebCirclePathWithView:(UIView *)view
[GrowingNodeHelper
recalculateXpath:view
block:^(NSString *_Nonnull xpath, NSString *_Nonnull xcontent, NSString *_Nonnull originxcontent) {
xpath = [NSString stringWithFormat:@"%@/%@", pagexpath, xpath];
xcontent = [NSString stringWithFormat:@"%@/%@", pagexcontent, xcontent];
originxcontent = [NSString stringWithFormat:@"%@/%@", pagexcontent, originxcontent];
xpath = [NSString stringWithFormat:@"%@%@", pagexpath, xpath];
xcontent = [NSString stringWithFormat:@"%@%@", pagexcontent, xcontent];
originxcontent = [NSString stringWithFormat:@"%@%@", pagexcontent, originxcontent];
XCTAssertEqualObjects(xpathForView, xpath);
XCTAssertEqualObjects(xcontentForView, xcontent);
XCTAssertEqualObjects(originxcontentForView, originxcontent);
Expand Down
8 changes: 4 additions & 4 deletions GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ + (void)recalculateXpath:(UIView *)view

NSString * (^toStringBlock)(NSArray *) = ^(NSArray *array) {
NSArray *reverse = array.reverseObjectEnumerator.allObjects;
return [reverse componentsJoinedByString:@"/"];
return [NSString stringWithFormat:@"/%@", [reverse componentsJoinedByString:@"/"]];
};

NSString *xpath = toStringBlock(viewPathArray);
Expand Down Expand Up @@ -97,9 +97,9 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA
return GrowingViewNode.builder.setView(rootview)
.setIndex(-1)
.setViewContent(rootview.growingNodeContent)
.setXpath(rootview.growingNodeSubPath)
.setXcontent(rootview.growingNodeSubSimilarIndex)
.setOriginXcontent(rootview.growingNodeSubIndex)
.setXpath([NSString stringWithFormat:@"/%@", rootview.growingNodeSubPath])
.setXcontent([NSString stringWithFormat:@"/%@", rootview.growingNodeSubSimilarIndex])
.setOriginXcontent([NSString stringWithFormat:@"/%@", rootview.growingNodeSubIndex])
.setNodeType([self getViewNodeType:rootview])
.build;
}
Expand Down
23 changes: 13 additions & 10 deletions GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ + (void)viewOnChange:(UIView *)view {
GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page];
GrowingViewNode *node = [GrowingNodeHelper getViewNode:view];

NSDictionary *pathInfo = page.pathInfo;
NSString *pagexpath = pathInfo[@"xpath"];
NSString *pagexcontent = pathInfo[@"xcontent"];
GrowingViewElementBuilder *builder =
GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange)
.setPath(@"")
.setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath])
.setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent])
.setIndex(node.index)
.setTextValue(node.viewContent);
GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange)
.setPath(@"")
.setIndex(node.index)
.setTextValue(node.viewContent);
if (node.isBreak) {
builder.setXpath(node.xpath).setXcontent(node.xcontent);

Check warning on line 46 in GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m

View check run for this annotation

Codecov / codecov/patch

GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m#L46

Added line #L46 was not covered by tests
} else {
NSDictionary *pathInfo = page.pathInfo;
NSString *pagexpath = pathInfo[@"xpath"];
NSString *pagexcontent = pathInfo[@"xcontent"];
builder.setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath])
.setXcontent([NSString stringWithFormat:@"%@%@", pagexcontent, node.xcontent]);
}

if (autotrackPage) {
builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes);
Expand Down
23 changes: 13 additions & 10 deletions GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ + (void)viewOnClick:(UIView *)view {
GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page];
GrowingViewNode *node = [GrowingNodeHelper getViewNode:view];

NSDictionary *pathInfo = page.pathInfo;
NSString *pagexpath = pathInfo[@"xpath"];
NSString *pagexcontent = pathInfo[@"xcontent"];
GrowingViewElementBuilder *builder =
GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick)
.setPath(@"")
.setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath])
.setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent])
.setIndex(node.index)
.setTextValue(node.viewContent);
GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick)
.setPath(@"")
.setIndex(node.index)
.setTextValue(node.viewContent);
if (node.isBreak) {
builder.setXpath(node.xpath).setXcontent(node.xcontent);

Check warning on line 46 in GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m

View check run for this annotation

Codecov / codecov/patch

GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m#L46

Added line #L46 was not covered by tests
} else {
NSDictionary *pathInfo = page.pathInfo;
NSString *pagexpath = pathInfo[@"xpath"];
NSString *pagexcontent = pathInfo[@"xcontent"];
builder.setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath])
.setXcontent([NSString stringWithFormat:@"%@%@", pagexcontent, node.xcontent]);
}

if (autotrackPage) {
builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes);
Expand Down
9 changes: 4 additions & 5 deletions GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy, readonly) NSString *_Nullable nodeType;
// 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1
@property (nonatomic, assign, readonly) int index;
// 视图在父节点的排序index,称之为position,例如UIView下的第一个UIButton,postion=0
@property (nonatomic, assign, readonly) int position;
@property (nonatomic, assign, readonly) BOOL hasListParent;
// xpath/xcontent会被uniqueTag截断
@property (nonatomic, assign, readonly) BOOL isBreak;
// 当圈选时,从上至下的路径不一定和正常事件(从下至上)的路径一致,我们需要从新计算xpath
@property (nonatomic, assign, readonly) BOOL needRecalculate;

Expand Down Expand Up @@ -70,9 +70,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy, readonly) NSString *_Nullable nodeType;
// 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1
@property (nonatomic, assign, readonly) int index;
// 视图在父节点的排序index,称之为position,例如UIView下的第一个UIButton,postion=0
@property (nonatomic, assign, readonly) int position;
@property (nonatomic, assign, readonly) BOOL hasListParent;
@property (nonatomic, assign, readonly) BOOL isBreak;
@property (nonatomic, assign, readonly) BOOL needRecalculate;

- (GrowingViewNodeBuilder * (^)(UIView *value))setView;
Expand All @@ -82,10 +81,10 @@ NS_ASSUME_NONNULL_BEGIN
- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXpath;
- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXcontent;
- (GrowingViewNodeBuilder * (^)(int value))setIndex;
- (GrowingViewNodeBuilder * (^)(int value))setPosition;
- (GrowingViewNodeBuilder * (^)(NSString *value))setViewContent;
- (GrowingViewNodeBuilder * (^)(NSString *value))setNodeType;
- (GrowingViewNodeBuilder * (^)(BOOL value))setHasListParent;
- (GrowingViewNodeBuilder * (^)(BOOL value))setIsBreak;
- (GrowingViewNodeBuilder * (^)(BOOL value))setNeedRecalculate;
- (GrowingViewNode *)build;

Expand Down
29 changes: 15 additions & 14 deletions GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ - (instancetype)initWithBuilder:(GrowingViewNodeBuilder *)builder {
_clickableParentXcontent = builder.clickableParentXcontent;
_nodeType = builder.nodeType;
_index = builder.index;
_position = builder.position;
_hasListParent = builder.hasListParent;
_isBreak = builder.isBreak;
_needRecalculate = builder.needRecalculate;
if (_needRecalculate) {
[self recalculate];
Expand Down Expand Up @@ -87,13 +87,14 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate {
}

NSString *uniqueTag = view.growingUniqueTag;
NSString *xpath = uniqueTag && uniqueTag.length > 0
? [NSString stringWithFormat:@"/%@", uniqueTag]
: [self.xpath stringByAppendingFormat:@"/%@", view.growingNodeSubPath];
NSString *xcontent = uniqueTag && uniqueTag.length > 0
BOOL hasUniqueTag = uniqueTag && uniqueTag.length > 0;
BOOL isBreak = self.isBreak || hasUniqueTag;
NSString *xpath = hasUniqueTag ? [NSString stringWithFormat:@"/%@", uniqueTag]
: [self.xpath stringByAppendingFormat:@"/%@", view.growingNodeSubPath];
NSString *xcontent = hasUniqueTag
? [NSString stringWithFormat:@"/%@", view.growingNodeSubSimilarIndex]
: [self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubSimilarIndex];
NSString *originxcontent = uniqueTag && uniqueTag.length > 0
NSString *originxcontent = hasUniqueTag
? [NSString stringWithFormat:@"/%@", view.growingNodeSubIndex]
: [self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubIndex];
NSString *parentXpath = self.view.growingNodeUserInteraction ? self.xpath : self.clickableParentXpath;
Expand All @@ -108,8 +109,8 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate {
.setClickableParentXpath(parentXpath)
.setClickableParentXcontent(parentXcontent)
.setHasListParent(haslistParent)
.setIsBreak(isBreak)
.setViewContent(content ? [content growingHelper_safeSubStringWithLength:50] : nil)
.setPosition((int)view.growingNodeKeyIndex)
.setNodeType([GrowingNodeHelper getViewNodeType:view])
.setNeedRecalculate(recalculate)
.build;
Expand Down Expand Up @@ -168,13 +169,6 @@ @implementation GrowingViewNodeBuilder
};
}

- (GrowingViewNodeBuilder * (^)(int value))setPosition {
return ^(int value) {
self->_position = value;
return self;
};
}

- (GrowingViewNodeBuilder * (^)(NSString *value))setViewContent {
return ^(NSString *value) {
self->_viewContent = value;
Expand All @@ -196,6 +190,13 @@ @implementation GrowingViewNodeBuilder
};
}

- (GrowingViewNodeBuilder * (^)(BOOL value))setIsBreak {
return ^(BOOL value) {
self->_isBreak = value;
return self;
};
}

- (GrowingViewNodeBuilder * (^)(BOOL value))setNeedRecalculate {
return ^(BOOL value) {
self->_needRecalculate = value;
Expand Down
9 changes: 5 additions & 4 deletions Modules/WebCircle/GrowingWebCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node {
.setContent(node.viewContent)
.setZLevel(self.zLevel++)
.setIndex(node.index)
.setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath])
.setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent])
.setXpath(node.isBreak ? node.xpath : [NSString stringWithFormat:@"%@%@", pagexpath, node.xpath])
.setXcontent(node.isBreak ? node.xcontent
: [NSString stringWithFormat:@"%@%@", pagexcontent, node.xcontent])
.setNodeType(node.nodeType)
.setPage(autotrackPage ? autotrackPage.alias : @"");
if (node.clickableParentXpath) {
builder =
builder.setParentXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.clickableParentXpath])
.setParentXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.clickableParentXcontent]);
builder.setParentXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXpath])
.setParentXcontent([NSString stringWithFormat:@"%@%@", pagexcontent, node.clickableParentXcontent]);
}
GrowingWebCircleElement *element = builder.build;

Expand Down

0 comments on commit c42f248

Please sign in to comment.