diff --git a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m index eb8818933..662e908f7 100644 --- a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m +++ b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m @@ -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 diff --git a/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m b/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m index 2c7e8da15..76e6fd635 100644 --- a/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m +++ b/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m @@ -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"; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 420419a99..3489a8b57 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -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); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 5ee504e85..e7a1798e8 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -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); @@ -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; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index 45c32c062..163df9358 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -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); + } 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); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index 9d8f2e1d0..aba80766a 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -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); + } 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); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h index 1151cf498..ed49534a7 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h @@ -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; @@ -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; @@ -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; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m index 73cee8081..5387cb657 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m @@ -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]; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 2f78a3813..ea28438eb 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -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;