From 21650785b91e715e77f37273c0dde4850f98183a Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 5 Jun 2023 15:59:54 +0800 Subject: [PATCH 001/126] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20FORM?= =?UTF-8?q?=5FSUBMIT=20=E4=BA=8B=E4=BB=B6=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hybrid/gio_hybrideventtest.html | 24 ------------ .../Helper/ManualTrackHelper.h | 2 - .../Helper/ManualTrackHelper.m | 9 ----- .../HybridTests/HybridTest_HostApp.m | 20 ---------- .../ProtobufTests/ProtobufEventsTest.m | 38 ------------------- GrowingTrackerCore/Event/GrowingEventFilter.m | 10 ++--- .../Public/GrowingEventFilter.h | 20 ++++------ .../Hybrid/Events/GrowingHybridEventType.h | 22 ----------- .../Hybrid/Events/GrowingHybridEventType.m | 22 ----------- Modules/Hybrid/GrowingHybridBridgeProvider.m | 3 -- .../Catagory/GrowingBaseEvent+Protobuf.m | 2 - .../GrowingPBEventV3Dto+GrowingHelper.m | 3 -- Modules/SwiftProtobuf/SwiftProtobuf.swift | 2 - 13 files changed, 11 insertions(+), 166 deletions(-) delete mode 100644 Modules/Hybrid/Events/GrowingHybridEventType.h delete mode 100644 Modules/Hybrid/Events/GrowingHybridEventType.m diff --git a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html index c6568dd98..b6c65b350 100644 --- a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html +++ b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html @@ -299,27 +299,6 @@ sendMockEvent(event); } - function sendMockFormSubmitEvent() { - let event = { - "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", - "sessionId": "d5cbcf77-b38b-4223-954f-c6a2fdc0c098", - "eventType": "FORM_SUBMIT", - "platform": "Web", - "timestamp": 1602485628504, - "domain": "test-browser.growingio.com", - "path": "/push/web.html", - "query": "a=1&b=2", - "title": "Hybrid测试页面", - "referralPage": "http://test-browser.growingio.com/push", - "globalSequenceId": 99, - "eventSequenceId": 3, - "pageShowTimestamp": 1602485626878, - "xpath": "/div/form/input", - "index": 1 - }; - sendMockEvent(event); - } - function sendMockEvent(event) { GrowingWebViewJavascriptBridge.dispatchEvent(JSON.stringify(event)); } @@ -389,9 +368,6 @@

这仅仅是一个测试页面

- diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h index 2296c9ae7..02a0cff20 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h @@ -31,8 +31,6 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event; -+ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event; - + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event; @end diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m index b1d54945e..1d0c5f8af 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m @@ -89,15 +89,6 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event { return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } -+ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event { - if (event.count == 0) { - return NO; - } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"pageShowTimestamp", @"xpath"]]; - NSArray *optional = @[@"index", @"query"]; - return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; -} - /// 验证测量协议中通用非必需字段不为空(需在生成事件前赋值对应字段,如userId、userKey等) /// @param event 事件 + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event { diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m index bd72b20d3..14c856947 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m @@ -24,7 +24,6 @@ #import "GrowingTrackerCore/Event/GrowingTrackEventType.h" #import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" #import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" -#import "Modules/Hybrid/Events/GrowingHybridEventType.h" #import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" #import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" @@ -258,25 +257,6 @@ - (void)test10SendMockViewChangeEvent { XCTAssertEqualObjects(dic[@"textValue"], @"输入内容"); } -- (void)test11SendMockFormSubmitEvent { - KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; - [self webView:actor.view evaluateJavaScript:@"sendMockFormSubmitEvent()"]; - [viewTester waitForTimeInterval:1]; - - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeFormSubmit]; - XCTAssertEqual(events.count, 1); - - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)events.firstObject; - NSDictionary *dic = event.toDictionary; - XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeFormSubmit); - XCTAssertTrue([ManualTrackHelper hybridFormSubmitEventCheck:dic]); - XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - - XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); - XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); - XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); -} - - (void)test12MockSetUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockSetUserId('xctest_userId_hybrid')"]; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m index fe51af351..7bab8a5b6 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m @@ -33,7 +33,6 @@ #import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" -#import "Modules/Hybrid/Events/GrowingHybridEventType.h" @interface ProtobufEventsTest : XCTestCase @@ -489,43 +488,6 @@ - (void)testEventConvertToPB_ViewChange { } } -- (void)testEventConvertToPB_FormSubmit { - // GrowingHybridViewElementEvent - { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeFormSubmit) - .setPath(@"path") - .setPageShowTimestamp(1638857558209) - .setXpath(@"xpath") - .setIndex(1) - .setQuery(@"query") - .build); - GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; - [self contrastOfDefaultParamter:event protobuf:protobuf]; - XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); - XCTAssertEqual(GrowingPBEventType_FormSubmit, protobuf.eventType); - XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); - XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); - XCTAssertEqual(event.index, protobuf.index); - XCTAssertEqualObjects(event.query ?: @"", protobuf.query); - } - { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeFormSubmit) - .build); - GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; - [self contrastOfDefaultParamter:event protobuf:protobuf]; - XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); - XCTAssertEqual(GrowingPBEventType_FormSubmit, protobuf.eventType); - XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); - XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); - XCTAssertEqual(event.index, protobuf.index); - XCTAssertEqualObjects(event.query ?: @"", protobuf.query); - } -} - - (GrowingPBEventV3Dto *)protobufFromEvent:(GrowingBaseEvent *)event { GrowingEventProtobufPersistence *p = [GrowingEventProtobufPersistence persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; diff --git a/GrowingTrackerCore/Event/GrowingEventFilter.m b/GrowingTrackerCore/Event/GrowingEventFilter.m index ad3c0f6ad..703b34790 100644 --- a/GrowingTrackerCore/Event/GrowingEventFilter.m +++ b/GrowingTrackerCore/Event/GrowingEventFilter.m @@ -20,8 +20,8 @@ #import "GrowingTrackerCore/Public/GrowingEventFilter.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -NSUInteger const GrowingFilterClickChangeSubmit = - (GrowingFilterEventViewClick | GrowingFilterEventViewChange | GrowingFilterEventFormSubmit); +NSUInteger const GrowingFilterClickChange = + (GrowingFilterEventViewClick | GrowingFilterEventViewChange); @implementation GrowingEventFilter @@ -32,16 +32,12 @@ + (NSArray *)filterEventItems { _filterEventItems = @[ @"VISIT", @"CUSTOM", - @"VISITOR_ATTRIBUTES", @"LOGIN_USER_ATTRIBUTES", - @"CONVERSION_VARIABLES", @"APP_CLOSED", @"PAGE", - @"PAGE_ATTRIBUTES", @"VIEW_CLICK", @"VIEW_CHANGE", - @"FORM_SUBMIT", - @"REENGAGE" + @"ACTIVATE" ]; }); return _filterEventItems; diff --git a/GrowingTrackerCore/Public/GrowingEventFilter.h b/GrowingTrackerCore/Public/GrowingEventFilter.h index 9e911b989..69f4b5409 100644 --- a/GrowingTrackerCore/Public/GrowingEventFilter.h +++ b/GrowingTrackerCore/Public/GrowingEventFilter.h @@ -19,22 +19,18 @@ #import -// 过滤 VIEW_CLICK、VIEW_CHANGE、FORM_SUBMIT 事件的掩码值 -extern NSUInteger const GrowingFilterClickChangeSubmit; +// 过滤 VIEW_CLICK、VIEW_CHANGE 事件的掩码值 +extern NSUInteger const GrowingFilterClickChange; typedef NS_OPTIONS(NSUInteger, GrowingFilterEvent) { GrowingFilterEventVisit = (1 << 0), GrowingFilterEventCustom = (1 << 1), - GrowingFilterEventVisitorAttributes = (1 << 2), - GrowingFilterEventLoginUserAttributes = (1 << 3), - GrowingFilterEventConversionVariables = (1 << 4), - GrowingFilterEventAppClosed = (1 << 5), - GrowingFilterEventPage = (1 << 6), - GrowingFilterEventPageAttributes = (1 << 7), - GrowingFilterEventViewClick = (1 << 8), - GrowingFilterEventViewChange = (1 << 9), - GrowingFilterEventFormSubmit = (1 << 10), - GrowingFilterEventReengage = (1 << 11), + GrowingFilterEventLoginUserAttributes = (1 << 2), + GrowingFilterEventAppClosed = (1 << 3), + GrowingFilterEventPage = (1 << 4), + GrowingFilterEventViewClick = (1 << 5), + GrowingFilterEventViewChange = (1 << 6), + GrowingFilterEventActivate = (1 << 7), }; @interface GrowingEventFilter : NSObject diff --git a/Modules/Hybrid/Events/GrowingHybridEventType.h b/Modules/Hybrid/Events/GrowingHybridEventType.h deleted file mode 100644 index 058dbc5c0..000000000 --- a/Modules/Hybrid/Events/GrowingHybridEventType.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// GrowingHybridEventType.h -// GrowingAnalytics -// -// Created by sheng on 2020/11/17. -// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "GrowingTrackerCore/Event/GrowingTrackEventType.h" - -FOUNDATION_EXPORT GrowingEventType const GrowingEventTypeFormSubmit; diff --git a/Modules/Hybrid/Events/GrowingHybridEventType.m b/Modules/Hybrid/Events/GrowingHybridEventType.m deleted file mode 100644 index be7d8d367..000000000 --- a/Modules/Hybrid/Events/GrowingHybridEventType.m +++ /dev/null @@ -1,22 +0,0 @@ -// -// GrowingHybridEventType.m -// GrowingAnalytics -// -// Created by sheng on 2020/11/17. -// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "Modules/Hybrid/Events/GrowingHybridEventType.h" - -NSString *const GrowingEventTypeFormSubmit = @"FORM_SUBMIT"; diff --git a/Modules/Hybrid/GrowingHybridBridgeProvider.m b/Modules/Hybrid/GrowingHybridBridgeProvider.m index aaf94e00d..bcaad7e2b 100644 --- a/Modules/Hybrid/GrowingHybridBridgeProvider.m +++ b/Modules/Hybrid/GrowingHybridBridgeProvider.m @@ -32,7 +32,6 @@ #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" #import "GrowingULTimeUtil.h" #import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" -#import "Modules/Hybrid/Events/GrowingHybridEventType.h" #import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" #import "Modules/Hybrid/GrowingWebViewDomChangedDelegate.h" @@ -231,8 +230,6 @@ - (void)parseEventJsonString:(NSString *)jsonString { builder = [self transformViewElementBuilder:dict].setEventType(type); } else if ([type isEqualToString:GrowingEventTypeViewChange]) { builder = [self transformViewElementBuilder:dict].setEventType(type); - } else if ([type isEqualToString:GrowingEventTypeFormSubmit]) { - builder = [self transformViewElementBuilder:dict].setEventType(type); } else if ([type isEqualToString:GrowingEventTypeCustom]) { builder = GrowingHybridCustomEvent.builder.setQuery(dict[@KEY_QUERY]) .setPath(dict[@KEY_PATH]) diff --git a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index a2439d493..272738545 100644 --- a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -132,8 +132,6 @@ - (GrowingPBEventType)pbEventType { return GrowingPBEventType_ViewClick; } else if ([self.eventType isEqualToString:@"VIEW_CHANGE"]) { return GrowingPBEventType_ViewChange; - } else if ([self.eventType isEqualToString:@"FORM_SUBMIT"]) { - return GrowingPBEventType_FormSubmit; } else if ([self.eventType isEqualToString:@"ACTIVATE"]) { return GrowingPBEventType_Activate; } diff --git a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index a1c4a40e2..0d3d1a185 100644 --- a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -69,9 +69,6 @@ - (id)growingHelper_jsonObject { case GrowingPBEventType_ViewChange: { [dic setObject:@"VIEW_CHANGE" forKey:@"eventType"]; } break; - case GrowingPBEventType_FormSubmit: { - [dic setObject:@"FORM_SUBMIT" forKey:@"eventType"]; - } break; case GrowingPBEventType_Activate: { [dic setObject:@"ACTIVATE" forKey:@"eventType"]; } break; diff --git a/Modules/SwiftProtobuf/SwiftProtobuf.swift b/Modules/SwiftProtobuf/SwiftProtobuf.swift index eb7913b0c..dd90a83e1 100644 --- a/Modules/SwiftProtobuf/SwiftProtobuf.swift +++ b/Modules/SwiftProtobuf/SwiftProtobuf.swift @@ -164,8 +164,6 @@ extension GrowingBaseEvent { return .viewClick } else if self.eventType == "VIEW_CHANGE" { return .viewChange - } else if self.eventType == "FORM_SUBMIT" { - return .formSubmit } else if self.eventType == "ACTIVATE" { return .activate } From 28b6925e2b7afd68ac6a4b65d229fd71a541e67a Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 5 Jun 2023 17:51:14 +0800 Subject: [PATCH 002/126] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20pageSh?= =?UTF-8?q?owTimestamp=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hybrid/gio_hybrideventtest.html | 7 ------- .../Helper/ManualTrackHelper.m | 6 +++--- .../HybridTests/HybridEventTest.m | 6 +----- .../ProtobufTests/ProtobufEventsTest.m | 20 ------------------- .../GrowingNode/GrowingViewChangeProvider.m | 1 - .../GrowingNode/GrowingViewClickProvider.m | 1 - .../Event/Autotrack/GrowingPageCustomEvent.h | 3 --- .../Event/Autotrack/GrowingPageCustomEvent.m | 9 --------- .../Event/Autotrack/GrowingViewElementEvent.h | 3 --- .../Event/Autotrack/GrowingViewElementEvent.m | 9 --------- .../Hybrid/Events/GrowingHybridCustomEvent.h | 1 - .../Events/GrowingHybridViewElementEvent.h | 1 - Modules/Hybrid/GrowingHybridBridgeProvider.m | 5 ----- .../Catagory/GrowingBaseEvent+Protobuf.m | 1 - .../GrowingPBEventV3Dto+GrowingHelper.m | 3 --- Modules/SwiftProtobuf/SwiftProtobuf.swift | 11 ---------- 16 files changed, 4 insertions(+), 83 deletions(-) diff --git a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html index b6c65b350..22bc91810 100644 --- a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html +++ b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html @@ -66,7 +66,6 @@ "globalSequenceId": 99, "eventSequenceId": 3, "eventName": "test_name", - "pageShowTimestamp": 1602485626878 }; sendMockEvent(event); } @@ -86,7 +85,6 @@ "globalSequenceId": 99, "eventSequenceId": 3, "eventName": "test_name", - "pageShowTimestamp": 1602485626878, "attributes": { "key1": "value1", "key2": "value2", @@ -112,7 +110,6 @@ "referralPage": "http://test-browser.growingio.com/push", "globalSequenceId": 99, "eventSequenceId": 3, - "pageShowTimestamp": 1602485626878, "attributes": { "key1": "value1", "key2": "value2", @@ -138,7 +135,6 @@ "referralPage": "http://test-browser.growingio.com/push", "globalSequenceId": 99, "eventSequenceId": 3, - "pageShowTimestamp": 1602485626878, "attributes": { "key1": "value1", "key2": "value2", @@ -164,7 +160,6 @@ "referralPage": "http://test-browser.growingio.com/push", "globalSequenceId": 99, "eventSequenceId": 3, - "pageShowTimestamp": 1602485626878, "attributes": { "key1": "value1", "key2": "value2", @@ -268,7 +263,6 @@ "referralPage": "http://test-browser.growingio.com/push", "globalSequenceId": 99, "eventSequenceId": 3, - "pageShowTimestamp": 1602485626878, "textValue": "登录", "xpath": "/div/button#abc", "index": 1, @@ -291,7 +285,6 @@ "referralPage": "http://test-browser.growingio.com/push", "globalSequenceId": 99, "eventSequenceId": 3, - "pageShowTimestamp": 1602485626878, "textValue": "输入内容", "xpath": "/div/form/input", "index": 1 diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m index 1d0c5f8af..c2fb2fe63 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m @@ -26,7 +26,7 @@ + (BOOL)customEventCheck:(NSDictionary *)event { return NO; } NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"eventName"]]; - NSArray *optional = @[@"path", @"pageShowTimestamp", @"attributes", @"query"]; + NSArray *optional = @[@"path", @"attributes", @"query"]; return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } @@ -75,7 +75,7 @@ + (BOOL)viewClickEventCheck:(NSDictionary *)event { if (event.count == 0) { return NO; } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"pageShowTimestamp", @"xpath"]]; + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"xpath"]]; NSArray *optional = @[@"textValue", @"index", @"hyperlink", @"query"]; return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } @@ -84,7 +84,7 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event { if (event.count == 0) { return NO; } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"pageShowTimestamp", @"xpath"]]; + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"xpath"]]; NSArray *optional = @[@"textValue", @"index", @"hyperlink", @"query"]; return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } diff --git a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m index 652f6d947..b6699dc74 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m @@ -42,13 +42,11 @@ - (void)testGrowingHybridCustomEvent { GrowingHybridCustomEvent *event = (GrowingHybridCustomEvent *)GrowingHybridCustomEvent.builder.setPath(@"/hybrid/test") .setQuery(@"testquery") .setEventName(@"testEventName") - .setPageShowTimestamp(123456677) .setAttributes(@{@"test":@"value"}).build; XCTAssertEqual(event.path, @"/hybrid/test"); XCTAssertEqual(event.query, @"testquery"); XCTAssertEqual(event.eventName, @"testEventName"); - XCTAssertTrue(event.pageShowTimestamp == 123456677); NSString *value = (NSString *)event.attributes[@"test"]; XCTAssertTrue([value isEqualToString:@"value"]); } @@ -68,14 +66,12 @@ - (void)testGrowingPageCustomEvent { GrowingPageCustomEvent *event = (GrowingPageCustomEvent *)GrowingPageCustomEvent.builder .setPath(@"path") .setEventName(@"testEventName") - .setAttributes(@{@"test":@"value"}) - .setPageShowTimestamp(123456677).build; + .setAttributes(@{@"test":@"value"}).build; XCTAssertEqualObjects(event.path, @"path"); XCTAssertEqualObjects(event.eventName, @"testEventName"); NSString *value = (NSString *)event.attributes[@"test"]; XCTAssertTrue([value isEqualToString:@"value"]); - XCTAssertTrue(event.pageShowTimestamp == 123456677); } - (void)testGrowingHybridViewElementEvent { diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m index 7bab8a5b6..62ae73067 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m @@ -80,7 +80,6 @@ - (void)testEventConvertToPB_Visit { GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder .setEventType(GrowingEventTypeVisit) .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setXpath(@"xpath") .setIndex(1) .setQuery(@"query") @@ -90,7 +89,6 @@ - (void)testEventConvertToPB_Visit { XCTAssertEqualObjects(GrowingEventTypeVisit, event.eventType); XCTAssertEqual(GrowingPBEventType_Visit, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); XCTAssertEqualObjects(event.query ?: @"", protobuf.query); @@ -126,7 +124,6 @@ - (void)testEventConvertToPB_Custom { GrowingPageCustomEvent *event = (GrowingPageCustomEvent *)(GrowingPageCustomEvent.builder .setEventName(@"custom") .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setAttributes(@{@"key": @"value"}) .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; @@ -135,7 +132,6 @@ - (void)testEventConvertToPB_Custom { XCTAssertEqual(GrowingPBEventType_Custom, protobuf.eventType); XCTAssertEqualObjects(event.eventName ?: @"", protobuf.eventName); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); } { @@ -146,7 +142,6 @@ - (void)testEventConvertToPB_Custom { XCTAssertEqual(GrowingPBEventType_Custom, protobuf.eventType); XCTAssertEqualObjects(event.eventName ?: @"", protobuf.eventName); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); } @@ -155,7 +150,6 @@ - (void)testEventConvertToPB_Custom { GrowingHybridCustomEvent *event = (GrowingHybridCustomEvent *)(GrowingHybridCustomEvent.builder .setEventName(@"custom") .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setAttributes(@{@"key": @"value"}) .setQuery(@"query") .build); @@ -165,7 +159,6 @@ - (void)testEventConvertToPB_Custom { XCTAssertEqual(GrowingPBEventType_Custom, protobuf.eventType); XCTAssertEqualObjects(event.eventName ?: @"", protobuf.eventName); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); XCTAssertEqualObjects(event.query ?: @"", protobuf.query); } @@ -177,7 +170,6 @@ - (void)testEventConvertToPB_Custom { XCTAssertEqual(GrowingPBEventType_Custom, protobuf.eventType); XCTAssertEqualObjects(event.eventName ?: @"", protobuf.eventName); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); XCTAssertEqualObjects(event.query ?: @"", protobuf.query); } @@ -338,7 +330,6 @@ - (void)testEventConvertToPB_ViewClick { GrowingViewElementEvent *event = (GrowingViewElementEvent *)(GrowingViewElementEvent.builder .setEventType(GrowingEventTypeViewClick) .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setTextValue(@"textvalue") .setXpath(@"xpath") .setIndex(1) @@ -348,7 +339,6 @@ - (void)testEventConvertToPB_ViewClick { XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewClick, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); @@ -362,7 +352,6 @@ - (void)testEventConvertToPB_ViewClick { XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewClick, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); @@ -373,7 +362,6 @@ - (void)testEventConvertToPB_ViewClick { GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder .setEventType(GrowingEventTypeViewClick) .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setTextValue(@"textvalue") .setXpath(@"xpath") .setIndex(1) @@ -385,7 +373,6 @@ - (void)testEventConvertToPB_ViewClick { XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewClick, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); @@ -401,7 +388,6 @@ - (void)testEventConvertToPB_ViewClick { XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewClick, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); @@ -416,7 +402,6 @@ - (void)testEventConvertToPB_ViewChange { GrowingViewElementEvent *event = (GrowingViewElementEvent *)(GrowingViewElementEvent.builder .setEventType(GrowingEventTypeViewChange) .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setTextValue(@"textvalue") .setXpath(@"xpath") .setIndex(1) @@ -426,7 +411,6 @@ - (void)testEventConvertToPB_ViewChange { XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewChange, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); @@ -440,7 +424,6 @@ - (void)testEventConvertToPB_ViewChange { XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewChange, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); @@ -451,7 +434,6 @@ - (void)testEventConvertToPB_ViewChange { GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder .setEventType(GrowingEventTypeViewChange) .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setTextValue(@"textvalue") .setXpath(@"xpath") .setIndex(1) @@ -463,7 +445,6 @@ - (void)testEventConvertToPB_ViewChange { XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewChange, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); @@ -479,7 +460,6 @@ - (void)testEventConvertToPB_ViewChange { XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); XCTAssertEqual(GrowingPBEventType_ViewChange, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.textValue ?: @"", protobuf.textValue); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index e07ad82da..d7858432a 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -46,7 +46,6 @@ + (void)sendChangeEvent:(GrowingPageGroup *)page viewNode:(GrowingViewNode *)nod [[GrowingEventManager sharedInstance] postEventBuilder:GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange) .setPath(page.path) - .setPageShowTimestamp(page.showTimestamp) .setXpath(node.xPath) .setIndex(node.index) .setTextValue(node.viewContent)]; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index 6afdbb0dd..c33db43b5 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -46,7 +46,6 @@ + (void)sendClickEvent:(GrowingPageGroup *)page viewNode:(GrowingViewNode *)node [[GrowingEventManager sharedInstance] postEventBuilder:GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick) .setPath(page.path) - .setPageShowTimestamp(page.showTimestamp) .setXpath(node.xPath) .setIndex(node.index) .setTextValue(node.viewContent)]; diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h index 1eecebf8a..0369e8729 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h @@ -26,7 +26,6 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingPageCustomEvent : GrowingCustomEvent @property (nonatomic, copy, readonly) NSString *path; -@property (nonatomic, assign, readonly) long long pageShowTimestamp; + (GrowingPageCustomBuilder *)builder; @@ -35,10 +34,8 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingPageCustomBuilder : GrowingCustomBuilder @property (nonatomic, copy, readonly) NSString *pageName; -@property (nonatomic, assign, readonly) long long pageShowTimestamp; - (GrowingPageCustomBuilder * (^)(NSString *value))setPath; -- (GrowingPageCustomBuilder * (^)(long long value))setPageShowTimestamp; // override - (GrowingPageCustomBuilder * (^)(NSString *value))setEventName; diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m index eae7720f1..ad78b7992 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m +++ b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m @@ -29,7 +29,6 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { if (self = [super initWithBuilder:builder]) { GrowingPageCustomBuilder *subBuilder = (GrowingPageCustomBuilder *)builder; _path = subBuilder.pageName; - _pageShowTimestamp = subBuilder.pageShowTimestamp; } return self; } @@ -37,7 +36,6 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { - (NSDictionary *)toDictionary { NSMutableDictionary *dataDictM = [NSMutableDictionary dictionaryWithDictionary:[super toDictionary]]; dataDictM[@"path"] = self.path; - dataDictM[@"pageShowTimestamp"] = @(self.pageShowTimestamp); return dataDictM; } @@ -54,13 +52,6 @@ @implementation GrowingPageCustomBuilder }; } -- (GrowingPageCustomBuilder * (^)(long long value))setPageShowTimestamp { - return ^(long long value) { - self->_pageShowTimestamp = value; - return self; - }; -} - - (GrowingBaseEvent *)build { return [[GrowingPageCustomEvent alloc] initWithBuilder:self]; } diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h index 787d7ffe2..5622dbf61 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h @@ -29,7 +29,6 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingViewElementEvent : GrowingBaseEvent @property (nonatomic, copy, readonly) NSString *path; -@property (nonatomic, assign, readonly) long long pageShowTimestamp; @property (nonatomic, copy, readonly) NSString *textValue; @property (nonatomic, copy, readonly) NSString *xpath; @property (nonatomic, assign, readonly) int index; @@ -41,13 +40,11 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingViewElementBuilder : GrowingBaseBuilder @property (nonatomic, copy, readonly) NSString *pageName; -@property (nonatomic, assign, readonly) long long pageShowTimestamp; @property (nonatomic, copy, readonly) NSString *textValue; @property (nonatomic, copy, readonly) NSString *xpath; @property (nonatomic, assign, readonly) int index; - (GrowingViewElementBuilder * (^)(NSString *value))setPath; -- (GrowingViewElementBuilder * (^)(long long value))setPageShowTimestamp; - (GrowingViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingViewElementBuilder * (^)(NSString *value))setXpath; - (GrowingViewElementBuilder * (^)(int value))setIndex; diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m index 80741b869..31f2cefb6 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m @@ -29,7 +29,6 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { if (self = [super initWithBuilder:builder]) { GrowingViewElementBuilder *subBuilder = (GrowingViewElementBuilder *)builder; _path = subBuilder.pageName; - _pageShowTimestamp = subBuilder.pageShowTimestamp; _textValue = subBuilder.textValue; _xpath = subBuilder.xpath; _index = subBuilder.index; @@ -40,7 +39,6 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { - (NSDictionary *)toDictionary { NSMutableDictionary *dataDictM = [NSMutableDictionary dictionaryWithDictionary:[super toDictionary]]; dataDictM[@"path"] = self.path; - dataDictM[@"pageShowTimestamp"] = @(self.pageShowTimestamp); dataDictM[@"textValue"] = self.textValue; dataDictM[@"xpath"] = self.xpath; dataDictM[@"index"] = self.index >= 0 ? @(self.index) : nil; @@ -60,13 +58,6 @@ @implementation GrowingViewElementBuilder }; } -- (GrowingViewElementBuilder * (^)(long long value))setPageShowTimestamp { - return ^(long long value) { - self->_pageShowTimestamp = value; - return self; - }; -} - - (GrowingViewElementBuilder * (^)(NSString *value))setTextValue { return ^(NSString *value) { self->_textValue = value; diff --git a/Modules/Hybrid/Events/GrowingHybridCustomEvent.h b/Modules/Hybrid/Events/GrowingHybridCustomEvent.h index 7ccadc4a5..2abe1bc4c 100644 --- a/Modules/Hybrid/Events/GrowingHybridCustomEvent.h +++ b/Modules/Hybrid/Events/GrowingHybridCustomEvent.h @@ -37,7 +37,6 @@ NS_ASSUME_NONNULL_BEGIN // override - (GrowingHybridCustomBuilder * (^)(NSString *value))setPath; -- (GrowingHybridCustomBuilder * (^)(long long value))setPageShowTimestamp; - (GrowingHybridCustomBuilder * (^)(NSString *value))setEventName; - (GrowingHybridCustomBuilder * (^)(NSDictionary *value))setAttributes; diff --git a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h index 934fbfed2..9b37d81a8 100644 --- a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h +++ b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h @@ -42,7 +42,6 @@ NS_ASSUME_NONNULL_BEGIN // 重写 - (GrowingHybridViewElementBuilder * (^)(NSString *value))setPath; -- (GrowingHybridViewElementBuilder * (^)(long long value))setPageShowTimestamp; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setXpath; - (GrowingHybridViewElementBuilder * (^)(int value))setIndex; diff --git a/Modules/Hybrid/GrowingHybridBridgeProvider.m b/Modules/Hybrid/GrowingHybridBridgeProvider.m index bcaad7e2b..12d233b3e 100644 --- a/Modules/Hybrid/GrowingHybridBridgeProvider.m +++ b/Modules/Hybrid/GrowingHybridBridgeProvider.m @@ -53,7 +53,6 @@ #define KEY_REFERRAL_PAGE "referralPage" #define KEY_TITLE "title" #define KEY_TIMESTAMP "timestamp" -#define KEY_PAGE_SHOW_TIMESTAMP "pageShowTimestamp" #define KEY_ATTRIBUTES "attributes" #define KEY_VARIABLES "variables" #define KEY_EVENT_NAME "eventName" @@ -233,8 +232,6 @@ - (void)parseEventJsonString:(NSString *)jsonString { } else if ([type isEqualToString:GrowingEventTypeCustom]) { builder = GrowingHybridCustomEvent.builder.setQuery(dict[@KEY_QUERY]) .setPath(dict[@KEY_PATH]) - .setPageShowTimestamp([dict growingHelper_longlongForKey:@KEY_PAGE_SHOW_TIMESTAMP - fallback:[GrowingULTimeUtil currentTimeMillis]]) .setAttributes([self safeAttributesFromDict:dict]) .setEventName(dict[@KEY_EVENT_NAME]) .setDomain([self getDomain:dict]); @@ -255,8 +252,6 @@ - (GrowingBaseBuilder *)transformViewElementBuilder:(NSDictionary *)dict { .setTextValue(dict[@KEY_TEXT_VALUE]) .setXpath(dict[@KEY_XPATH]) .setPath(dict[@KEY_PATH]) - .setPageShowTimestamp([dict growingHelper_longlongForKey:@KEY_PAGE_SHOW_TIMESTAMP - fallback:[GrowingULTimeUtil currentTimeMillis]]) .setDomain([self getDomain:dict]); } diff --git a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index 272738545..316b4c18d 100644 --- a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -97,7 +97,6 @@ - (GrowingPBEventV3Dto *)toProtobuf { dto.idfv = stringBlock(@"idfv"); dto.extraSdk = dicBlock(@"extraSdk").mutableCopy; dto.path = stringBlock(@"pageName").length > 0 ? stringBlock(@"pageName") : stringBlock(@"path"); - dto.pageShowTimestamp = int64Block(@"pageShowTimestamp"); dto.textValue = stringBlock(@"textValue"); dto.xpath = stringBlock(@"xpath"); dto.index = int32Block(@"index"); diff --git a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index 0d3d1a185..af13f90c2 100644 --- a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -120,9 +120,6 @@ - (id)growingHelper_jsonObject { if (self.eventName.length > 0) { [dic setObject:self.eventName forKey:@"eventName"]; } - if (self.pageShowTimestamp > 0) { - [dic setObject:@(self.pageShowTimestamp) forKey:@"pageShowTimestamp"]; - } if (self.attributes_Count > 0) { [dic setObject:self.attributes forKey:@"attributes"]; } diff --git a/Modules/SwiftProtobuf/SwiftProtobuf.swift b/Modules/SwiftProtobuf/SwiftProtobuf.swift index dd90a83e1..aaf5f8857 100644 --- a/Modules/SwiftProtobuf/SwiftProtobuf.swift +++ b/Modules/SwiftProtobuf/SwiftProtobuf.swift @@ -127,7 +127,6 @@ extension GrowingBaseEvent { dto.idfv = idfv() dto.extraSdk = extraSdk() dto.path = path() - dto.pageShowTimestamp = pageShowTimestamp() dto.textValue = textValue() dto.xpath = xpath() dto.index = index() @@ -211,16 +210,6 @@ extension GrowingBaseEvent { return "" } - fileprivate func pageShowTimestamp() -> Int64 { - let selector = Selector(("pageShowTimestamp")) - if self.responds(to: selector) { - let imp: IMP = method_getImplementation(class_getInstanceMethod(type(of: self), selector)!) - let result = unsafeBitCast(imp, to: (@convention(c)(GrowingBaseEvent, Selector) -> Int64).self)(self, selector) - return result > 0 ? result : 0 - } - return 0 - } - fileprivate func textValue() -> String { let selector = Selector(("textValue")) if self.responds(to: selector) { From 69c7e2ce35db6e0db849e15b5191a628ff96287a Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 5 Jun 2023 19:30:27 +0800 Subject: [PATCH 003/126] =?UTF-8?q?feat:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=B1=9E=E6=80=A7=E6=B7=BB=E5=8A=A0=20page?= =?UTF-8?q?=20attributes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GrowingNode/GrowingViewChangeProvider.m | 19 +++++++++++++------ .../GrowingNode/GrowingViewClickProvider.m | 19 +++++++++++++------ .../Event/Autotrack/GrowingViewElementEvent.h | 7 ++++--- .../Events/GrowingHybridViewElementEvent.h | 2 ++ Modules/Hybrid/GrowingHybridBridgeProvider.m | 3 ++- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index d7858432a..6908e8793 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -22,6 +22,7 @@ #import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" +#import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" @@ -43,12 +44,18 @@ + (void)viewOnChange:(UIView *)view { } + (void)sendChangeEvent:(GrowingPageGroup *)page viewNode:(GrowingViewNode *)node { - [[GrowingEventManager sharedInstance] - postEventBuilder:GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange) - .setPath(page.path) - .setXpath(node.xPath) - .setIndex(node.index) - .setTextValue(node.viewContent)]; + GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder + .setEventType(GrowingEventTypeViewChange) + .setPath(page.path) + .setXpath(node.xPath) + .setIndex(node.index) + .setTextValue(node.viewContent); + + if (!page.isIgnored) { + builder.setAttributes([page.carrier growingPageAttributes]); + } + + [[GrowingEventManager sharedInstance] postEventBuilder:builder]; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index c33db43b5..a9b248d49 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -22,6 +22,7 @@ #import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" +#import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" @@ -43,12 +44,18 @@ + (void)viewOnClick:(UIView *)view { } + (void)sendClickEvent:(GrowingPageGroup *)page viewNode:(GrowingViewNode *)node { - [[GrowingEventManager sharedInstance] - postEventBuilder:GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick) - .setPath(page.path) - .setXpath(node.xPath) - .setIndex(node.index) - .setTextValue(node.viewContent)]; + GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder + .setEventType(GrowingEventTypeViewClick) + .setPath(page.path) + .setXpath(node.xPath) + .setIndex(node.index) + .setTextValue(node.viewContent); + + if (!page.isIgnored) { + builder.setAttributes([page.carrier growingPageAttributes]); + } + + [[GrowingEventManager sharedInstance] postEventBuilder:builder]; } @end diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h index 5622dbf61..f678bc333 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h @@ -17,7 +17,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "GrowingBaseEvent.h" +#import "GrowingTrackerCore/Event/GrowingBaseAttributesEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" // 泛型类型,可以生成多个类型event,故可以设置eventType @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN @class GrowingViewElementBuilder; -@interface GrowingViewElementEvent : GrowingBaseEvent +@interface GrowingViewElementEvent : GrowingBaseAttributesEvent @property (nonatomic, copy, readonly) NSString *path; @property (nonatomic, copy, readonly) NSString *textValue; @@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN @end -@interface GrowingViewElementBuilder : GrowingBaseBuilder +@interface GrowingViewElementBuilder : GrowingBaseAttributesBuilder @property (nonatomic, copy, readonly) NSString *pageName; @property (nonatomic, copy, readonly) NSString *textValue; @@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingViewElementBuilder * (^)(NSString *value))setXpath; - (GrowingViewElementBuilder * (^)(int value))setIndex; +- (GrowingViewElementBuilder *(^)(NSDictionary *value))setAttributes; // extra add // 覆盖返回值类型为GrowingViewElementBuilder diff --git a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h index 9b37d81a8..d6dd0b910 100644 --- a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h +++ b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h @@ -45,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingHybridViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setXpath; - (GrowingHybridViewElementBuilder * (^)(int value))setIndex; +- (GrowingHybridViewElementBuilder *(^)(NSString *value))setDomain; +- (GrowingHybridViewElementBuilder *(^)(NSDictionary *value))setAttributes; // extra add - (GrowingHybridViewElementBuilder * (^)(NSString *value))setEventType; diff --git a/Modules/Hybrid/GrowingHybridBridgeProvider.m b/Modules/Hybrid/GrowingHybridBridgeProvider.m index 12d233b3e..e7507bff6 100644 --- a/Modules/Hybrid/GrowingHybridBridgeProvider.m +++ b/Modules/Hybrid/GrowingHybridBridgeProvider.m @@ -252,7 +252,8 @@ - (GrowingBaseBuilder *)transformViewElementBuilder:(NSDictionary *)dict { .setTextValue(dict[@KEY_TEXT_VALUE]) .setXpath(dict[@KEY_XPATH]) .setPath(dict[@KEY_PATH]) - .setDomain([self getDomain:dict]); + .setDomain([self getDomain:dict]) + .setAttributes([self safeAttributesFromDict:dict]);; } @end From bcb75ce73487451688c3337e4632e6347441b9a3 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 6 Jun 2023 10:31:46 +0800 Subject: [PATCH 004/126] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20hybrid?= =?UTF-8?q?=20=E8=BD=AC=E5=8F=91=E4=BA=8B=E4=BB=B6=E4=B8=AD=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=20event=5Ftype=20=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/Hybrid/GrowingHybridBridgeProvider.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Modules/Hybrid/GrowingHybridBridgeProvider.m b/Modules/Hybrid/GrowingHybridBridgeProvider.m index e7507bff6..c0004bc7d 100644 --- a/Modules/Hybrid/GrowingHybridBridgeProvider.m +++ b/Modules/Hybrid/GrowingHybridBridgeProvider.m @@ -223,8 +223,6 @@ - (void)parseEventJsonString:(NSString *)jsonString { fallback:[GrowingULTimeUtil currentTimeMillis]]) .setAttributes([self safeAttributesFromDict:dict]) .setDomain([self getDomain:dict]); - } else if ([type isEqualToString:GrowingEventTypeVisit]) { - builder = [self transformViewElementBuilder:dict].setEventType(type); } else if ([type isEqualToString:GrowingEventTypeViewClick]) { builder = [self transformViewElementBuilder:dict].setEventType(type); } else if ([type isEqualToString:GrowingEventTypeViewChange]) { @@ -237,8 +235,6 @@ - (void)parseEventJsonString:(NSString *)jsonString { .setDomain([self getDomain:dict]); } else if ([type isEqualToString:GrowingEventTypeLoginUserAttributes]) { builder = GrowingLoginUserAttributesEvent.builder.setAttributes([self safeAttributesFromDict:dict]); - } else if ([type isEqualToString:GrowingEventTypeConversionVariables]) { - builder = GrowingConversionVariableEvent.builder.setAttributes([self safeAttributesFromDict:dict]); } if (builder) { [[GrowingEventManager sharedInstance] postEventBuilder:builder]; From d982595a525117c829fb59cb18271cbf8d88962f Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 9 Jun 2023 10:03:38 +0800 Subject: [PATCH 005/126] =?UTF-8?q?revert:=20=E7=A7=BB=E9=99=A4=20FORM=5FS?= =?UTF-8?q?UBMIT=20=E4=BA=8B=E4=BB=B6=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hybrid/gio_hybrideventtest.html | 24 ++++++++++++ .../Helper/ManualTrackHelper.h | 2 + .../Helper/ManualTrackHelper.m | 9 +++++ .../HybridTests/HybridTest_HostApp.m | 20 ++++++++++ .../ProtobufTests/ProtobufEventsTest.m | 38 +++++++++++++++++++ GrowingTrackerCore/Event/GrowingEventFilter.m | 1 + .../Public/GrowingEventFilter.h | 3 +- .../Hybrid/Events/GrowingHybridEventType.h | 22 +++++++++++ .../Hybrid/Events/GrowingHybridEventType.m | 22 +++++++++++ Modules/Hybrid/GrowingHybridBridgeProvider.m | 3 ++ .../Catagory/GrowingBaseEvent+Protobuf.m | 2 + .../GrowingPBEventV3Dto+GrowingHelper.m | 3 ++ Modules/SwiftProtobuf/SwiftProtobuf.swift | 2 + 13 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 Modules/Hybrid/Events/GrowingHybridEventType.h create mode 100644 Modules/Hybrid/Events/GrowingHybridEventType.m diff --git a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html index 22bc91810..882a6a9d0 100644 --- a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html +++ b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html @@ -292,6 +292,27 @@ sendMockEvent(event); } + function sendMockFormSubmitEvent() { + let event = { + "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", + "sessionId": "d5cbcf77-b38b-4223-954f-c6a2fdc0c098", + "eventType": "FORM_SUBMIT", + "platform": "Web", + "timestamp": 1602485628504, + "domain": "test-browser.growingio.com", + "path": "/push/web.html", + "query": "a=1&b=2", + "title": "Hybrid测试页面", + "referralPage": "http://test-browser.growingio.com/push", + "globalSequenceId": 99, + "eventSequenceId": 3, + "pageShowTimestamp": 1602485626878, + "xpath": "/div/form/input", + "index": 1 + }; + sendMockEvent(event); + } + function sendMockEvent(event) { GrowingWebViewJavascriptBridge.dispatchEvent(JSON.stringify(event)); } @@ -361,6 +382,9 @@

这仅仅是一个测试页面

+ diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h index 02a0cff20..2296c9ae7 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h @@ -31,6 +31,8 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event; ++ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event; + + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event; @end diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m index c2fb2fe63..c4e9008d9 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m @@ -89,6 +89,15 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event { return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } ++ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event { + if (event.count == 0) { + return NO; + } + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"pageShowTimestamp", @"xpath"]]; + NSArray *optional = @[@"index", @"query"]; + return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; +} + /// 验证测量协议中通用非必需字段不为空(需在生成事件前赋值对应字段,如userId、userKey等) /// @param event 事件 + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event { diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m index 14c856947..bd72b20d3 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m @@ -24,6 +24,7 @@ #import "GrowingTrackerCore/Event/GrowingTrackEventType.h" #import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" #import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" +#import "Modules/Hybrid/Events/GrowingHybridEventType.h" #import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" #import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" @@ -257,6 +258,25 @@ - (void)test10SendMockViewChangeEvent { XCTAssertEqualObjects(dic[@"textValue"], @"输入内容"); } +- (void)test11SendMockFormSubmitEvent { + KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; + [self webView:actor.view evaluateJavaScript:@"sendMockFormSubmitEvent()"]; + [viewTester waitForTimeInterval:1]; + + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeFormSubmit]; + XCTAssertEqual(events.count, 1); + + GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)events.firstObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeFormSubmit); + XCTAssertTrue([ManualTrackHelper hybridFormSubmitEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); + XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); + XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); +} + - (void)test12MockSetUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockSetUserId('xctest_userId_hybrid')"]; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m index 62ae73067..eb62f972a 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m @@ -33,6 +33,7 @@ #import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" +#import "Modules/Hybrid/Events/GrowingHybridEventType.h" @interface ProtobufEventsTest : XCTestCase @@ -468,6 +469,43 @@ - (void)testEventConvertToPB_ViewChange { } } +- (void)testEventConvertToPB_FormSubmit { + // GrowingHybridViewElementEvent + { + GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder + .setEventType(GrowingEventTypeFormSubmit) + .setPath(@"path") + .setPageShowTimestamp(1638857558209) + .setXpath(@"xpath") + .setIndex(1) + .setQuery(@"query") + .build); + GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; + [self contrastOfDefaultParamter:event protobuf:protobuf]; + XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); + XCTAssertEqual(GrowingPBEventType_FormSubmit, protobuf.eventType); + XCTAssertEqualObjects(event.path ?: @"", protobuf.path); + XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); + XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); + XCTAssertEqual(event.index, protobuf.index); + XCTAssertEqualObjects(event.query ?: @"", protobuf.query); + } + { + GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder + .setEventType(GrowingEventTypeFormSubmit) + .build); + GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; + [self contrastOfDefaultParamter:event protobuf:protobuf]; + XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); + XCTAssertEqual(GrowingPBEventType_FormSubmit, protobuf.eventType); + XCTAssertEqualObjects(event.path ?: @"", protobuf.path); + XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); + XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); + XCTAssertEqual(event.index, protobuf.index); + XCTAssertEqualObjects(event.query ?: @"", protobuf.query); + } +} + - (GrowingPBEventV3Dto *)protobufFromEvent:(GrowingBaseEvent *)event { GrowingEventProtobufPersistence *p = [GrowingEventProtobufPersistence persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; diff --git a/GrowingTrackerCore/Event/GrowingEventFilter.m b/GrowingTrackerCore/Event/GrowingEventFilter.m index 703b34790..97629d8fb 100644 --- a/GrowingTrackerCore/Event/GrowingEventFilter.m +++ b/GrowingTrackerCore/Event/GrowingEventFilter.m @@ -37,6 +37,7 @@ + (NSArray *)filterEventItems { @"PAGE", @"VIEW_CLICK", @"VIEW_CHANGE", + @"FORM_SUBMIT", @"ACTIVATE" ]; }); diff --git a/GrowingTrackerCore/Public/GrowingEventFilter.h b/GrowingTrackerCore/Public/GrowingEventFilter.h index 69f4b5409..da7ed52bd 100644 --- a/GrowingTrackerCore/Public/GrowingEventFilter.h +++ b/GrowingTrackerCore/Public/GrowingEventFilter.h @@ -30,7 +30,8 @@ typedef NS_OPTIONS(NSUInteger, GrowingFilterEvent) { GrowingFilterEventPage = (1 << 4), GrowingFilterEventViewClick = (1 << 5), GrowingFilterEventViewChange = (1 << 6), - GrowingFilterEventActivate = (1 << 7), + GrowingFilterEventFormSubmit = (1 << 7), + GrowingFilterEventActivate = (1 << 8) }; @interface GrowingEventFilter : NSObject diff --git a/Modules/Hybrid/Events/GrowingHybridEventType.h b/Modules/Hybrid/Events/GrowingHybridEventType.h new file mode 100644 index 000000000..058dbc5c0 --- /dev/null +++ b/Modules/Hybrid/Events/GrowingHybridEventType.h @@ -0,0 +1,22 @@ +// +// GrowingHybridEventType.h +// GrowingAnalytics +// +// Created by sheng on 2020/11/17. +// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingTrackerCore/Event/GrowingTrackEventType.h" + +FOUNDATION_EXPORT GrowingEventType const GrowingEventTypeFormSubmit; diff --git a/Modules/Hybrid/Events/GrowingHybridEventType.m b/Modules/Hybrid/Events/GrowingHybridEventType.m new file mode 100644 index 000000000..be7d8d367 --- /dev/null +++ b/Modules/Hybrid/Events/GrowingHybridEventType.m @@ -0,0 +1,22 @@ +// +// GrowingHybridEventType.m +// GrowingAnalytics +// +// Created by sheng on 2020/11/17. +// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "Modules/Hybrid/Events/GrowingHybridEventType.h" + +NSString *const GrowingEventTypeFormSubmit = @"FORM_SUBMIT"; diff --git a/Modules/Hybrid/GrowingHybridBridgeProvider.m b/Modules/Hybrid/GrowingHybridBridgeProvider.m index c0004bc7d..11ef3982c 100644 --- a/Modules/Hybrid/GrowingHybridBridgeProvider.m +++ b/Modules/Hybrid/GrowingHybridBridgeProvider.m @@ -32,6 +32,7 @@ #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" #import "GrowingULTimeUtil.h" #import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" +#import "Modules/Hybrid/Events/GrowingHybridEventType.h" #import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" #import "Modules/Hybrid/GrowingWebViewDomChangedDelegate.h" @@ -227,6 +228,8 @@ - (void)parseEventJsonString:(NSString *)jsonString { builder = [self transformViewElementBuilder:dict].setEventType(type); } else if ([type isEqualToString:GrowingEventTypeViewChange]) { builder = [self transformViewElementBuilder:dict].setEventType(type); + } else if ([type isEqualToString:GrowingEventTypeFormSubmit]) { + builder = [self transformViewElementBuilder:dict].setEventType(type); } else if ([type isEqualToString:GrowingEventTypeCustom]) { builder = GrowingHybridCustomEvent.builder.setQuery(dict[@KEY_QUERY]) .setPath(dict[@KEY_PATH]) diff --git a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index 316b4c18d..4658d3198 100644 --- a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -131,6 +131,8 @@ - (GrowingPBEventType)pbEventType { return GrowingPBEventType_ViewClick; } else if ([self.eventType isEqualToString:@"VIEW_CHANGE"]) { return GrowingPBEventType_ViewChange; + } else if ([self.eventType isEqualToString:@"FORM_SUBMIT"]) { + return GrowingPBEventType_FormSubmit; } else if ([self.eventType isEqualToString:@"ACTIVATE"]) { return GrowingPBEventType_Activate; } diff --git a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index af13f90c2..2420531a9 100644 --- a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -69,6 +69,9 @@ - (id)growingHelper_jsonObject { case GrowingPBEventType_ViewChange: { [dic setObject:@"VIEW_CHANGE" forKey:@"eventType"]; } break; + case GrowingPBEventType_FormSubmit: { + [dic setObject:@"FORM_SUBMIT" forKey:@"eventType"]; + } break; case GrowingPBEventType_Activate: { [dic setObject:@"ACTIVATE" forKey:@"eventType"]; } break; diff --git a/Modules/SwiftProtobuf/SwiftProtobuf.swift b/Modules/SwiftProtobuf/SwiftProtobuf.swift index aaf5f8857..f6288b771 100644 --- a/Modules/SwiftProtobuf/SwiftProtobuf.swift +++ b/Modules/SwiftProtobuf/SwiftProtobuf.swift @@ -163,6 +163,8 @@ extension GrowingBaseEvent { return .viewClick } else if self.eventType == "VIEW_CHANGE" { return .viewChange + } else if self.eventType == "FORM_SUBMIT" { + return .formSubmit } else if self.eventType == "ACTIVATE" { return .activate } From fc8d18d1140aaabfc138309b9f9b307122896805 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 6 Jul 2023 10:32:41 +0800 Subject: [PATCH 006/126] =?UTF-8?q?refactor:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClickEvent/GIOClickEventViewController.m | 3 +- ...IOMeasurementProtocolTableViewController.m | 2 +- .../GIOPageAttributesEventViewController.m | 5 +- .../GIOButtonViewController.m | 2 +- .../Hybrid/gio_hybrideventtest.html | 74 ------ .../GIOChildsAddViewController.m | 5 +- .../PageStructure/GIOMultiViewController.m | 2 - .../GrowingNodeTests/NodeTest.m | 1 - .../HybridTests/HybridTest_HostApp.m | 36 --- .../WebCircleTests/WebCircleTest.m | 4 +- .../DeepLinkTests/DeepLinkTest.m | 1 + GrowingAutotracker/GrowingAutotracker.h | 30 ++- .../UIViewController+GrowingAutotracker.h | 8 +- .../UIViewController+GrowingAutotracker.m | 62 +---- .../Category/UIAlertController+GrowingNode.m | 4 +- .../Category/UICollectionView+GrowingNode.m | 24 +- .../Category/UIControl+GrowingNode.m | 1 - .../Category/UIImageView+GrowingNode.m | 10 +- .../Category/UILabel+GrowingNode.m | 3 +- .../Category/UISegmentedControl+GrowingNode.m | 15 +- .../Category/UITableView+GrowingNode.m | 25 +- .../GrowingNode/Category/UIView+GrowingNode.m | 56 +++-- .../Category/UIViewController+GrowingNode.m | 20 +- .../Category/UIWindow+GrowingNode.m | 4 - .../GrowingNode/GrowingNodeHelper.h | 7 +- .../GrowingNode/GrowingNodeHelper.m | 101 +++----- .../GrowingNode/GrowingViewChangeProvider.m | 34 ++- .../GrowingNode/GrowingViewClickProvider.m | 35 ++- .../GrowingNode/GrowingViewNode.h | 25 +- .../GrowingNode/GrowingViewNode.m | 64 +++-- .../GrowingRealAutotracker.m | 12 + GrowingAutotrackerCore/Page/GrowingPage.h | 25 +- GrowingAutotrackerCore/Page/GrowingPage.m | 109 +++++---- .../Page/GrowingPageGroup.h | 31 --- .../Page/GrowingPageGroup.m | 55 ----- .../Page/GrowingPageManager.h | 31 +-- .../Page/GrowingPageManager.m | 224 ++++++++---------- .../Event/Autotrack/GrowingViewElementEvent.h | 7 +- .../Event/Autotrack/GrowingViewElementEvent.m | 9 + .../Event/Base/GrowingBaseEvent.m | 24 +- GrowingTrackerCore/Event/GrowingEventFilter.m | 3 +- .../Event/GrowingNodeProtocol.h | 4 +- .../Tools/GrowingPersistenceDataProvider.h | 6 +- .../Tools/GrowingPersistenceDataProvider.m | 15 +- GrowingTrackerCore/GrowingRealTracker.m | 1 + .../Foundation/NSString+GrowingHelper.m | 4 +- GrowingTrackerCore/Manager/GrowingSession.h | 2 + GrowingTrackerCore/Manager/GrowingSession.m | 12 +- GrowingTrackerCore/Public/GrowingBaseEvent.h | 8 +- Modules/Flutter/GrowingFlutterPlugin.m | 7 +- .../Events/GrowingHybridViewElementEvent.h | 7 +- .../Events/GrowingHybridViewElementEvent.m | 9 + Modules/Hybrid/GrowingHybridBridgeProvider.m | 4 +- .../Catagory/GrowingBaseEvent+Protobuf.m | 12 - .../GrowingPBEventV3Dto+GrowingHelper.m | 6 - Modules/Protobuf/Proto/GrowingEvent.pbobjc.h | 10 - Modules/Protobuf/Proto/GrowingEvent.pbobjc.m | 33 --- Modules/SwiftProtobuf/SwiftProtobuf.swift | 2 - Modules/WebCircle/GrowingWebCircle.m | 43 ++-- Modules/WebCircle/GrowingWebCircleElement.h | 9 +- Modules/WebCircle/GrowingWebCircleElement.m | 22 +- 61 files changed, 531 insertions(+), 878 deletions(-) delete mode 100644 GrowingAutotrackerCore/Page/GrowingPageGroup.h delete mode 100644 GrowingAutotrackerCore/Page/GrowingPageGroup.m diff --git a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m index f799a8a62..95a86124c 100644 --- a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m +++ b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m @@ -24,13 +24,12 @@ - (void)viewDidLoad { [super viewDidLoad]; #if defined(AUTOTRACKER) #if defined(SDK3rd) - self.growingPageAttributes = @{@"greet": @"hello"}; + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"点击事件测试" attributes:@{@"greet": @"hello"}]; #endif #endif #if defined(AUTOTRACKER) #if defined(SDK3rd) - self.growingPageIgnorePolicy = GrowingIgnoreSelf; self.segmentControl.growingUniqueTag = @"language-selector"; [self.sendEventButton growingTrackImpression:@"hello_track_impression"]; [self.view growingTrackImpression:@"self_view_imp_track" attributes:@{@"self_view_key": @"self_view_value"}]; diff --git a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m index 16a56907d..cd5e88da2 100644 --- a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m +++ b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m @@ -25,7 +25,7 @@ - (void)viewDidLoad { [super viewDidLoad]; #if defined(AUTOTRACKER) #if defined(SDK3rd) - self.growingPageAttributes = @{@"xxx" : @"111mmm"}; + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"首页" attributes:@{@"xxx" : @"111mmm"}]; #endif #endif self.tableView.accessibilityIdentifier = @"MeasurementProtocolTableView"; diff --git a/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m b/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m index 22fc6190a..f332715cd 100644 --- a/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m +++ b/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m @@ -31,7 +31,7 @@ - (void)didReceiveMemoryWarning { - (void)configRandomPageAttributes { #if defined(AUTOTRACKER) #if defined(SDK3rd) - self.growingPageAttributes = [self getRandomAttributes]; + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"页面属性测试" attributes:[self getRandomAttributes]]; #endif #endif } @@ -41,11 +41,10 @@ - (IBAction)setPageAttributesBtnClick:(UIButton *)sender { } - (IBAction)setPageAttributesOutRangeBtnClick:(UIButton *)sender { - NSDictionary *pval = [GIOConstants getLargeDictionary]; #if defined(AUTOTRACKER) #if defined(SDK3rd) - self.growingPageAttributes = pval; + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"页面属性测试" attributes:pval]; #endif #endif NSLog(@"setPageVariable largeDic length is:%ld",pval.count); diff --git a/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m b/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m index 8e7921e5a..2c7e8da15 100644 --- a/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m +++ b/Example/Example/UICategoryTests/Button&AlertView/GIOButtonViewController.m @@ -35,7 +35,7 @@ - (void)viewDidLoad { [super viewDidLoad]; #if defined(AUTOTRACKER) #if defined(SDK3rd) - self.growingPageAlias = @"xxxx"; + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"Button测试"]; self.view.growingUniqueTag = @"我是一个特别的view"; #endif #endif diff --git a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html index 882a6a9d0..ecb56fa2d 100644 --- a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html +++ b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html @@ -33,24 +33,6 @@ return GrowingWebViewJavascriptBridge.configuration = JSON.parse(window.GrowingWebViewJavascriptBridge.getConfiguration()); } - function sendMockVisitEvent() { - let event = { - "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", - "sessionId": "d5cbcf77-b38b-4223-954f-c6a2fdc0c098", - "eventType": "VISIT", - "platform": "Web", - "timestamp": 1602485628504, - "domain": "test-browser.growingio.com", - "path": "/push/web.html", - "query": "a=1&b=2", - "title": "Hybrid测试页面", - "referralPage": "http://test-browser.growingio.com/push", - "globalSequenceId": 99, - "eventSequenceId": 3, - }; - sendMockEvent(event); - } - function sendMockCustomEvent() { let event = { "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", @@ -96,31 +78,6 @@ sendMockEvent(event); } - function sendMockVisitorAttributesEvent() { - let event = { - "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", - "sessionId": "d5cbcf77-b38b-4223-954f-c6a2fdc0c098", - "eventType": "VISITOR_ATTRIBUTES", - "platform": "Web", - "timestamp": 1602485628504, - "domain": "test-browser.growingio.com", - "path": "/push/web.html", - "query": "a=1&b=2", - "title": "Hybrid测试页面", - "referralPage": "http://test-browser.growingio.com/push", - "globalSequenceId": 99, - "eventSequenceId": 3, - "attributes": { - "key1": "value1", - "key2": "value2", - "key3": "", - "key4": null, - "key5": undefined - } - }; - sendMockEvent(event); - } - function sendMockLoginUserAttributesEvent() { let event = { "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", @@ -146,31 +103,6 @@ sendMockEvent(event); } - function sendMockConversionVariablesEvent() { - let event = { - "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", - "sessionId": "d5cbcf77-b38b-4223-954f-c6a2fdc0c098", - "eventType": "CONVERSION_VARIABLES", - "platform": "Web", - "timestamp": 1602485628504, - "domain": "test-browser.growingio.com", - "path": "/push/web.html", - "query": "a=1&b=2", - "title": "Hybrid测试页面", - "referralPage": "http://test-browser.growingio.com/push", - "globalSequenceId": 99, - "eventSequenceId": 3, - "attributes": { - "key1": "value1", - "key2": "value2", - "key3": "", - "key4": null, - "key5": undefined - } - }; - sendMockEvent(event); - } - function sendMockPageEvent() { let event = { "deviceId": "7196f014-d7bc-4bd8-b920-757cb2375ff6", @@ -355,15 +287,9 @@

这仅仅是一个测试页面

- - diff --git a/Example/Example/UICategoryTests/PageStructure/GIOChildsAddViewController.m b/Example/Example/UICategoryTests/PageStructure/GIOChildsAddViewController.m index 56bda955c..6e376aa18 100644 --- a/Example/Example/UICategoryTests/PageStructure/GIOChildsAddViewController.m +++ b/Example/Example/UICategoryTests/PageStructure/GIOChildsAddViewController.m @@ -13,7 +13,6 @@ @implementation GIOIgnoreBaseViewController - (void)viewDidLoad { [super viewDidLoad]; -// self.growingPageIgnorePolicy = GrowingIgnoreSelf; } @end @@ -30,9 +29,7 @@ - (void)viewDidLoad { UIViewController *parent = self.parentViewController; while (parent.parentViewController) { parent = parent.parentViewController; - } -// parent.growingPageIgnorePolicy = GrowingIgnoreAll; - + } CGFloat width = [UIScreen mainScreen].bounds.size.width; CGFloat height = [UIScreen mainScreen].bounds.size.height; diff --git a/Example/Example/UICategoryTests/PageStructure/GIOMultiViewController.m b/Example/Example/UICategoryTests/PageStructure/GIOMultiViewController.m index 862ad98cb..60fe59710 100644 --- a/Example/Example/UICategoryTests/PageStructure/GIOMultiViewController.m +++ b/Example/Example/UICategoryTests/PageStructure/GIOMultiViewController.m @@ -11,8 +11,6 @@ - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = UIColor.whiteColor; self.navigationItem.title = @"Multi ViewController"; - -// self.growingPageIgnorePolicy = GrowingIgnoreAll; } - (void)viewDidAppear:(BOOL)animated { diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m index a75de9ae1..474d629f2 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m @@ -47,7 +47,6 @@ -(void)testGrowingUIViewController { [vc1 performSelector:@selector(growingNodeSubPath)]; [vc1 performSelector:@selector(growingNodeSubSimilarPath)]; [vc1 performSelector:@selector(growingNodeChilds)]; - [vc1 performSelector:@selector(growingPageIgnorePolicy)]; #pragma clang diagnostic pop } diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m index bd72b20d3..ca539b7b9 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m @@ -63,25 +63,6 @@ - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. } -- (void)test01SendMockVisitEvent { - KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; - [self webView:actor.view evaluateJavaScript:@"sendMockVisitEvent()"]; - [viewTester waitForTimeInterval:1]; - - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; - XCTAssertEqual(events.count, 1); - - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)events.firstObject; - NSDictionary *dic = event.toDictionary; - XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeVisit); - XCTAssertTrue([ManualTrackHelper visitEventCheck:dic]); - XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - - XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); - XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); - XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); -} - - (void)test02SendMockCustomEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockCustomEvent()"]; @@ -140,23 +121,6 @@ - (void)test04SendMockLoginUserAttributesEvent { XCTAssertEqualObjects(dic[@"attributes"][@"key2"], @"value2"); } -- (void)test05SendMockConversionVariablesEvent { - KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; - [self webView:actor.view evaluateJavaScript:@"sendMockConversionVariablesEvent()"]; - [viewTester waitForTimeInterval:1]; - - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeConversionVariables]; - XCTAssertEqual(events.count, 1); - - GrowingConversionVariableEvent *event = (GrowingConversionVariableEvent *)events.firstObject; - NSDictionary *dic = event.toDictionary; - XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeConversionVariables); - XCTAssertTrue([ManualTrackHelper conversionVariablesEventCheck:dic]); - XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - - XCTAssertNotNil(dic[@"attributes"]); -} - - (void)test06SendMockPageEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockPageEvent()"]; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index 13526b956..2308a6a32 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -27,7 +27,6 @@ #import "GrowingTrackerCore/DeepLink/GrowingDeepLinkHandler.h" #import "GrowingTrackerCore/Event/GrowingNodeProtocol.h" #import "Modules/WebCircle/GrowingWebCircle.h" -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "Modules/WebCircle/GrowingWebCircleElement.h" @@ -103,8 +102,7 @@ - (void)testWebCircle { UIViewController *current = [[UIViewController alloc] init]; // 避免自动发 PAGE 报错 - current.growingPageIgnorePolicy = GrowingIgnoreSelf; - GrowingPageGroup *page = [current growingPageObject]; + GrowingPage *page = [current growingPageObject]; if (!page) { [[GrowingPageManager sharedInstance] createdViewControllerPage:current]; page = [current growingPageObject]; diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m index 371412de7..9d1d65eba 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m @@ -46,6 +46,7 @@ - (void)testDeepLinkhandlerUrl { - (BOOL)growingHandlerUrl:(NSURL *)url { XCTAssertEqualObjects(url.absoluteString, @"https://www.baidu.com"); + return YES; } @end diff --git a/GrowingAutotracker/GrowingAutotracker.h b/GrowingAutotracker/GrowingAutotracker.h index 534d2e2a0..b1f04e1e1 100644 --- a/GrowingAutotracker/GrowingAutotracker.h +++ b/GrowingAutotracker/GrowingAutotracker.h @@ -115,6 +115,23 @@ NS_ASSUME_NONNULL_BEGIN /// 清除所有事件计时器 - (void)clearTrackTimer; +///------------------------------- +#pragma mark Autotrack Event +///------------------------------- + +/// 追踪页面展示事件 +/// @param controller 被追踪页面 +/// @param alias 页面别名 +- (void)autotrackPage:(UIViewController *)controller alias:(NSString *)alias; + +/// 追踪页面展示事件 +/// @param controller 被追踪页面 +/// @param alias 页面别名 +/// @param attributes 事件发生时所伴随的维度信息 +- (void)autotrackPage:(UIViewController *)controller + alias:(NSString *)alias + attributes:(NSDictionary *)attributes; + ///------------------------------- #pragma mark Unavailable ///------------------------------- @@ -166,17 +183,4 @@ NS_ASSUME_NONNULL_BEGIN @end -// 该属性setter方法均使用 objc_setAssociatedObject实现 -// 如果是自定义的UIViewController不要使用重写getter方法来实现,因为SDK在set方法内部有逻辑处理 -@interface UIViewController (GrowingAttributes) - -// 手动标识该页面的标题,必须在该UIViewController显示之前设置 -@property (nonatomic, copy) NSString *growingPageAlias; - -@property (nonatomic, copy) NSDictionary *growingPageAttributes; - -@property (nonatomic, assign) GrowingIgnorePolicy growingPageIgnorePolicy; - -@end - NS_ASSUME_NONNULL_END diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h index aed2c81ff..3c9f7b397 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN -@class GrowingPageGroup; +@class GrowingPage; @interface UIViewController (GrowingAutotracker) @@ -29,11 +29,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy) NSDictionary *growingPageAttributes; - (BOOL)growingHookIsCustomAddVC; // 用来判断是否是没有使用addChildViewController方法的childVC -- (NSString *)growingPageName; - (nullable NSString *)growingPageTitle; -- (BOOL)growingPageDidIgnore; -- (void)setGrowingPageObject:(GrowingPageGroup *)page; -- (GrowingPageGroup *)growingPageObject; +- (void)setGrowingPageObject:(GrowingPage *)page; +- (GrowingPage *)growingPageObject; @end diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m index 912619b28..9cb1afe54 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m @@ -20,29 +20,17 @@ #import #import "GrowingAutotrackerCore/Autotrack/GrowingPropertyDefine.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" +#import "GrowingAutotrackerCore/Page/GrowingPage.h" #import "GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingTrackerCore/Utils/GrowingArgumentChecker.h" #import "GrowingULViewControllerLifecycle.h" static char kGrowingPageObjectKey; -static char kGrowingPageIgnorePolicyKey; static char kGrowingPageAttributesKey; @implementation UIViewController (GrowingAutotracker) -- (NSString *)growingPageName { - NSString *pageName = nil; - NSString *growingAttributesPageName = [self growingPageAlias]; - if (growingAttributesPageName.length > 0) { - pageName = growingAttributesPageName; - } else { - pageName = NSStringFromClass(self.class); - } - return pageName; -} - - (nullable NSString *)growingPageTitle { NSString *currentPageName = self.title; if (!currentPageName.length) { @@ -59,11 +47,11 @@ - (BOOL)growingHookIsCustomAddVC { [UIApplication sharedApplication].keyWindow.rootViewController != self; } -- (void)setGrowingPageObject:(GrowingPageGroup *)page { +- (void)setGrowingPageObject:(GrowingPage *)page { objc_setAssociatedObject(self, &kGrowingPageObjectKey, page, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (GrowingPageGroup *)growingPageObject { +- (GrowingPage *)growingPageObject { return objc_getAssociatedObject(self, &kGrowingPageObjectKey); } @@ -88,48 +76,4 @@ - (void)setGrowingPageAttributes:(NSDictionary *)attribu return [objc_getAssociatedObject(self, &kGrowingPageAttributesKey) copy]; } -- (void)setGrowingPageIgnorePolicy:(GrowingIgnorePolicy)growingPageIgnorePolicy { - objc_setAssociatedObject(self, - &kGrowingPageIgnorePolicyKey, - [NSNumber numberWithUnsignedInteger:growingPageIgnorePolicy], - OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (GrowingIgnorePolicy)growingPageIgnorePolicy { - id policyObjc = objc_getAssociatedObject(self, &kGrowingPageIgnorePolicyKey); - if (!policyObjc) { - return GrowingIgnoreNone; - } - - if ([policyObjc isKindOfClass:NSNumber.class]) { - NSNumber *policyNum = (NSNumber *)policyObjc; - return policyNum.unsignedIntegerValue; - } - - return GrowingIgnoreNone; -} - -- (BOOL)growingPageDidIgnore { - // judge self firstly - GrowingIgnorePolicy selfPolicy = self.growingPageIgnorePolicy; - if (GrowingIgnoreAll == selfPolicy || GrowingIgnoreSelf == selfPolicy) { - return YES; - } - - // judge parent - UIViewController *current = self; - while (current.parentViewController) { - UIViewController *parent = current.parentViewController; - GrowingIgnorePolicy parentPolicy = parent.growingPageIgnorePolicy; - - if (GrowingIgnoreChildren == parentPolicy || GrowingIgnoreAll == parentPolicy) { - return YES; - } - - current = parent; - } - - return NO; -} - @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m index be26af34b..d059d80f0 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m @@ -103,12 +103,10 @@ - (BOOL)growingNodeUserInteraction { - (NSString *)growingNodeContent { NSString *nodeContent = [[UIAlertController growing_actionForActionView:(id)self] title]; - if (nodeContent.length) { return nodeContent; - } else { - return self.accessibilityLabel; } + return nil; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m index 74d9ec2fd..3b93d4b2d 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m @@ -56,23 +56,31 @@ - (NSIndexPath *)growingNodeIndexPath { } - (NSString *)growingNodeSubPath { + if (self.growingUniqueTag.length > 0) { + return self.growingUniqueTag; + } + NSIndexPath *indexpath = [self growingNodeIndexPath]; if (indexpath) { - return [NSString stringWithFormat:@"Section[%ld]/%@[%ld]", - (long)indexpath.section, - NSStringFromClass(self.class), - (long)indexpath.row]; + return [NSString stringWithFormat:@"Section/%@", NSStringFromClass(self.class)]; } return [super growingNodeSubPath]; } -- (NSString *)growingNodeSubSimilarPath { +- (NSString *)growingNodeSubIndex { NSIndexPath *indexpath = [self growingNodeIndexPath]; if (indexpath) { - return - [NSString stringWithFormat:@"Section[%ld]/%@[-]", (long)indexpath.section, NSStringFromClass(self.class)]; + return [NSString stringWithFormat:@"%ld/%ld", (long)indexpath.section, (long)indexpath.row]; } - return [super growingNodeSubPath]; + return [super growingNodeSubIndex]; +} + +- (NSString *)growingNodeSubSimilarIndex { + NSIndexPath *indexpath = [self growingNodeIndexPath]; + if (indexpath) { + return [NSString stringWithFormat:@"%ld/-", (long)indexpath.section]; + } + return [super growingNodeSubIndex]; } - (BOOL)growingNodeUserInteraction { diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIControl+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIControl+GrowingNode.m index b8dc82b75..791b5a3b6 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIControl+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIControl+GrowingNode.m @@ -43,7 +43,6 @@ - (NSString *)growingViewContent { } } - // TODO: Improve the logic and performance using DFS while (unvisted.count) { UIView *current = unvisted.firstObject; [unvisted removeObject:current]; diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIImageView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIImageView+GrowingNode.m index 1adaed701..7aafb38bb 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIImageView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIImageView+GrowingNode.m @@ -23,13 +23,9 @@ @implementation UIImageView (GrowingNode) - (NSString *)growingViewContent { - if (self.accessibilityLabel.length) { - return self.accessibilityLabel; - } else { - for (UIView *view in self.subviews) { - if ([view isKindOfClass:[UILabel class]] && [view growingViewContent].length) { - return [view growingViewContent]; - } + for (UIView *view in self.subviews) { + if ([view isKindOfClass:[UILabel class]] && [view growingViewContent].length) { + return [view growingViewContent]; } } diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m index beb7ec5f0..fdb61fee4 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m @@ -24,9 +24,8 @@ @implementation UILabel (GrowingNode) - (NSString *)growingViewContent { if (self.text.length) { return self.text; - } else { - return self.accessibilityLabel; } + return nil; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m index ea89c9cae..a460fec91 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m @@ -70,25 +70,16 @@ - (BOOL)growingViewUserInteraction { return nil; } -- (NSString *)growingNodeSubSimilarPath { - // 如果手动标识了该view,返回标识 - if ([self respondsToSelector:@selector(growingUniqueTag)]) { - if (self.growingUniqueTag.length > 0) { - return self.growingUniqueTag; - } - } - - NSString *className = NSStringFromClass(self.class); - return index < 0 ? className : [NSString stringWithFormat:@"%@[-]", className]; +- (NSString *)growingNodeSubSimilarIndex { + return @"-"; } - (NSString *)growingNodeContent { NSString *nodeContent = [UISegmentedControl growing_titleForSegment:(id)self]; if (nodeContent.length) { return nodeContent; - } else { - return self.accessibilityLabel; } + return nil; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m index f14259ba6..f7c89a1ed 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m @@ -56,24 +56,31 @@ - (NSIndexPath *)growingNodeIndexPath { } - (NSString *)growingNodeSubPath { + if (self.growingUniqueTag.length > 0) { + return self.growingUniqueTag; + } + NSIndexPath *indexpath = [self growingNodeIndexPath]; if (indexpath) { - return [NSString stringWithFormat:@"Section[%ld]/%@[%ld]", - (long)indexpath.section, - NSStringFromClass(self.class), - (long)indexpath.row]; - ; + return [NSString stringWithFormat:@"Section/%@", NSStringFromClass(self.class)]; } return [super growingNodeSubPath]; } -- (NSString *)growingNodeSubSimilarPath { +- (NSString *)growingNodeSubIndex { NSIndexPath *indexpath = [self growingNodeIndexPath]; if (indexpath) { - return - [NSString stringWithFormat:@"Section[%ld]/%@[-]", (long)indexpath.section, NSStringFromClass(self.class)]; + return [NSString stringWithFormat:@"%ld/%ld", (long)indexpath.section, (long)indexpath.row]; } - return [super growingNodeSubPath]; + return [super growingNodeSubIndex]; +} + +- (NSString *)growingNodeSubSimilarIndex { + NSIndexPath *indexpath = [self growingNodeIndexPath]; + if (indexpath) { + return [NSString stringWithFormat:@"%ld/-", (long)indexpath.section]; + } + return [super growingNodeSubIndex]; } - (NSArray> *)growingNodeChilds { diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index 752b91284..539b5005e 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -66,14 +66,22 @@ - (NSString *)growingNodeSubPath { if (self.growingUniqueTag.length > 0) { return self.growingUniqueTag; } - // 返回类型+index + + return NSStringFromClass(self.class); +} + +- (NSString *)growingNodeSubIndex { + // UITableViewWrapperView 为 iOS11 以下 UITableView 与 cell 之间的 view + if ([NSStringFromClass(self.class) isEqualToString:@"UITableViewWrapperView"]) { + return nil; + } + NSInteger index = [self growingNodeKeyIndex]; - NSString *className = NSStringFromClass(self.class); - return index < 0 ? className : [NSString stringWithFormat:@"%@[%ld]", className, (long)index]; + return index < 0 ? @"0" : [NSString stringWithFormat:@"%ld", (long)index]; } -- (NSString *)growingNodeSubSimilarPath { - return [self growingNodeSubPath]; +- (NSString *)growingNodeSubSimilarIndex { + return [self growingNodeSubIndex]; } - (NSArray> *)growingNodeChilds { @@ -198,28 +206,26 @@ - (BOOL)growingNodeDonotCircle { } - (NSString *)growingViewContent { - // apple在11.1.2的部分机型上很小概率对于class为UIPickerTableView的对象调用accessibilityLabel可能会崩溃 - // 此为apple bug - NSString *className = NSStringFromClass(self.class); - NSString *prefixString = @"UIPicke"; - NSString *suffixString = @"rTableView"; - if ([className hasPrefix:prefixString] && [className hasSuffix:suffixString] && - className.length == (prefixString.length + suffixString.length)) { - return nil; - } else { - // https://growingio.atlassian.net/browse/PI-839 美图IOS崩溃 - // 目前无法预知什么情况下还会有类似crash, 不再对控件类名做判断, - // 直接try/catch处理 - NSString *accessibilityLabel = nil; - @try { - accessibilityLabel = self.accessibilityLabel; - } @catch (NSException *exception) { - accessibilityLabel = nil; - } @finally { - // do nothing + NSMutableArray *unvisted = [[NSMutableArray alloc] init]; + if (self.subviews.count) { + [unvisted addObjectsFromArray:self.subviews]; + } + + while (unvisted.count) { + UIView *current = unvisted.firstObject; + [unvisted removeObject:current]; + if ([current isKindOfClass:[UILabel class]] && [current growingViewContent].length) { + return [current growingViewContent]; + } + if ([current isKindOfClass:[UIImageView class]] && [(UIImageView *)current growingViewContent].length) { + return [(UIImageView *)current growingViewContent]; + } + if (current.subviews.count) { + unvisted = [[current.subviews arrayByAddingObjectsFromArray:unvisted] mutableCopy]; } - return accessibilityLabel; } + + return nil; } #pragma mark - GrowingNodeProtocol diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m index 457f65420..346e2d47d 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m @@ -22,7 +22,6 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.h" -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" @implementation UIViewController (GrowingNode) @@ -74,7 +73,7 @@ - (CGRect)growingNodeFrame { // UIAlertController的presentingViewController 为 UIApplicationRotationFollowingController // 取最上层的视图控制器,则无法使用上面两种方式。 if ([self isKindOfClass:UIAlertController.class]) { - return [[GrowingPageManager sharedInstance] currentViewController]; + return [[GrowingPageManager sharedInstance] currentPage].carrier; } else { return self.parentViewController; } @@ -105,7 +104,7 @@ - (BOOL)growingNodeUserInteraction { } - (NSString *)growingNodeContent { - return self.accessibilityLabel; + return nil; } #pragma mark - xpath @@ -131,17 +130,16 @@ - (NSInteger)growingNodeKeyIndex { } - (NSString *)growingNodeSubPath { - // 如果别名存在,则直接返回别名 - if (self.growingPageAlias) { - return self.growingPageAlias; - } + return NSStringFromClass(self.class); +} + +- (NSString *)growingNodeSubIndex { NSInteger index = [self growingNodeKeyIndex]; - NSString *className = NSStringFromClass(self.class); - return index < 0 ? className : [NSString stringWithFormat:@"%@[%ld]", className, (long)index]; + return index < 0 ? @"0" : [NSString stringWithFormat:@"%ld", (long)index]; } -- (NSString *)growingNodeSubSimilarPath { - return [self growingNodeSubPath]; +- (NSString *)growingNodeSubSimilarIndex { + return [self growingNodeSubIndex]; } - (NSArray> *)growingNodeChilds { diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m index 7ebb97c81..0d44354bc 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m @@ -46,8 +46,4 @@ - (BOOL)growingViewUserInteraction { return NO; } -- (NSString *)growingViewContent { - return self.accessibilityLabel; -} - @end diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h index 2fdb3eb53..0befa35e0 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h @@ -24,11 +24,8 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingNodeHelper : NSObject -+ (nullable NSString *)xPathSimilarForNode:(id)node; -+ (nullable NSString *)xPathForNode:(id)node; - -+ (NSString *)xPathForView:(nullable UIView *)view similar:(BOOL)isSimilar; -+ (NSString *)xPathForViewController:(UIViewController *)vc; ++ (void)recalculateXpath:(UIView *)view + block:(void (^)(NSString *xpath, NSString *xindex, NSString *originxindex))block; + (NSString *)buildElementContentForNode:(id _Nullable)view; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 0fd8af6bb..8414f82ba 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -20,7 +20,6 @@ #import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" @@ -29,81 +28,40 @@ @implementation GrowingNodeHelper -// 当node为列表视图时,返回路径为 TableView/cell[-],序号在index字段中返回 -+ (nullable NSString *)xPathSimilarForNode:(id)node { - if ([node isKindOfClass:[UIView class]]) { - return [self xPathForView:(UIView *)node similar:YES]; - } else if ([node isKindOfClass:[UIViewController class]]) { - return [self xPathForViewController:(UIViewController *)node]; - } - return nil; -} - -+ (nullable NSString *)xPathForNode:(id)node { - if ([node isKindOfClass:[UIView class]]) { - return [self xPathForView:(UIView *)node similar:NO]; - } else if ([node isKindOfClass:[UIViewController class]]) { - return [self xPathForViewController:(UIViewController *)node]; - } - return nil; -} - -/// 获取某个view的xpath -/// @param view 节点 -/// @param isSimilar 是否返回相似路径 -+ (NSString *)xPathForView:(nullable UIView *)view similar:(BOOL)isSimilar { - NSMutableArray *viewPathArray = [NSMutableArray array]; ++ (void)recalculateXpath:(UIView *)view + block:(void (^)(NSString *xpath, NSString *xindex, NSString *originxindex))block { id node = view; - + NSMutableArray *viewPathArray = [NSMutableArray array]; + NSMutableArray *xindexArray = [NSMutableArray array]; + NSMutableArray *originxindexArray = [NSMutableArray array]; + BOOL isSimilar = YES; while (node && [node isKindOfClass:[UIView class]]) { + if (node.growingNodeSubPath == nil) { + continue; + } + [viewPathArray addObject:node.growingNodeSubPath]; + [xindexArray addObject:node.growingNodeSubIndex]; if (isSimilar) { - if (node.growingNodeSubSimilarPath.length > 0) { - [viewPathArray addObject:node.growingNodeSubSimilarPath]; - isSimilar = NO; - } + [originxindexArray addObject:node.growingNodeSubSimilarIndex]; + isSimilar = NO; } else { - if (node.growingNodeSubPath.length > 0) [viewPathArray addObject:node.growingNodeSubPath]; + [originxindexArray addObject:node.growingNodeSubIndex]; } + node = node.growingNodeParent; } - // 当检测到viewController时,会替换成page字段 - // 此时则需要判断是否ignored以及过滤 - if ([node isKindOfClass:[UIViewController class]]) { - // vc.view不计入xpath - // eg:UIViewController/view => /Page/ - // eg:UIViewController/TableView => /Page/ - if (viewPathArray.count > 0) { - [viewPathArray removeLastObject]; - } - while (node) { - if ([[GrowingPageManager sharedInstance] isPrivateViewControllerIgnored:(UIViewController *)node]) { - if (node.growingNodeSubPath.length > 0) [viewPathArray addObject:node.growingNodeSubPath]; - } else { - GrowingPageGroup *page = [(UIViewController *)node growingPageObject]; - if (page.isIgnored) { - if (node.growingNodeSubPath.length > 0) [viewPathArray addObject:node.growingNodeSubPath]; - } else { - [viewPathArray addObject:kGrowingNodeRootPage]; - break; - } - } - node = node.growingNodeParent; - } - // 如果遍历到了根节点(即没有parent),说明所有层级vc都被过滤,则添加IgnorePage - if (!node) { - [viewPathArray addObject:kGrowingNodeRootIgnore]; - } - } - NSString *viewPath = [[[viewPathArray reverseObjectEnumerator] allObjects] componentsJoinedByString:@"/"]; - viewPath = [@"/" stringByAppendingString:viewPath]; - return viewPath; -} + NSString * (^toStringBlock)(NSArray *) = ^(NSArray *array) { + NSArray *reverse = array.reverseObjectEnumerator.allObjects; + return [@"/" stringByAppendingString:[reverse componentsJoinedByString:@"/"]]; + }; -+ (NSString *)xPathForViewController:(UIViewController *)vc { - NSAssert(vc, @"+xPathForViewController: vc is nil"); - GrowingPageGroup *page = [[GrowingPageManager sharedInstance] findPageByViewController:vc]; - return page.path; + NSString *xpath = toStringBlock(viewPathArray); + NSString *xindex = toStringBlock(xindexArray); + NSString *originxindex = toStringBlock(originxindexArray); + if (block) { + block(xpath, xindex, originxindex); + } } + (NSString *)buildElementContentForNode:(id _Nullable)view { @@ -136,7 +94,7 @@ + (NSString *)buildElementContentForNode:(id _Nullable)view { + (GrowingViewNode *)getViewNode:(UIView *)view { NSPointerArray *weakArray = [NSPointerArray weakObjectsPointerArray]; GrowingViewNode *viewNode = [self getTopViewNode:view array:weakArray]; - for (int i = (int)weakArray.count - 2; i >= 0; i--) { + for (int i = (int)weakArray.count - 1; i >= 0; i--) { UIView *parent = [weakArray pointerAtIndex:i]; if (parent) { viewNode = [viewNode appendNode:parent isRecalculate:NO]; @@ -157,13 +115,12 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA } while ([parent isKindOfClass:[UIView class]]); UIView *rootview = [weakArray pointerAtIndex:weakArray.count - 1]; - NSString *xpath = [self xPathForView:rootview similar:YES]; - NSString *originXPath = [self xPathForView:rootview similar:NO]; return GrowingViewNode.builder.setView(rootview) .setIndex(-1) .setViewContent([self buildElementContentForNode:rootview]) - .setXPath(xpath) - .setOriginXPath(originXPath) + .setXpath(@"") + .setXindex(@"") + .setOriginXindex(@"") .setNodeType([self getViewNodeType:rootview]) .build; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index 6908e8793..485b3a12a 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -22,10 +22,8 @@ #import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" -#import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" @implementation GrowingViewChangeProvider @@ -35,26 +33,24 @@ + (void)viewOnChange:(UIView *)view { GIOLogDebug(@"viewOnChange %@ is donotTrack", view); return; } - GrowingPageGroup *page = [[GrowingPageManager sharedInstance] findPageByView:view]; - if (!page) { - page = [[GrowingPageManager sharedInstance] currentPage]; - } + GrowingPage *page = [GrowingPageManager.sharedInstance findPageByView:view]; + GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page]; GrowingViewNode *node = [GrowingNodeHelper getViewNode:view]; - [self sendChangeEvent:page viewNode:node]; -} -+ (void)sendChangeEvent:(GrowingPageGroup *)page viewNode:(GrowingViewNode *)node { - GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder - .setEventType(GrowingEventTypeViewChange) - .setPath(page.path) - .setXpath(node.xPath) - .setIndex(node.index) - .setTextValue(node.viewContent); - - if (!page.isIgnored) { - builder.setAttributes([page.carrier growingPageAttributes]); + NSDictionary *pathInfo = page.pathInfo; + NSString *pagexpath = pathInfo[@"xpath"]; + NSString *pagexindex = pathInfo[@"xindex"]; + GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange) + .setPath(@"") + .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) + .setIndex(node.index) + .setTextValue(node.viewContent); + + if (autotrackPage) { + builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes); } - + [[GrowingEventManager sharedInstance] postEventBuilder:builder]; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index a9b248d49..413373ca0 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -22,10 +22,8 @@ #import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" -#import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" @implementation GrowingViewClickProvider @@ -35,26 +33,25 @@ + (void)viewOnClick:(UIView *)view { GIOLogDebug(@"viewOnClick %@ is donotTrack", view); return; } - GrowingPageGroup *page = [[GrowingPageManager sharedInstance] findPageByView:view]; - if (!page) { - page = [[GrowingPageManager sharedInstance] currentPage]; - } + + GrowingPage *page = [GrowingPageManager.sharedInstance findPageByView:view]; + GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page]; GrowingViewNode *node = [GrowingNodeHelper getViewNode:view]; - [self sendClickEvent:page viewNode:node]; -} -+ (void)sendClickEvent:(GrowingPageGroup *)page viewNode:(GrowingViewNode *)node { - GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder - .setEventType(GrowingEventTypeViewClick) - .setPath(page.path) - .setXpath(node.xPath) - .setIndex(node.index) - .setTextValue(node.viewContent); - - if (!page.isIgnored) { - builder.setAttributes([page.carrier growingPageAttributes]); + NSDictionary *pathInfo = page.pathInfo; + NSString *pagexpath = pathInfo[@"xpath"]; + NSString *pagexindex = pathInfo[@"xindex"]; + GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick) + .setPath(@"") + .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) + .setIndex(node.index) + .setTextValue(node.viewContent); + + if (autotrackPage) { + builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes); } - + [[GrowingEventManager sharedInstance] postEventBuilder:builder]; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h index 7c70af758..cec11c5b6 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h @@ -27,11 +27,12 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak, readonly) UIView *_Nullable view; @property (nonatomic, copy, readonly) NSString *_Nullable viewContent; -@property (nonatomic, copy, readonly) NSString *_Nonnull xPath; -// 原始的xpath -@property (nonatomic, copy, readonly) NSString *_Nonnull originXPath; +@property (nonatomic, copy, readonly) NSString *_Nonnull xpath; +@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; +// 原始的位置组 +@property (nonatomic, copy, readonly) NSString *_Nonnull originxindex; // 可点击的父节点xpath -@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXPath; +@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXpath; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; @@ -57,11 +58,12 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, readonly) UIView *_Nullable view; @property (nonatomic, copy, readonly) NSString *_Nullable viewContent; -@property (nonatomic, copy, readonly) NSString *_Nonnull xPath; -// 原始的xpath -@property (nonatomic, copy, readonly) NSString *_Nonnull originXPath; +@property (nonatomic, copy, readonly) NSString *_Nonnull xpath; +@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; +// 原始的位置组 +@property (nonatomic, copy, readonly) NSString *_Nonnull originxindex; // 可点击的父节点xpath -@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXPath; +@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXpath; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; @@ -72,9 +74,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) BOOL needRecalculate; - (GrowingViewNodeBuilder * (^)(UIView *value))setView; -- (GrowingViewNodeBuilder * (^)(NSString *value))setXPath; -- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXPath; -- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXPath; +- (GrowingViewNodeBuilder * (^)(NSString *value))setXpath; +- (GrowingViewNodeBuilder * (^)(NSString *value))setXindex; +- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXindex; +- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXpath; - (GrowingViewNodeBuilder * (^)(int value))setIndex; - (GrowingViewNodeBuilder * (^)(int value))setPosition; - (GrowingViewNodeBuilder * (^)(long long value))setTimestamp; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m index 4a0323a4a..87caa8fce 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m @@ -25,15 +25,24 @@ #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingULTimeUtil.h" +@interface GrowingViewNode () + +@property (nonatomic, copy, readwrite) NSString *_Nonnull xpath; +@property (nonatomic, copy, readwrite) NSString *_Nonnull xindex; +@property (nonatomic, copy, readwrite) NSString *_Nonnull originxindex; + +@end + @implementation GrowingViewNode - (instancetype)initWithBuilder:(GrowingViewNodeBuilder *)builder { if (self = [super init]) { _view = builder.view; _viewContent = builder.viewContent; - _xPath = builder.xPath; - _originXPath = builder.originXPath; - _clickableParentXPath = builder.clickableParentXPath; + _xpath = builder.xpath; + _xindex = builder.xindex; + _originxindex = builder.originxindex; + _clickableParentXpath = builder.clickableParentXpath; _nodeType = builder.nodeType; _index = builder.index; _position = builder.position; @@ -48,8 +57,15 @@ - (instancetype)initWithBuilder:(GrowingViewNodeBuilder *)builder { } - (void)recalculate { - _xPath = [GrowingNodeHelper xPathForView:self.view similar:YES]; - _originXPath = [GrowingNodeHelper xPathForView:self.view similar:NO]; + __weak typeof(self) weakSelf = self; + [GrowingNodeHelper + recalculateXpath:self.view + block:^(NSString *_Nonnull xpath, NSString *_Nonnull xindex, NSString *_Nonnull originxindex) { + __strong typeof(weakSelf) self = weakSelf; + self.xpath = xpath; + self.xindex = xindex; + self.originxindex = originxindex; + }]; } + (GrowingViewNodeBuilder *)builder { @@ -62,9 +78,10 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { if (!subpath) { return GrowingViewNode.builder.setView(view) .setIndex(self.index) - .setXPath(self.xPath) - .setOriginXPath(self.originXPath) - .setClickableParentXPath(self.clickableParentXPath) + .setXpath(self.xpath) + .setXindex(self.xindex) + .setOriginXindex(self.originxindex) + .setClickableParentXpath(self.clickableParentXpath) .setHasListParent(self.hasListParent) .setViewContent(self.viewContent) .setPosition(self.position) @@ -86,15 +103,15 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { index = self.index; } - NSString *parentXPath = self.view.growingNodeUserInteraction ? self.xPath : self.clickableParentXPath; + NSString *parentXpath = self.view.growingNodeUserInteraction ? self.xpath : self.clickableParentXpath; NSString *content = view.growingNodeContent; - NSString *similar_path = view.growingNodeSubSimilarPath; return GrowingViewNode.builder.setView(view) .setIndex((int)index) - .setXPath([self.originXPath stringByAppendingFormat:@"/%@", similar_path]) - .setOriginXPath([self.originXPath stringByAppendingFormat:@"/%@", subpath]) - .setClickableParentXPath(parentXPath) + .setXpath([self.xpath stringByAppendingFormat:@"/%@", view.growingNodeSubPath]) + .setXindex([self.originxindex stringByAppendingFormat:@"/%@", view.growingNodeSubSimilarIndex]) + .setOriginXindex([self.originxindex stringByAppendingFormat:@"/%@", view.growingNodeSubIndex]) + .setClickableParentXpath(parentXpath) .setHasListParent(haslistParent) .setViewContent(content ? [content growingHelper_safeSubStringWithLength:50] : nil) .setPosition((int)view.growingNodeKeyIndex) @@ -114,21 +131,30 @@ @implementation GrowingViewNodeBuilder }; } -- (GrowingViewNodeBuilder * (^)(NSString *value))setXPath { +- (GrowingViewNodeBuilder * (^)(NSString *value))setXpath { return ^(NSString *value) { - self->_xPath = value; + self->_xpath = value; return self; }; } -- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXPath { + +- (GrowingViewNodeBuilder * (^)(NSString *value))setXindex { return ^(NSString *value) { - self->_originXPath = value; + self->_xindex = value; return self; }; } -- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXPath { + +- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXindex { + return ^(NSString *value) { + self->_originxindex = value; + return self; + }; +} + +- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXpath { return ^(NSString *value) { - self->_clickableParentXPath = value; + self->_clickableParentXpath = value; return self; }; } diff --git a/GrowingAutotrackerCore/GrowingRealAutotracker.m b/GrowingAutotrackerCore/GrowingRealAutotracker.m index d34ccc3f1..3e8c507cf 100644 --- a/GrowingAutotrackerCore/GrowingRealAutotracker.m +++ b/GrowingAutotrackerCore/GrowingRealAutotracker.m @@ -28,8 +28,10 @@ #import "GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h" +#import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" +#import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" #import "GrowingULSwizzle.h" #import "GrowingULViewControllerLifecycle.h" @@ -49,6 +51,16 @@ - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration return self; } +- (void)autotrackPage:(UIViewController *)controller alias:(NSString *)alias { + [GrowingPageManager.sharedInstance autotrackPage:controller alias:alias attributes:nil]; +} + +- (void)autotrackPage:(UIViewController *)controller + alias:(NSString *)alias + attributes:(NSDictionary *)attributes { + [GrowingPageManager.sharedInstance autotrackPage:controller alias:alias attributes:attributes]; +} + - (void)addAutoTrackSwizzles { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ diff --git a/GrowingAutotrackerCore/Page/GrowingPage.h b/GrowingAutotrackerCore/Page/GrowingPage.h index 46d04b557..5de053689 100644 --- a/GrowingAutotrackerCore/Page/GrowingPage.h +++ b/GrowingAutotrackerCore/Page/GrowingPage.h @@ -20,24 +20,25 @@ #import #import -@class GrowingPageGroup; - @interface GrowingPage : NSObject -@property (readonly, weak, nonatomic) UIViewController *carrier; -@property (readwrite, strong, nonatomic) GrowingPageGroup *parent; -@property (readonly, assign, nonatomic) long long showTimestamp; -@property (readwrite, assign, nonatomic) BOOL isIgnored; -@property (readonly, copy, nonatomic) NSString *name; -@property (readonly, copy, nonatomic) NSString *title; -@property (readwrite, copy, nonatomic) NSString *alias; -@property (readonly, copy, nonatomic) NSString *path; -@property (readwrite, strong, nonatomic) NSDictionary *variables; +@property (nonatomic, weak, readonly) UIViewController *carrier; +@property (nonatomic, copy, readonly) NSString *title; +@property (nonatomic, assign, readonly, getter=isAutotrack) BOOL autotrack; +@property (nonatomic, copy, readonly) NSDictionary *attributes; +@property (nonatomic, assign, readonly) long long showTimestamp; + +@property (nonatomic, copy, readonly) NSString *alias; +@property (nonatomic, copy, readonly) NSDictionary *pathInfo; -- (instancetype)initWithCarrier:(UIViewController *)carrier; +@property (nonatomic, strong) GrowingPage *parent; +@property (nonatomic, strong, readonly) NSPointerArray *childPages; + (instancetype)pageWithCarrier:(UIViewController *)carrier; - (void)refreshShowTimestamp; +- (void)addChildrenPage:(GrowingPage *)page; +- (void)removeChildrenPage:(GrowingPage *)page; + @end diff --git a/GrowingAutotrackerCore/Page/GrowingPage.m b/GrowingAutotrackerCore/Page/GrowingPage.m index db1719f98..5edd932ec 100644 --- a/GrowingAutotrackerCore/Page/GrowingPage.m +++ b/GrowingAutotrackerCore/Page/GrowingPage.m @@ -19,23 +19,23 @@ #import "GrowingAutotrackerCore/Page/GrowingPage.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" +#import "GrowingTrackerCore/Utils/GrowingInternalMacros.h" #import "GrowingULTimeUtil.h" -@interface GrowingPage () -@property (nonatomic, copy, readonly) NSString *pathCopy; -@end +@implementation GrowingPage { + GROWING_LOCK_DECLARE(lock); +} -@implementation GrowingPage +#pragma mark - Init - (instancetype)initWithCarrier:(UIViewController *)carrier { self = [super init]; if (self) { _carrier = carrier; _showTimestamp = GrowingULTimeUtil.currentTimeMillis; - _isIgnored = [carrier growingPageDidIgnore]; - _title = [carrier growingPageTitle]; + _childPages = [NSPointerArray pointerArrayWithOptions:NSPointerFunctionsWeakMemory]; + GROWING_LOCK_INIT(lock); } return self; @@ -45,26 +45,49 @@ + (instancetype)pageWithCarrier:(UIViewController *)carrier { return [[self alloc] initWithCarrier:carrier]; } +#pragma mark - Public + - (void)refreshShowTimestamp { _showTimestamp = GrowingULTimeUtil.currentTimeMillis; } -- (NSString *)name { - if (self.carrier == nil) { - return nil; +- (void)addChildrenPage:(GrowingPage *)page { + GROWING_LOCK(lock); + if (![self.childPages.allObjects containsObject:page]) { + [self.childPages addPointer:(__bridge void *)page]; } + GROWING_UNLOCK(lock); +} - if (![NSString growingHelper_isBlankString:self.alias]) { - return self.alias; - } +- (void)removeChildrenPage:(GrowingPage *)page { + GROWING_LOCK(lock); + [self.childPages.allObjects enumerateObjectsWithOptions:NSEnumerationReverse + usingBlock:^(NSObject *obj, NSUInteger idx, BOOL *_Nonnull stop) { + if (page == obj) { + [self.childPages removePointerAtIndex:idx]; + *stop = YES; + } + }]; + GROWING_UNLOCK(lock); +} - NSString *clazz = NSStringFromClass(self.carrier.class); - NSString *tag = self.tag; - if (tag == nil) { - return clazz; - } else { - return [NSString stringWithFormat:@"%@[%@]", clazz, tag]; - } +#pragma mark - Setter & Getter + +// 所有属性都通过动态获取,不做内存存储 +- (BOOL)isAutotrack { + return self.carrier.growingPageAlias != nil; +} + +- (NSString *)title { + return self.carrier.growingPageTitle; +} + +- (NSDictionary *)attributes { + return self.carrier.growingPageAttributes; +} + +- (NSString *)alias { + return self.carrier.growingPageAlias; } - (NSString *)tag { @@ -89,38 +112,24 @@ - (NSString *)tag { return nil; } -- (NSString *)path { - if (self.pathCopy != nil) { - return self.pathCopy; - } - - if (self.alias != nil) { - _pathCopy = [NSString stringWithFormat:@"/%@", self.alias]; - return self.pathCopy; - } - - NSMutableArray *pageTree = [NSMutableArray array]; - [pageTree addObject:self]; - GrowingPageGroup *pageParent = self.parent; - while (pageParent != nil) { - [pageTree addObject:pageParent]; - if (![NSString growingHelper_isBlankString:pageParent.alias]) { - break; - } +- (NSDictionary *)pathInfo { + NSPointerArray *pageTree = [NSPointerArray pointerArrayWithOptions:NSPointerFunctionsWeakMemory]; + GrowingPage *pageParent = self; + do { + [pageTree addPointer:(__bridge void *)pageParent]; pageParent = pageParent.parent; + } while (pageParent != nil); + + NSMutableString *xpath = [NSMutableString string]; + NSMutableString *xindex = [NSMutableString string]; + NSArray *array = pageTree.allObjects; + for (int i = (int)(array.count - 1); i >= 0; i--) { + GrowingPage *page = array[i]; + [xpath appendFormat:@"/%@", NSStringFromClass(page.carrier.class)]; + [xindex appendFormat:@"/%@", page.tag ?: @"0"]; } - NSString *path = [NSString string]; - for (NSInteger i = 0; i < pageTree.count; ++i) { - if (i >= 3) { - // SDK3.0 xpath逻辑调整,仅遍历UIViewController的三层视图 - path = [NSString stringWithFormat:@"*%@", path]; - break; - } - NSString *subpath = [NSString stringWithFormat:@"/%@", pageTree[i].name]; - path = [NSString stringWithFormat:@"%@%@", subpath, path]; - } - _pathCopy = path; - return self.pathCopy; + + return @{@"xpath": xpath, @"xindex": xindex}; } @end diff --git a/GrowingAutotrackerCore/Page/GrowingPageGroup.h b/GrowingAutotrackerCore/Page/GrowingPageGroup.h deleted file mode 100644 index 31a50a33b..000000000 --- a/GrowingAutotrackerCore/Page/GrowingPageGroup.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// GrowingPageGroup.h -// GrowingAnalytics -// -// Created by xiangyang on 2020/4/27. -// Copyright (C) 2020 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import -#import "GrowingAutotrackerCore/Page/GrowingPage.h" - -@interface GrowingPageGroup : GrowingPage - -@property (nonatomic, readonly, strong) NSPointerArray *childPages; - -- (void)addChildrenPage:(GrowingPage *)page; - -- (void)removeChildrenPage:(GrowingPage *)page; - -@end diff --git a/GrowingAutotrackerCore/Page/GrowingPageGroup.m b/GrowingAutotrackerCore/Page/GrowingPageGroup.m deleted file mode 100644 index e6e83dced..000000000 --- a/GrowingAutotrackerCore/Page/GrowingPageGroup.m +++ /dev/null @@ -1,55 +0,0 @@ -// -// GrowingPageGroup.m -// GrowingAnalytics -// -// Created by xiangyang on 2020/4/27. -// Copyright (C) 2020 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" -#import "GrowingTrackerCore/Utils/GrowingInternalMacros.h" - -@implementation GrowingPageGroup { - GROWING_LOCK_DECLARE(lock); -} - -- (void)addChildrenPage:(GrowingPage *)page { - GROWING_LOCK(lock); - if (![self.childPages.allObjects containsObject:page]) { - [self.childPages addPointer:(__bridge void *)page]; - } - GROWING_UNLOCK(lock); -} - -- (void)removeChildrenPage:(GrowingPage *)page { - GROWING_LOCK(lock); - [self.childPages.allObjects enumerateObjectsWithOptions:NSEnumerationReverse - usingBlock:^(NSObject *obj, NSUInteger idx, BOOL *_Nonnull stop) { - if (page == obj) { - [self.childPages removePointerAtIndex:idx]; - *stop = YES; - } - }]; - GROWING_UNLOCK(lock); -} - -- (instancetype)initWithCarrier:(UIViewController *)carrier { - if (self = [super initWithCarrier:carrier]) { - _childPages = [NSPointerArray pointerArrayWithOptions:NSPointerFunctionsWeakMemory]; - GROWING_LOCK_INIT(lock); - } - return self; -} - -@end diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.h b/GrowingAutotrackerCore/Page/GrowingPageManager.h index 9f1386aaf..021796e01 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.h +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.h @@ -18,8 +18,9 @@ // limitations under the License. #import -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" -#import "GrowingULViewControllerLifecycle.h" +#import "GrowingAutotrackerCore/Page/GrowingPage.h" + +NS_ASSUME_NONNULL_BEGIN @interface GrowingPageManager : NSObject @@ -27,25 +28,17 @@ - (void)start; -- (void)createdViewControllerPage:(UIViewController *)viewController; - -- (BOOL)isPrivateViewControllerIgnored:(UIViewController *)viewController; - -// All ViewControllers that did appeared -- (NSArray *)allDidAppearViewControllers; - -// Current ViewController show in window -- (UIViewController *)currentViewController; +- (GrowingPage *)currentPage; +- (NSArray *)allDidAppearPages; -// Root ViewController in DidAppearControllers eg:UIWindow/Root/xxx/xxx/Current -- (UIViewController *)rootViewController; - -// Whether a vc is did appeared - (BOOL)isDidAppearController:(UIViewController *)vc; -- (GrowingPageGroup *)findPageByView:(UIView *)view; -- (GrowingPageGroup *)findPageByViewController:(UIViewController *)current; - -- (GrowingPageGroup *)currentPage; +- (void)autotrackPage:(UIViewController *)controller + alias:(NSString *)alias + attributes:(NSDictionary *_Nullable)attributes; +- (GrowingPage *)findPageByView:(UIView *)view; +- (GrowingPage *_Nullable)findAutotrackPageByPage:(GrowingPage *)page; @end + +NS_ASSUME_NONNULL_END diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.m b/GrowingAutotrackerCore/Page/GrowingPageManager.m index af52014ca..74e96ce00 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.m +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.m @@ -20,20 +20,17 @@ #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.h" -#import "GrowingAutotrackerCore/Page/GrowingPage.h" -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" +#import "GrowingTrackerCore/Utils/GrowingArgumentChecker.h" #import "GrowingULAppLifecycle.h" #import "GrowingULViewControllerLifecycle.h" @interface GrowingPageManager () -@property (nonatomic, strong) NSHashTable *visiableControllersTable; -@property (nonatomic, strong) NSPointerArray *visiableControllersArray; - +@property (nonatomic, strong) NSPointerArray *visiablePages; @property (nonatomic, strong) NSMutableArray *ignoredPrivateControllers; @end @@ -58,182 +55,169 @@ - (void)start { } - (void)viewControllerDidAppear:(UIViewController *)controller { - if (![self isPrivateViewControllerIgnored:controller]) { - [self createdViewControllerPage:controller]; - [self addDidAppearController:controller]; + if (![self isPrivateViewController:controller]) { + GrowingPage *page = [self createdViewControllerPage:controller]; + + if (!self.visiablePages) { + self.visiablePages = [NSPointerArray weakObjectsPointerArray]; + } + + if (![self.visiablePages.allObjects containsObject:page]) { + [self.visiablePages addPointer:(__bridge void *)page]; + } } } - (void)viewControllerDidDisappear:(UIViewController *)controller { - if (![self isPrivateViewControllerIgnored:controller]) { - [self removeDidDisappearController:controller]; + if (![self isPrivateViewController:controller]) { + [self.visiablePages.allObjects + enumerateObjectsWithOptions:NSEnumerationReverse + usingBlock:^(GrowingPage *page, NSUInteger idx, BOOL *_Nonnull stop) { + if (page.carrier == controller) { + [self.visiablePages removePointerAtIndex:idx]; + } + }]; } } -- (void)createdViewControllerPage:(UIViewController *)viewController { - GrowingPageGroup *page = [viewController growingPageObject]; - if (page == nil) { - page = [self createdPage:viewController]; +- (GrowingPage *)createdViewControllerPage:(UIViewController *)controller { + GrowingPage *page = [controller growingPageObject]; + if (!page) { + page = [self createdPage:controller]; } else { [page refreshShowTimestamp]; } - if (!page.isIgnored) { - // 发送page事件 + if (page.isAutotrack) { + // 发送PAGE事件 [self sendPageEventWithPage:page]; - } else { - GIOLogDebug(@"createdViewControllerPage: path = %@ is ignored", page.path); } + return page; } - (void)sendPageEventWithPage:(GrowingPage *)page { GrowingBaseBuilder *builder = GrowingPageEvent.builder.setTitle(page.title) - .setPath(page.path) + .setPath(page.alias) .setTimestamp(page.showTimestamp) - .setAttributes([page.carrier growingPageAttributes]); + .setAttributes(page.attributes); [[GrowingEventManager sharedInstance] postEventBuilder:builder]; } -- (void)addPageAlias:(GrowingPage *)page { - NSString *alias = [page.carrier growingPageAlias]; - if (![NSString growingHelper_isBlankString:alias]) { - page.alias = alias; - } -} - -- (GrowingPageGroup *)createdPage:(UIViewController *)viewController { - GrowingPageGroup *page = [GrowingPageGroup pageWithCarrier:viewController]; +- (GrowingPage *)createdPage:(UIViewController *)viewController { + GrowingPage *page = [GrowingPage pageWithCarrier:viewController]; page.parent = [self findParentPage:viewController]; if (page.parent != nil) { [page.parent addChildrenPage:page]; } - [self addPageAlias:page]; [viewController setGrowingPageObject:page]; return page; } -- (GrowingPageGroup *)findParentPage:(UIViewController *)carrier { - UIViewController *parentVC = nil; - - if ([carrier isKindOfClass:UIAlertController.class]) { - parentVC = [self currentViewController]; - } else { - parentVC = carrier.parentViewController; +- (GrowingPage *)findParentPage:(UIViewController *)carrier { + UIViewController *controller = (UIViewController *)carrier.growingNodeParent; + if (!controller) { + return nil; } - if (parentVC == nil) { - return nil; - } else { - GrowingPageGroup *page = [parentVC growingPageObject]; - if (page == nil) { - page = [self createdPage:parentVC]; - } - return page; + GrowingPage *page = [controller growingPageObject]; + if (!page) { + // 一般来说,page对象在viewDidAppear时就已创建 + // 此处兼容viewDidAppear未执行的特殊情况,比如: + // 用户未在自定义的ViewController viewDidAppear中调用super viewDidAppear + page = [self createdPage:controller]; } + return page; } #pragma mark Visiable ViewController -- (void)addDidAppearController:(UIViewController *)appearVc { - if ([self isPrivateViewControllerIgnored:appearVc]) { - return; - } - if (!self.visiableControllersTable) { - self.visiableControllersTable = [NSHashTable weakObjectsHashTable]; - } - - if (!self.visiableControllersArray) { - self.visiableControllersArray = [NSPointerArray weakObjectsPointerArray]; - } - - [self.visiableControllersTable addObject:appearVc]; - if (![self.visiableControllersArray.allObjects containsObject:appearVc]) { - [self.visiableControllersArray addPointer:(__bridge void *)appearVc]; - } +- (NSArray *)allDidAppearPages { + return self.visiablePages.allObjects; } -- (void)removeDidDisappearController:(UIViewController *)disappearVc { - if ([self isPrivateViewControllerIgnored:disappearVc]) { - return; +- (BOOL)isDidAppearController:(UIViewController *)vc { + for (GrowingPage *page in self.visiablePages) { + if (page.carrier == vc) { + return YES; + } } - [self.visiableControllersTable removeObject:disappearVc]; - [self.visiableControllersArray.allObjects - enumerateObjectsWithOptions:NSEnumerationReverse - usingBlock:^(UIViewController *vc, NSUInteger idx, BOOL *_Nonnull stop) { - if (disappearVc == vc) { - [self.visiableControllersArray removePointerAtIndex:idx]; - } - }]; + return NO; } -- (UIViewController *)currentViewController { - return self.allDidAppearViewControllers.lastObject; +- (BOOL)isPrivateViewController:(UIViewController *)viewController { + if (!viewController) { + return NO; + } + NSString *vcName = NSStringFromClass([viewController class]); + return [self.ignoredPrivateControllers containsObject:vcName]; } -- (UIViewController *)rootViewController { - UIViewController *vc = self.allDidAppearViewControllers.lastObject; - while (vc.parentViewController) { - vc = vc.parentViewController; +- (GrowingPage *)findPageByViewController:(UIViewController *)controller { + while ([self isPrivateViewController:controller]) { + controller = (UIViewController *)controller.growingNodeParent; } - return vc; -} -- (NSArray *)allDidAppearViewControllers { - return self.visiableControllersArray.allObjects; -} + if (!controller) { + return self.currentPage; + } -- (BOOL)isDidAppearController:(UIViewController *)vc { - return [self.visiableControllersTable containsObject:vc]; + GrowingPage *page = controller.growingPageObject; + if (!page) { + // 一般来说,page对象在viewDidAppear时就已创建 + // 此处兼容viewDidAppear未执行的特殊情况,比如: + // 用户未在自定义的ViewController viewDidAppear中调用super viewDidAppear + page = [self createdPage:controller]; + } + return page; } -- (BOOL)isPrivateViewControllerIgnored:(UIViewController *)viewController { - if (viewController == nil) { - return NO; +- (void)autotrackPage:(UIViewController *)controller + alias:(NSString *)alias + attributes:(NSDictionary *_Nullable)attributes { + if (controller == nil) { + return; } - NSString *vcName = NSStringFromClass([viewController class]); - if (self.ignoredPrivateControllers.count > 0 && [self.ignoredPrivateControllers containsObject:vcName]) { - return YES; + if ([NSString growingHelper_isBlankString:alias]) { + return; + } + if (attributes != nil && [GrowingArgumentChecker isIllegalAttributes:attributes]) { + return; } - return NO; -} -- (GrowingPageGroup *)findPageByViewController:(UIViewController *)current { - GrowingPageGroup *page = nil; - UIViewController *last = nil; - while (current) { - last = current; - if ([[GrowingPageManager sharedInstance] isPrivateViewControllerIgnored:current]) { - current = (UIViewController *)current.growingNodeParent; - } else { - page = [current growingPageObject]; - if (page == nil) { - page = [self createdPage:current]; - } - if (page.isIgnored) { - current = (UIViewController *)current.growingNodeParent; - } else { - break; - } - } + BOOL needAutotrackPage = NO; + GrowingPage *page = controller.growingPageObject; + if (page && !page.isAutotrack) { + // 当前页面已经进入viewDidAppear,但未发送过PAGE事件,需要补发 + needAutotrackPage = YES; } - if (!page && last) { - page = [last growingPageObject]; + + controller.growingPageAlias = alias; + controller.growingPageAttributes = attributes; + if (needAutotrackPage) { + [self sendPageEventWithPage:page]; } - return page; } -- (GrowingPageGroup *)findPageByView:(UIView *)view { +- (GrowingPage *)findPageByView:(UIView *)view { UIViewController *current = [view growingHelper_viewController]; if (!current) { - current = self.currentViewController; + return self.currentPage; } return [self findPageByViewController:current]; } -- (GrowingPageGroup *)currentPage { - UIViewController *parent = [self currentViewController]; - GrowingPageGroup *page = [parent growingPageObject]; - return page; +- (GrowingPage *)findAutotrackPageByPage:(GrowingPage *)page { + while (page) { + if (page.isAutotrack) { + return page; + } + page = page.parent; + } + return nil; +} + +- (GrowingPage *)currentPage { + return self.visiablePages.allObjects.lastObject; } #pragma mark Lazy Load diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h index f678bc333..44d6d7c94 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h @@ -17,8 +17,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "GrowingTrackerCore/Event/GrowingBaseAttributesEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" +#import "GrowingTrackerCore/Event/GrowingBaseAttributesEvent.h" // 泛型类型,可以生成多个类型event,故可以设置eventType @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *path; @property (nonatomic, copy, readonly) NSString *textValue; @property (nonatomic, copy, readonly) NSString *xpath; +@property (nonatomic, copy, readonly) NSString *xindex; @property (nonatomic, assign, readonly) int index; + (GrowingViewElementBuilder *)builder; @@ -42,13 +43,15 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *pageName; @property (nonatomic, copy, readonly) NSString *textValue; @property (nonatomic, copy, readonly) NSString *xpath; +@property (nonatomic, copy, readonly) NSString *xindex; @property (nonatomic, assign, readonly) int index; - (GrowingViewElementBuilder * (^)(NSString *value))setPath; - (GrowingViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingViewElementBuilder * (^)(NSString *value))setXpath; +- (GrowingViewElementBuilder * (^)(NSString *value))setXindex; - (GrowingViewElementBuilder * (^)(int value))setIndex; -- (GrowingViewElementBuilder *(^)(NSDictionary *value))setAttributes; +- (GrowingViewElementBuilder * (^)(NSDictionary *value))setAttributes; // extra add // 覆盖返回值类型为GrowingViewElementBuilder diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m index 31f2cefb6..4e73d1526 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m @@ -31,6 +31,7 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { _path = subBuilder.pageName; _textValue = subBuilder.textValue; _xpath = subBuilder.xpath; + _xindex = subBuilder.xindex; _index = subBuilder.index; } return self; @@ -41,6 +42,7 @@ - (NSDictionary *)toDictionary { dataDictM[@"path"] = self.path; dataDictM[@"textValue"] = self.textValue; dataDictM[@"xpath"] = self.xpath; + dataDictM[@"xindex"] = self.xindex; dataDictM[@"index"] = self.index >= 0 ? @(self.index) : nil; return dataDictM; } @@ -72,6 +74,13 @@ @implementation GrowingViewElementBuilder }; } +- (GrowingViewElementBuilder * (^)(NSString *value))setXindex { + return ^(NSString *value) { + self->_xindex = value; + return self; + }; +} + - (GrowingViewElementBuilder * (^)(int value))setIndex { return ^(int value) { self->_index = value; diff --git a/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m b/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m index aeece9d3e..18d724ee1 100644 --- a/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m +++ b/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m @@ -41,7 +41,6 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { _domain = builder.domain; _urlScheme = builder.urlScheme; _appState = builder.appState; - _globalSequenceId = builder.globalSequenceId; _eventSequenceId = builder.eventSequenceId; _platform = builder.platform; _platformVersion = builder.platformVersion; @@ -59,7 +58,6 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { _longitude = builder.longitude; _sdkVersion = builder.sdkVersion; _userKey = builder.userKey; - _gioId = builder.gioId; } return self; } @@ -86,7 +84,6 @@ - (NSDictionary *)toDictionary { dataDict[@"deviceId"] = self.deviceId; dataDict[@"platform"] = self.platform; dataDict[@"platformVersion"] = self.platformVersion; - dataDict[@"globalSequenceId"] = @(self.globalSequenceId); dataDict[@"eventSequenceId"] = @(self.eventSequenceId); dataDict[@"appState"] = (self.appState == GrowingAppStateForeground) ? @"FOREGROUND" : @"BACKGROUND"; dataDict[@"urlScheme"] = self.urlScheme; @@ -103,7 +100,6 @@ - (NSDictionary *)toDictionary { dataDict[@"longitude"] = ABS(self.longitude) > 0 ? @(self.longitude) : nil; dataDict[@"sdkVersion"] = self.sdkVersion; dataDict[@"userKey"] = self.userKey.length > 0 ? self.userKey : nil; - dataDict[@"gioId"] = self.gioId.length > 0 ? self.gioId : nil; return [dataDict copy]; } @@ -115,7 +111,7 @@ + (GrowingBaseBuilder *_Nonnull)builder { @implementation GrowingBaseBuilder -// 赋值属性,eg:deviceId,userId,sessionId,globalSequenceId,eventSequenceId +// 赋值属性,eg:deviceId,userId,sessionId,eventSequenceId - (void)readPropertyInTrackThread { GrowingTrackConfiguration *config = GrowingConfigurationManager.sharedInstance.trackConfiguration; _dataSourceId = config.dataSourceId; @@ -130,15 +126,13 @@ - (void)readPropertyInTrackThread { GrowingEventSequenceObject *sequence = [[GrowingPersistenceDataProvider sharedInstance] getAndIncrement:self.eventType]; - _globalSequenceId = sequence.globalId; - _eventSequenceId = sequence.eventTypeId; + _eventSequenceId = sequence.sequenceId; GrowingSession *session = [GrowingSession currentSession]; _userId = session.loginUserId; _sessionId = session.sessionId; _latitude = session.latitude; _longitude = session.longitude; _userKey = session.loginUserKey; - _gioId = session.latestNonNullUserId; _timestamp = _timestamp > 0 ? _timestamp : [GrowingULTimeUtil currentTimeMillis]; _screenWidth = [GrowingFieldsIgnore isIgnoreFields:@"screenWidth"] ? 0 : deviceInfo.screenWidth; @@ -211,13 +205,6 @@ - (void)readPropertyInTrackThread { }; } -- (GrowingBaseBuilder * (^)(long long value))setGlobalSequenceId { - return ^(long long value) { - self->_globalSequenceId = value; - return self; - }; -} - - (GrowingBaseBuilder * (^)(long long value))setEventSequenceId { return ^(long long value) { self->_eventSequenceId = value; @@ -344,13 +331,6 @@ - (void)readPropertyInTrackThread { }; } -- (GrowingBaseBuilder * (^)(NSString *value))setGioId { - return ^(NSString *value) { - self->_gioId = value; - return self; - }; -} - - (GrowingBaseEvent *)build { @throw [NSException exceptionWithName:NSInternalInconsistencyException diff --git a/GrowingTrackerCore/Event/GrowingEventFilter.m b/GrowingTrackerCore/Event/GrowingEventFilter.m index 97629d8fb..bbbe7d5e0 100644 --- a/GrowingTrackerCore/Event/GrowingEventFilter.m +++ b/GrowingTrackerCore/Event/GrowingEventFilter.m @@ -20,8 +20,7 @@ #import "GrowingTrackerCore/Public/GrowingEventFilter.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -NSUInteger const GrowingFilterClickChange = - (GrowingFilterEventViewClick | GrowingFilterEventViewChange); +NSUInteger const GrowingFilterClickChange = (GrowingFilterEventViewClick | GrowingFilterEventViewChange); @implementation GrowingEventFilter diff --git a/GrowingTrackerCore/Event/GrowingNodeProtocol.h b/GrowingTrackerCore/Event/GrowingNodeProtocol.h index 716f14f06..24821f66b 100644 --- a/GrowingTrackerCore/Event/GrowingNodeProtocol.h +++ b/GrowingTrackerCore/Event/GrowingNodeProtocol.h @@ -27,9 +27,11 @@ @property (nonatomic, assign, readonly) NSInteger growingNodeKeyIndex; /// 完整的xpath由各个node的subPath拼接而成 @property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubPath; +/// 完整的xindex由各个node的subIndex拼接而成 +@property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubIndex; /// 当同一视图下相同class的两个node点击行为相似 /// 当不需要区分点击哪一个node,仅需要区分点击那种类型时,使用该属性 -@property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubSimilarPath; +@property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubSimilarIndex; /// 原始父节点 - (id _Nullable)growingNodeParent; /// 过滤后的子节点,例如UITableView子节点只需要是cell和footter diff --git a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h index 4bb729fa5..363483bc6 100644 --- a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h +++ b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h @@ -47,10 +47,8 @@ NS_ASSUME_NONNULL_BEGIN @end @interface GrowingEventSequenceObject : NSObject -// 全局 序列id -@property (nonatomic, assign) long long globalId; -// 事件类型 序列id -@property (nonatomic, assign) long long eventTypeId; + +@property (nonatomic, assign) long long sequenceId; @end diff --git a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m index 7517adc9d..63daa633b 100644 --- a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m +++ b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m @@ -23,7 +23,7 @@ static NSString *kGrowingUserdefault_file = @"growingio.userdefault"; static NSString *kGrowingUserdefault_loginUserId = @"growingio.userdefault.loginUserId"; static NSString *kGrowingUserdefault_loginUserKey = @"growingio.userdefault.loginUserKey"; -static NSString *kGrowingUserdefault_globalId = @"growingio.userdefault.globalId"; +static NSString *kGrowingUserdefault_sequenceId = @"growingio.userdefault.sequenceId"; static NSString *kGrowingUserdefault_prefix = @"growingio.userdefault"; @interface GrowingPersistenceDataProvider () @@ -94,12 +94,15 @@ - (NSString *)getStringforKey:(NSString *)key; { return [_growingUserdefault valueForKey:key]; } - (GrowingEventSequenceObject *)getAndIncrement:(NSString *)eventType { - long long globalId = [self increaseFor:kGrowingUserdefault_globalId spanValue:1]; - long long eventTypeId = - [self increaseFor:[NSString stringWithFormat:@"%@.%@", kGrowingUserdefault_prefix, eventType] spanValue:1]; + int increase = 0; + if ([eventType isEqualToString:@"VISIT"] || [eventType isEqualToString:@"PAGE"] || + [eventType isEqualToString:@"VIEW_CLICK"] || [eventType isEqualToString:@"VIEW_CHANGE"] || + [eventType isEqualToString:@"CUSTOM"]) { + increase = 1; + } + long long sequenceId = [self increaseFor:kGrowingUserdefault_sequenceId spanValue:increase]; GrowingEventSequenceObject *obj = [[GrowingEventSequenceObject alloc] init]; - obj.globalId = globalId; - obj.eventTypeId = eventTypeId; + obj.sequenceId = sequenceId; return obj; } diff --git a/GrowingTrackerCore/GrowingRealTracker.m b/GrowingTrackerCore/GrowingRealTracker.m index a4340ef9d..29ee3f81a 100644 --- a/GrowingTrackerCore/GrowingRealTracker.m +++ b/GrowingTrackerCore/GrowingRealTracker.m @@ -265,6 +265,7 @@ - (void)setDataCollectionEnabled:(BOOL)enabled { } trackConfiguration.dataCollectionEnabled = enabled; if (enabled) { + [[GrowingSession currentSession] refreshSessionId]; [[GrowingSession currentSession] generateVisit]; } else { [GrowingEventTimer clearAllTimers]; diff --git a/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m b/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m index 8cd1e57bc..c9f4089aa 100644 --- a/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m +++ b/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m @@ -18,9 +18,7 @@ // limitations under the License. #import -#import "GrowingTrackerCore/Helpers/Foundation/NSData+GrowingHelper.h" -#import "GrowingTrackerCore/Helpers/Foundation/NSDictionary+GrowingHelper.h" -#import "GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.h" +#import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" diff --git a/GrowingTrackerCore/Manager/GrowingSession.h b/GrowingTrackerCore/Manager/GrowingSession.h index a4cf87f49..4bed6b298 100644 --- a/GrowingTrackerCore/Manager/GrowingSession.h +++ b/GrowingTrackerCore/Manager/GrowingSession.h @@ -47,6 +47,8 @@ typedef NS_ENUM(NSInteger, GrowingSessionState) { + (instancetype)currentSession; +- (void)refreshSessionId; + - (void)generateVisit; - (void)addUserIdChangedDelegate:(id)delegate; diff --git a/GrowingTrackerCore/Manager/GrowingSession.m b/GrowingTrackerCore/Manager/GrowingSession.m index 048650399..a86f361a5 100644 --- a/GrowingTrackerCore/Manager/GrowingSession.m +++ b/GrowingTrackerCore/Manager/GrowingSession.m @@ -218,9 +218,8 @@ - (void)resendVisitByUserIdDidChangedFrom:(NSString *)oldUserId to:(NSString *)n if (![NSString growingHelper_isBlankString:newUserId]) { NSString *latestNonNullUserId = self.latestNonNullUserId.copy; self.latestNonNullUserId = newUserId; - if ([NSString growingHelper_isBlankString:latestNonNullUserId]) { - [self generateVisit]; - } else if (![newUserId isEqualToString:latestNonNullUserId]) { + if (![NSString growingHelper_isBlankString:latestNonNullUserId] && + ![newUserId isEqualToString:latestNonNullUserId]) { [self refreshSessionId]; [self generateVisit]; } @@ -228,13 +227,6 @@ - (void)resendVisitByUserIdDidChangedFrom:(NSString *)oldUserId to:(NSString *)n } - (void)setLocation:(double)latitude longitude:(double)longitude { - // 经纬度从无到有会发visit - if ((_latitude == 0 && (ABS(latitude) > 0)) || (_longitude == 0 && ABS(longitude) > 0)) { - _latitude = latitude; - _longitude = longitude; - [self generateVisit]; - return; - } _latitude = latitude; _longitude = longitude; } diff --git a/GrowingTrackerCore/Public/GrowingBaseEvent.h b/GrowingTrackerCore/Public/GrowingBaseEvent.h index b4f8d59e9..89d440a33 100644 --- a/GrowingTrackerCore/Public/GrowingBaseEvent.h +++ b/GrowingTrackerCore/Public/GrowingBaseEvent.h @@ -40,7 +40,6 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) { @property (nonatomic, copy, readonly) NSString *_Nonnull domain; @property (nonatomic, copy, readonly) NSString *_Nonnull urlScheme; @property (nonatomic, assign, readonly) int appState; -@property (nonatomic, assign, readonly) long long globalSequenceId; @property (nonatomic, assign, readonly) long long eventSequenceId; @property (nonatomic, copy, readonly) NSString *_Nonnull platform; @property (nonatomic, copy, readonly) NSString *_Nonnull platformVersion; @@ -59,7 +58,6 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) { @property (nonatomic, assign, readonly) double longitude; @property (nonatomic, copy, readonly) NSString *_Nonnull sdkVersion; @property (nonatomic, copy, readonly) NSString *_Nullable userKey; -@property (nonatomic, copy, readonly) NSString *_Nullable gioId; @property (nonatomic, assign) GrowingEventSendPolicy sendPolicy; - (NSDictionary *_Nonnull)toDictionary; @@ -84,7 +82,6 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) { @property (nonatomic, copy, readonly) NSString *_Nonnull domain; @property (nonatomic, copy, readonly) NSString *_Nonnull urlScheme; @property (nonatomic, assign, readonly) int appState; -@property (nonatomic, assign, readonly) long long globalSequenceId; @property (nonatomic, assign, readonly) long long eventSequenceId; @property (nonatomic, copy, readonly) NSString *_Nonnull platform; @property (nonatomic, copy, readonly) NSString *_Nonnull platformVersion; @@ -103,11 +100,10 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) { @property (nonatomic, assign, readonly) double longitude; @property (nonatomic, copy, readonly) NSString *_Nonnull sdkVersion; @property (nonatomic, copy, readonly) NSString *_Nullable userKey; -@property (nonatomic, copy, readonly) NSString *_Nullable gioId; NS_ASSUME_NONNULL_BEGIN -// 赋值属性,eg:deviceId,userId,sessionId,globalSequenceId,eventSequenceId +// 赋值属性,eg:deviceId,userId,sessionId,eventSequenceId - (void)readPropertyInTrackThread; - (GrowingBaseBuilder * (^)(NSString *value))setDataSourceId; @@ -118,7 +114,6 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingBaseBuilder * (^)(NSString *value))setDomain; - (GrowingBaseBuilder * (^)(NSString *value))setUrlScheme; - (GrowingBaseBuilder * (^)(int value))setAppState; -- (GrowingBaseBuilder * (^)(long long value))setGlobalSequenceId; - (GrowingBaseBuilder * (^)(long long value))setEventSequenceId; - (GrowingBaseBuilder * (^)(NSString *value))setPlatform; - (GrowingBaseBuilder * (^)(NSString *value))setPlatformVersion; @@ -136,7 +131,6 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingBaseBuilder * (^)(double value))setLongitude; - (GrowingBaseBuilder * (^)(NSString *value))setSdkVersion; - (GrowingBaseBuilder * (^)(NSString *value))setUserKey; -- (GrowingBaseBuilder * (^)(NSString *value))setGioId; - (GrowingBaseBuilder * (^)(NSString *value))setEventType; - (GrowingBaseEvent *)build; diff --git a/Modules/Flutter/GrowingFlutterPlugin.m b/Modules/Flutter/GrowingFlutterPlugin.m index fea19febe..b032dcc84 100644 --- a/Modules/Flutter/GrowingFlutterPlugin.m +++ b/Modules/Flutter/GrowingFlutterPlugin.m @@ -89,14 +89,9 @@ - (void)trackViewElementEvent:(NSDictionary *)arguments { if (!path || ![path isKindOfClass:[NSString class]] || path.length == 0) { return; } - NSNumber *ptm = arguments[@"pageShowTimestamp"]; - if (!ptm || ![ptm isKindOfClass:[NSNumber class]]) { - return; - } GrowingViewElementBuilder *builder = - GrowingViewElementEvent.builder.setEventType(eventType).setXpath(xpath).setPath(path).setPageShowTimestamp( - ptm.longLongValue); + GrowingViewElementEvent.builder.setEventType(eventType).setXpath(xpath).setPath(path); NSString *viewContent = arguments[@"textValue"]; if (viewContent && [viewContent isKindOfClass:[NSString class]] && viewContent.length > 0) { builder = builder.setTextValue(viewContent); diff --git a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h index d6dd0b910..11b034337 100644 --- a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h +++ b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h @@ -25,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingHybridViewElementEvent : GrowingViewElementEvent +@property (nonatomic, copy, readonly) NSString *xcontent; @property (nonatomic, copy, readonly) NSString *hyperlink; @property (nonatomic, copy, readonly) NSString *query; @@ -34,9 +35,11 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingHybridViewElementBuilder : GrowingViewElementBuilder +@property (nonatomic, copy, readonly) NSString *xcontent; @property (nonatomic, copy, readonly) NSString *hyperlink; @property (nonatomic, copy, readonly) NSString *query; +- (GrowingHybridViewElementBuilder * (^)(NSString *value))setXcontent; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setQuery; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setHyperlink; @@ -45,8 +48,8 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingHybridViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setXpath; - (GrowingHybridViewElementBuilder * (^)(int value))setIndex; -- (GrowingHybridViewElementBuilder *(^)(NSString *value))setDomain; -- (GrowingHybridViewElementBuilder *(^)(NSDictionary *value))setAttributes; +- (GrowingHybridViewElementBuilder * (^)(NSString *value))setDomain; +- (GrowingHybridViewElementBuilder * (^)(NSDictionary *value))setAttributes; // extra add - (GrowingHybridViewElementBuilder * (^)(NSString *value))setEventType; diff --git a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m index 425eb2778..618521c14 100644 --- a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m +++ b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m @@ -24,6 +24,7 @@ @implementation GrowingHybridViewElementEvent - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { if (self = [super initWithBuilder:builder]) { GrowingHybridViewElementBuilder *subBuilder = (GrowingHybridViewElementBuilder *)builder; + _xcontent = subBuilder.xcontent; _query = subBuilder.query; _hyperlink = subBuilder.hyperlink; } @@ -36,6 +37,7 @@ + (GrowingHybridViewElementBuilder *)builder { - (NSDictionary *)toDictionary { NSMutableDictionary *dataDictM = [NSMutableDictionary dictionaryWithDictionary:[super toDictionary]]; + dataDictM[@"xcontent"] = self.xcontent; dataDictM[@"query"] = self.query; dataDictM[@"hyperlink"] = self.hyperlink; return dataDictM; @@ -48,6 +50,13 @@ - (NSDictionary *)toDictionary { @implementation GrowingHybridViewElementBuilder +- (GrowingHybridViewElementBuilder * (^)(NSString *value))setXcontent { + return ^(NSString *value) { + self->_xcontent = value; + return self; + }; +} + - (GrowingHybridViewElementBuilder * (^)(NSString *value))setQuery { return ^(NSString *value) { self->_query = value; diff --git a/Modules/Hybrid/GrowingHybridBridgeProvider.m b/Modules/Hybrid/GrowingHybridBridgeProvider.m index 11ef3982c..81c3bd948 100644 --- a/Modules/Hybrid/GrowingHybridBridgeProvider.m +++ b/Modules/Hybrid/GrowingHybridBridgeProvider.m @@ -61,6 +61,7 @@ #define KEY_INDEX "index" #define KEY_TEXT_VALUE "textValue" #define KEY_XPATH "xpath" +#define KEY_XCONTENT "xcontent" @interface UIView (GrowingNode) @end @@ -250,9 +251,10 @@ - (GrowingBaseBuilder *)transformViewElementBuilder:(NSDictionary *)dict { .setIndex([dict growingHelper_intForKey:@KEY_INDEX fallback:-1]) .setTextValue(dict[@KEY_TEXT_VALUE]) .setXpath(dict[@KEY_XPATH]) + .setXcontent(dict[@KEY_XCONTENT]) .setPath(dict[@KEY_PATH]) .setDomain([self getDomain:dict]) - .setAttributes([self safeAttributesFromDict:dict]);; + .setAttributes([self safeAttributesFromDict:dict]); } @end diff --git a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index 4658d3198..a2237b1d7 100644 --- a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -35,7 +35,6 @@ - (GrowingPBEventV3Dto *)toProtobuf { dto.deviceId = self.deviceId; dto.platform = self.platform; dto.platformVersion = self.platformVersion; - dto.globalSequenceId = self.globalSequenceId; dto.eventSequenceId = (int)self.eventSequenceId; dto.appState = (self.appState == GrowingAppStateForeground) ? @"FOREGROUND" : @"BACKGROUND"; dto.URLScheme = self.urlScheme; @@ -52,7 +51,6 @@ - (GrowingPBEventV3Dto *)toProtobuf { dto.longitude = self.longitude; dto.sdkVersion = self.sdkVersion; dto.userKey = self.userKey; - dto.gioId = self.gioId; __weak typeof(self) weakSelf = self; NSString * (^stringBlock)(NSString *) = ^(NSString *selectorString) { @@ -74,16 +72,6 @@ - (GrowingPBEventV3Dto *)toProtobuf { return 0; }; - int64_t (^int64Block)(NSString *) = ^(NSString *selectorString) { - __strong typeof(weakSelf) self = weakSelf; - SEL selector = NSSelectorFromString(selectorString); - if ([self respondsToSelector:selector]) { - int64_t result = ((int64_t(*)(id, SEL))objc_msgSend)(self, selector); - return result > 0 ? result : (int64_t)0; - } - return (int64_t)0; - }; - NSDictionary * (^dicBlock)(NSString *) = ^(NSString *selectorString) { __strong typeof(weakSelf) self = weakSelf; SEL selector = NSSelectorFromString(selectorString); diff --git a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index 2420531a9..aa88ca9ca 100644 --- a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -32,9 +32,6 @@ - (id)growingHelper_jsonObject { if (self.userId.length > 0) { [dic setObject:self.userId forKey:@"userId"]; } - if (self.gioId.length > 0) { - [dic setObject:self.gioId forKey:@"gioId"]; - } if (self.sessionId.length > 0) { [dic setObject:self.sessionId forKey:@"sessionId"]; } @@ -99,9 +96,6 @@ - (id)growingHelper_jsonObject { if (self.referralPage.length > 0) { [dic setObject:self.referralPage forKey:@"referralPage"]; } - if (self.globalSequenceId > 0) { - [dic setObject:@(self.globalSequenceId) forKey:@"globalSequenceId"]; - } if (self.eventSequenceId > 0) { [dic setObject:@(self.eventSequenceId) forKey:@"eventSequenceId"]; } diff --git a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h index 39d8c86cb..99d92b42a 100644 --- a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h +++ b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h @@ -83,7 +83,6 @@ GPB_FINAL @interface GrowingPBEventV3Root : GPBRootObject typedef GPB_ENUM(GrowingPBEventV3Dto_FieldNumber) { GrowingPBEventV3Dto_FieldNumber_DeviceId = 1, GrowingPBEventV3Dto_FieldNumber_UserId = 2, - GrowingPBEventV3Dto_FieldNumber_GioId = 3, GrowingPBEventV3Dto_FieldNumber_SessionId = 4, GrowingPBEventV3Dto_FieldNumber_DataSourceId = 5, GrowingPBEventV3Dto_FieldNumber_EventType = 6, @@ -94,7 +93,6 @@ typedef GPB_ENUM(GrowingPBEventV3Dto_FieldNumber) { GrowingPBEventV3Dto_FieldNumber_Query = 11, GrowingPBEventV3Dto_FieldNumber_Title = 12, GrowingPBEventV3Dto_FieldNumber_ReferralPage = 13, - GrowingPBEventV3Dto_FieldNumber_GlobalSequenceId = 14, GrowingPBEventV3Dto_FieldNumber_EventSequenceId = 15, GrowingPBEventV3Dto_FieldNumber_ScreenHeight = 16, GrowingPBEventV3Dto_FieldNumber_ScreenWidth = 17, @@ -103,7 +101,6 @@ typedef GPB_ENUM(GrowingPBEventV3Dto_FieldNumber) { GrowingPBEventV3Dto_FieldNumber_AppVersion = 20, GrowingPBEventV3Dto_FieldNumber_ExtraSdk = 21, GrowingPBEventV3Dto_FieldNumber_EventName = 22, - GrowingPBEventV3Dto_FieldNumber_PageShowTimestamp = 23, GrowingPBEventV3Dto_FieldNumber_Attributes = 24, GrowingPBEventV3Dto_FieldNumber_ResourceItem = 25, GrowingPBEventV3Dto_FieldNumber_ProtocolType = 26, @@ -142,8 +139,6 @@ GPB_FINAL @interface GrowingPBEventV3Dto : GPBMessage @property (nonatomic, readwrite, copy, null_resettable) NSString *userId; -@property (nonatomic, readwrite, copy, null_resettable) NSString *gioId; - @property (nonatomic, readwrite, copy, null_resettable) NSString *sessionId; @property (nonatomic, readwrite, copy, null_resettable) NSString *dataSourceId; @@ -168,8 +163,6 @@ GPB_FINAL @interface GrowingPBEventV3Dto : GPBMessage /** PageEvent */ @property (nonatomic, readwrite, copy, null_resettable) NSString *referralPage; -@property (nonatomic, readwrite) int64_t globalSequenceId; - @property (nonatomic, readwrite) int32_t eventSequenceId; @property (nonatomic, readwrite) int32_t screenHeight; @@ -190,9 +183,6 @@ GPB_FINAL @interface GrowingPBEventV3Dto : GPBMessage /** customEvent */ @property (nonatomic, readwrite, copy, null_resettable) NSString *eventName; -/** PageAttributesEvent */ -@property (nonatomic, readwrite) int64_t pageShowTimestamp; - /** BaseAttributesEvent */ @property (nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *attributes; /** The number of items in @c attributes without causing the array to be created. */ diff --git a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m index 3bd113c98..adddca017 100644 --- a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m +++ b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m @@ -117,7 +117,6 @@ @implementation GrowingPBEventV3Dto @dynamic deviceId; @dynamic userId; -@dynamic gioId; @dynamic sessionId; @dynamic dataSourceId; @dynamic eventType; @@ -128,7 +127,6 @@ @implementation GrowingPBEventV3Dto @dynamic query; @dynamic title; @dynamic referralPage; -@dynamic globalSequenceId; @dynamic eventSequenceId; @dynamic screenHeight; @dynamic screenWidth; @@ -137,7 +135,6 @@ @implementation GrowingPBEventV3Dto @dynamic appVersion; @dynamic extraSdk, extraSdk_Count; @dynamic eventName; -@dynamic pageShowTimestamp; @dynamic attributes, attributes_Count; @dynamic hasResourceItem, resourceItem; @dynamic protocolType; @@ -178,7 +175,6 @@ @implementation GrowingPBEventV3Dto int32_t index; NSString *deviceId; NSString *userId; - NSString *gioId; NSString *sessionId; NSString *dataSourceId; NSString *platform; @@ -219,8 +215,6 @@ @implementation GrowingPBEventV3Dto NSString *projectKey; NSString *userKey; int64_t timestamp; - int64_t globalSequenceId; - int64_t pageShowTimestamp; double latitude; double longitude; int64_t sendTime; @@ -250,15 +244,6 @@ + (GPBDescriptor *)descriptor { .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, }, - { - .name = "gioId", - .dataTypeSpecific.clazz = Nil, - .number = GrowingPBEventV3Dto_FieldNumber_GioId, - .hasIndex = 2, - .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, gioId), - .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), - .dataType = GPBDataTypeString, - }, { .name = "sessionId", .dataTypeSpecific.clazz = Nil, @@ -349,15 +334,6 @@ + (GPBDescriptor *)descriptor { .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, }, - { - .name = "globalSequenceId", - .dataTypeSpecific.clazz = Nil, - .number = GrowingPBEventV3Dto_FieldNumber_GlobalSequenceId, - .hasIndex = 13, - .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, globalSequenceId), - .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), - .dataType = GPBDataTypeInt64, - }, { .name = "eventSequenceId", .dataTypeSpecific.clazz = Nil, @@ -430,15 +406,6 @@ + (GPBDescriptor *)descriptor { .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, }, - { - .name = "pageShowTimestamp", - .dataTypeSpecific.clazz = Nil, - .number = GrowingPBEventV3Dto_FieldNumber_PageShowTimestamp, - .hasIndex = 21, - .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, pageShowTimestamp), - .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), - .dataType = GPBDataTypeInt64, - }, { .name = "attributes", .dataTypeSpecific.clazz = Nil, diff --git a/Modules/SwiftProtobuf/SwiftProtobuf.swift b/Modules/SwiftProtobuf/SwiftProtobuf.swift index f6288b771..8a3f6ed6b 100644 --- a/Modules/SwiftProtobuf/SwiftProtobuf.swift +++ b/Modules/SwiftProtobuf/SwiftProtobuf.swift @@ -96,7 +96,6 @@ extension GrowingBaseEvent { var dto = EventV3Dto() dto.dataSourceID = self.dataSourceId ?? "" - dto.gioID = self.gioId ?? "" dto.sessionID = self.sessionId ?? "" dto.timestamp = self.timestamp dto.domain = self.domain @@ -104,7 +103,6 @@ extension GrowingBaseEvent { dto.deviceID = self.deviceId dto.platform = self.platform dto.platformVersion = self.platformVersion - dto.globalSequenceID = self.globalSequenceId dto.eventSequenceID = Int32(self.eventSequenceId) dto.appState = self.appState == GrowingAppState.foreground.rawValue ? "FOREGROUND" : "BACKGROUND" dto.urlScheme = self.urlScheme diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index f416298b5..5ad6954ba 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -25,7 +25,6 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" -#import "GrowingAutotrackerCore/Page/GrowingPageGroup.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingTrackerCore/DeepLink/GrowingDeepLinkHandler.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" @@ -126,13 +125,12 @@ - (void)_setNeedUpdateScreen { "left": 0, "top": 0, "width": 720, - "height": 1520, - "isIgnored": true + "height": 1520 } */ -- (NSMutableDictionary *)dictFromPage:(id)aNode xPath:(NSString *)xPath { +- (NSMutableDictionary *)dictFromPage:(GrowingPage *)page { NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; - CGRect frame = [aNode growingNodeFrame]; + CGRect frame = [page.carrier growingNodeFrame]; if (!CGRectEqualToRect(frame, CGRectZero)) { CGFloat scale = MIN([UIScreen mainScreen].scale, 2); dict[@"left"] = [NSNumber numberWithInt:(int)(frame.origin.x * scale)]; @@ -140,14 +138,8 @@ - (NSMutableDictionary *)dictFromPage:(id)aNode xPath:(NSString *)x dict[@"width"] = [NSNumber numberWithInt:(int)(frame.size.width * scale)]; dict[@"height"] = [NSNumber numberWithInt:(int)(frame.size.height * scale)]; } - dict[@"path"] = xPath; - - UIViewController *vc = (UIViewController *)aNode; - if (vc.title) { - dict[@"title"] = vc.title; - } - - dict[@"isIgnored"] = @([vc growingPageDidIgnore]); + dict[@"path"] = page.alias; + dict[@"title"] = page.title; return dict; } @@ -161,10 +153,11 @@ - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node { .setContent(node.viewContent) .setZLevel(self.zLevel++) .setIndex(node.index) - .setXpath(node.xPath) - .setParentXPath(node.clickableParentXPath) + .setXpath(node.xpath) + .setXindex(node.xindex) + .setParentXpath(node.clickableParentXpath) .setNodeType(node.nodeType) - .setPage(page.path) + .setPage(page.alias) .build; return [NSMutableDictionary dictionaryWithDictionary:element.toDictionary]; @@ -264,8 +257,9 @@ - (void)fillAllViewsForWebCircle:(NSDictionary *)dataDict completion:(void (^)(N [self traverseViewNode:GrowingViewNode.builder.setView(topwindow) .setIndex(-1) .setViewContent([GrowingNodeHelper buildElementContentForNode:topwindow]) - .setXPath([GrowingNodeHelper xPathForView:topwindow similar:NO]) - .setOriginXPath([GrowingNodeHelper xPathForView:topwindow similar:NO]) + .setXpath(topwindow.growingNodeSubPath) + .setXindex(topwindow.growingNodeSubIndex) + .setOriginXindex(topwindow.growingNodeSubSimilarIndex) .setNodeType([GrowingNodeHelper getViewNodeType:topwindow]) .build]; if (self.isPageDontShow) { @@ -275,12 +269,13 @@ - (void)fillAllViewsForWebCircle:(NSDictionary *)dataDict completion:(void (^)(N } NSMutableArray *pages = [NSMutableArray array]; - NSArray *vcs = [[GrowingPageManager sharedInstance] allDidAppearViewControllers]; - for (int i = 0; i < vcs.count; i++) { - UIViewController *tmp = vcs[i]; - GrowingPage *page = [[GrowingPageManager sharedInstance] findPageByViewController:tmp]; - NSMutableDictionary *dict = [self dictFromPage:tmp xPath:page.path]; - [pages addObject:dict]; + NSArray *allDidAppearPages = [[GrowingPageManager sharedInstance] allDidAppearPages]; + for (int i = 0; i < allDidAppearPages.count; i++) { + GrowingPage *page = allDidAppearPages[i]; + if (page.isAutotrack) { + NSMutableDictionary *dict = [self dictFromPage:page]; + [pages addObject:dict]; + } } NSDictionary *flutterData = self.flutterCircleData; diff --git a/Modules/WebCircle/GrowingWebCircleElement.h b/Modules/WebCircle/GrowingWebCircleElement.h index 87ff0e1de..87b79793b 100644 --- a/Modules/WebCircle/GrowingWebCircleElement.h +++ b/Modules/WebCircle/GrowingWebCircleElement.h @@ -27,8 +27,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) int zLevel; @property (nonatomic, copy, readonly) NSString *_Nullable content; @property (nonatomic, copy, readonly) NSString *_Nonnull xpath; +@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; @property (nonatomic, copy, readonly) NSString *_Nonnull nodeType; -@property (nonatomic, copy, readonly) NSString *_Nullable parentXPath; +@property (nonatomic, copy, readonly) NSString *_Nullable parentXpath; @property (nonatomic, assign, readonly) BOOL isContainer; @property (nonatomic, assign, readonly) int index; @property (nonatomic, copy, readonly) NSString *_Nonnull page; @@ -49,8 +50,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) int zLevel; @property (nonatomic, copy, readonly) NSString *_Nullable content; @property (nonatomic, copy, readonly) NSString *_Nonnull xpath; +@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; @property (nonatomic, copy, readonly) NSString *_Nonnull nodeType; -@property (nonatomic, copy, readonly) NSString *_Nullable parentXPath; +@property (nonatomic, copy, readonly) NSString *_Nullable parentXpath; @property (nonatomic, assign, readonly) BOOL isContainer; @property (nonatomic, assign, readonly) int index; @property (nonatomic, copy, readonly) NSString *_Nonnull page; @@ -59,8 +61,9 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingWebCircleElementBuilder * (^)(int value))setZLevel; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setContent; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setXpath; +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setXindex; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setNodeType; -- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXPath; +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXpath; - (GrowingWebCircleElementBuilder * (^)(BOOL value))setIsContainer; - (GrowingWebCircleElementBuilder * (^)(int value))setIndex; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setPage; diff --git a/Modules/WebCircle/GrowingWebCircleElement.m b/Modules/WebCircle/GrowingWebCircleElement.m index 4c15e5724..77ba2bfb1 100644 --- a/Modules/WebCircle/GrowingWebCircleElement.m +++ b/Modules/WebCircle/GrowingWebCircleElement.m @@ -32,10 +32,11 @@ - (instancetype)initWithBuilder:(GrowingWebCircleElementBuilder *)builder { _zLevel = builder.zLevel; _content = builder.content; _xpath = builder.xpath; + _xindex = builder.xindex; _nodeType = builder.nodeType; _isContainer = builder.isContainer; _index = builder.index; - _parentXPath = builder.parentXPath; + _parentXpath = builder.parentXpath; _page = builder.page; _domain = [GrowingDeviceInfo currentDeviceInfo].bundleID; } @@ -52,10 +53,11 @@ - (NSDictionary *)toDictionary { dataDict[@"zLevel"] = @(self.zLevel); dataDict[@"content"] = self.content; dataDict[@"xpath"] = self.xpath; + dataDict[@"xindex"] = self.xindex; dataDict[@"nodeType"] = self.nodeType; dataDict[@"isContainer"] = @(self.isContainer); dataDict[@"index"] = self.index >= 0 ? @(self.index) : nil; - dataDict[@"parentXPath"] = self.parentXPath; + dataDict[@"parentXpath"] = self.parentXpath; dataDict[@"page"] = self.page; dataDict[@"domain"] = self.domain; return [dataDict copy]; @@ -71,24 +73,35 @@ @implementation GrowingWebCircleElementBuilder return self; }; } + - (GrowingWebCircleElementBuilder * (^)(int value))setZLevel { return ^(int value) { self->_zLevel = value; return self; }; } + - (GrowingWebCircleElementBuilder * (^)(NSString *value))setContent { return ^(NSString *value) { self->_content = value; return self; }; } + - (GrowingWebCircleElementBuilder * (^)(NSString *value))setXpath { return ^(NSString *value) { self->_xpath = value; return self; }; } + +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setXindex { + return ^(NSString *value) { + self->_xindex = value; + return self; + }; +} + - (GrowingWebCircleElementBuilder * (^)(NSString *value))setNodeType { return ^(NSString *value) { self->_nodeType = value; @@ -96,9 +109,9 @@ @implementation GrowingWebCircleElementBuilder }; } -- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXPath { +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXpath { return ^(NSString *value) { - self->_parentXPath = value; + self->_parentXpath = value; return self; }; } @@ -109,6 +122,7 @@ @implementation GrowingWebCircleElementBuilder return self; }; } + - (GrowingWebCircleElementBuilder * (^)(int value))setIndex { return ^(int value) { self->_index = value; From 42ee9fd6673e9c8e8393d90aa9d9f1537681df1e Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 6 Jul 2023 10:38:29 +0800 Subject: [PATCH 007/126] refactor: remove cdp wrapper BREAKING CHANGE --- Example/Example.xcodeproj/project.pbxproj | 57 +----- .../GrowingAnalyticsTests.xctestplan | 7 - Example/Podfile | 9 +- Gemfile.lock | 14 +- GrowingAutotracker-cdp/GrowingAutotracker.h | 182 ------------------ GrowingAutotracker-cdp/GrowingAutotracker.m | 74 ------- GrowingTracker-cdp/GrowingTracker.h | 125 ------------ GrowingTracker-cdp/GrowingTracker.m | 74 ------- Package.swift | 80 -------- Podfile.lock | 162 ++++++++++++++++ .../dummy.m | 18 -- .../include/dummy.h | 20 -- .../GrowingAutotracker-cdp-Wrapper/dummy.m | 18 -- .../include/dummy.h | 20 -- .../GrowingTracker-cdp-NoIDFA-Wrapper/dummy.m | 18 -- .../include/dummy.h | 20 -- .../GrowingTracker-cdp-Wrapper/dummy.m | 18 -- .../include/dummy.h | 20 -- 18 files changed, 171 insertions(+), 765 deletions(-) delete mode 100644 GrowingAutotracker-cdp/GrowingAutotracker.h delete mode 100644 GrowingAutotracker-cdp/GrowingAutotracker.m delete mode 100644 GrowingTracker-cdp/GrowingTracker.h delete mode 100644 GrowingTracker-cdp/GrowingTracker.m create mode 100644 Podfile.lock delete mode 100644 SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/dummy.m delete mode 100644 SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/include/dummy.h delete mode 100644 SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/dummy.m delete mode 100644 SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/include/dummy.h delete mode 100644 SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/dummy.m delete mode 100644 SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/include/dummy.h delete mode 100644 SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/dummy.m delete mode 100644 SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/include/dummy.h diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 54816544e..e4d8fba71 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -174,7 +174,6 @@ 6F7A64B402BF8E5ED466E56A /* Pods_GrowingAnalyticsTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0257123D870B44A9FDA90A22 /* Pods_GrowingAnalyticsTests.framework */; }; 7E20527CFF34511EE464C33F /* Pods_GrowingAnalyticsStartTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1769255A062869A5D219F683 /* Pods_GrowingAnalyticsStartTests.framework */; }; 8016AAD2B2E1BE4321C4AA76 /* Pods_AdvertTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6CD8BC1E7857B5F760A5EF6 /* Pods_AdvertTests.framework */; }; - 813BAB07E78F29715302F2A9 /* Pods_GrowingAnalyticsCDPTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B917B3D306DA7615DB939CF1 /* Pods_GrowingAnalyticsCDPTests.framework */; }; 997DAC68973F1F4FAF34EA2E /* Pods_Example_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B524BD63EF3439946134E74 /* Pods_Example_macOS.framework */; }; A61E1E81175885070AAD10A9 /* Pods_ExampleiOS13.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7CCC2E00F858DC5B58D4FA6 /* Pods_ExampleiOS13.framework */; }; A9D21D06460258FAC4736A26 /* Pods_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 90476D1583D0EE778FCBED5E /* Pods_Example.framework */; }; @@ -506,7 +505,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 813BAB07E78F29715302F2A9 /* Pods_GrowingAnalyticsCDPTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -712,8 +710,6 @@ 03D85F7CFC2FCDB001B3D5D4 /* Pods-Example-macOS.release.xcconfig */, F625366B1611DA7E27D0E32C /* Pods-ExampleiOS13.debug.xcconfig */, E1800E7E573CE2BD70F0B706 /* Pods-ExampleiOS13.release.xcconfig */, - FF93145D0D866B2292B78207 /* Pods-GrowingAnalyticsCDPTests.debug.xcconfig */, - E358AB81E170FF3B9BD33067 /* Pods-GrowingAnalyticsCDPTests.release.xcconfig */, 0B3751A8D7A8C11CD50B544E /* Pods-GrowingAnalyticsStartTests.debug.xcconfig */, CFC074E90BAC4B828194DC02 /* Pods-GrowingAnalyticsStartTests.release.xcconfig */, 6F9B4F11B90235A2D461CA2C /* Pods-GrowingAnalyticsTests.debug.xcconfig */, @@ -1332,7 +1328,6 @@ 90476D1583D0EE778FCBED5E /* Pods_Example.framework */, 7B524BD63EF3439946134E74 /* Pods_Example_macOS.framework */, C7CCC2E00F858DC5B58D4FA6 /* Pods_ExampleiOS13.framework */, - B917B3D306DA7615DB939CF1 /* Pods_GrowingAnalyticsCDPTests.framework */, 1769255A062869A5D219F683 /* Pods_GrowingAnalyticsStartTests.framework */, 0257123D870B44A9FDA90A22 /* Pods_GrowingAnalyticsTests.framework */, 42F5EA0EFE2552358C35A0F5 /* Pods_HostApplicationTests.framework */, @@ -1518,11 +1513,9 @@ isa = PBXNativeTarget; buildConfigurationList = 34D932FB27BF8A400038430E /* Build configuration list for PBXNativeTarget "GrowingAnalyticsCDPTests" */; buildPhases = ( - 3CEBDA37D6A7D501E79089BA /* [CP] Check Pods Manifest.lock */, 34D932F327BF8A400038430E /* Sources */, 34D932F427BF8A400038430E /* Frameworks */, 34D932F527BF8A400038430E /* Resources */, - A523D526C1FE97C2DBAC19A0 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -1833,15 +1826,13 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsStartTests/Pods-GrowingAnalyticsStartTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-fbb9594a/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-0637fae5/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-cdp/GrowingAnalytics_cdp.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics_cdp.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1892,28 +1883,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 3CEBDA37D6A7D501E79089BA /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-GrowingAnalyticsCDPTests-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; 3FA29A0059DBF9AA6AB30AC3 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -2046,28 +2015,6 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsTests/Pods-GrowingAnalyticsTests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - A523D526C1FE97C2DBAC19A0 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsCDPTests/Pods-GrowingAnalyticsCDPTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-fbb9594a/GrowingAnalytics.framework", - "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-cdp/GrowingAnalytics_cdp.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics_cdp.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsCDPTests/Pods-GrowingAnalyticsCDPTests-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; BD21E0F09980000364B80451 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -3346,7 +3293,6 @@ }; 34D932FC27BF8A400038430E /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = FF93145D0D866B2292B78207 /* Pods-GrowingAnalyticsCDPTests.debug.xcconfig */; buildSettings = { CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -3391,7 +3337,6 @@ }; 34D932FD27BF8A400038430E /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = E358AB81E170FF3B9BD33067 /* Pods-GrowingAnalyticsCDPTests.release.xcconfig */; buildSettings = { CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; diff --git a/Example/GrowingAnalyticsTests/GrowingAnalyticsTests.xctestplan b/Example/GrowingAnalyticsTests/GrowingAnalyticsTests.xctestplan index 1ff8add85..de343f0ff 100644 --- a/Example/GrowingAnalyticsTests/GrowingAnalyticsTests.xctestplan +++ b/Example/GrowingAnalyticsTests/GrowingAnalyticsTests.xctestplan @@ -40,13 +40,6 @@ "name" : "ProtobufTests" } }, - { - "target" : { - "containerPath" : "container:Example.xcodeproj", - "identifier" : "34D932F627BF8A400038430E", - "name" : "GrowingAnalyticsCDPTests" - } - }, { "target" : { "containerPath" : "container:Example.xcodeproj", diff --git a/Example/Podfile b/Example/Podfile index 2b674c6ec..074f901ff 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -35,14 +35,9 @@ target 'GrowingAnalyticsTests' do pod 'GrowingAnalytics/Tracker', :path => '../' end -target 'GrowingAnalyticsCDPTests' do - pod 'GrowingAnalytics-cdp/Autotracker', :path => '../' - pod 'GrowingAnalytics-cdp/Tracker', :path => '../' -end - target 'GrowingAnalyticsStartTests' do - pod 'GrowingAnalytics-cdp/Autotracker', :path => '../' - pod 'GrowingAnalytics-cdp/Tracker', :path => '../' + pod 'GrowingAnalytics/Autotracker', :path => './' + pod 'GrowingAnalytics/Tracker', :path => './' end target 'HostApplicationTests' do diff --git a/Gemfile.lock b/Gemfile.lock index 31017cebc..0a0ef7f08 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/CocoaPods/CocoaPods.git - revision: 57735585a6aca1ca62a25876d41804bde705eef7 + revision: 7234edf38f6e8bafc4ab75d42945af0f100b80df specs: cocoapods (1.12.1) addressable (~> 2.8) @@ -23,7 +23,7 @@ GIT GIT remote: https://github.com/CocoaPods/Xcodeproj.git - revision: 2fe65ce43a244370c245bcbf4176f16ff0f442cf + revision: 2ce68b60856c4680c2b3cd7aa5b221529120c7c4 specs: xcodeproj (1.22.0) CFPropertyList (>= 2.3.3, < 4.0) @@ -45,12 +45,11 @@ GEM specs: CFPropertyList (3.0.6) rexml - activesupport (6.1.7.3) + activesupport (7.0.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) algoliasearch (1.27.5) @@ -88,10 +87,10 @@ GEM fuzzy_match (2.0.4) gh_inspector (1.1.3) httpclient (2.8.3) - i18n (1.13.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) json (2.6.3) - minitest (5.18.0) + minitest (5.18.1) molinillo (0.8.0) nanaimo (0.3.0) nap (1.1.0) @@ -103,10 +102,9 @@ GEM ethon (>= 0.9.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - zeitwerk (2.6.7) PLATFORMS - ruby + arm64-darwin-22 DEPENDENCIES cocoapods! diff --git a/GrowingAutotracker-cdp/GrowingAutotracker.h b/GrowingAutotracker-cdp/GrowingAutotracker.h deleted file mode 100644 index dbb2e07d4..000000000 --- a/GrowingAutotracker-cdp/GrowingAutotracker.h +++ /dev/null @@ -1,182 +0,0 @@ -// -// GrowingAutotracker.h -// GrowingAnalytics-cdp -// -// Created by sheng on 2020/11/24. -// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import -#import "GrowingAttributesBuilder.h" -#import "GrowingAutotrackConfiguration.h" -#import "GrowingDynamicProxy.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface GrowingAutotracker : GrowingDynamicProxy - -///------------------------------- -#pragma mark Initialization -///------------------------------- - -/// 初始化方法 -/// @param configuration 配置信息 -/// @param launchOptions 启动参数 -+ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions; - -/// 单例获取 -+ (instancetype)sharedInstance; - -///------------------------------- -#pragma mark Configuration -///------------------------------- - -/// 打开或关闭数据采集 -/// @param enabled 打开或者关闭 -- (void)setDataCollectionEnabled:(BOOL)enabled; - -/// 当用户登录之后调用setLoginUserId API,设置登录用户ID。 -/// @param userId 用户ID -- (void)setLoginUserId:(NSString *)userId; - -/// 支持设置userId的类型, 存储方式与userId保持一致, userKey默认为null -/// @param userId 用户ID -/// @param userKey 用户ID对应的类型key值 -- (void)setLoginUserId:(NSString *)userId userKey:(NSString *)userKey; - -/// 当用户登出之后调用cleanLoginUserId,清除已经设置的登录用户ID。 -- (void)cleanLoginUserId; - -/// 设置经纬度坐标 -/// @param latitude 纬度 -/// @param longitude 经度 -- (void)setLocation:(double)latitude longitude:(double)longitude; - -/// 清除地理位置 -- (void)cleanLocation; - -/// 以登录用户的身份定义用户属性变量,用于用户信息相关分析。 -/// @param attributes 用户属性信息 -- (void)setLoginUserAttributes:(NSDictionary *)attributes; - -/// 同步获取设备id,又称为匿名用户id,SDK 自动生成用来定义唯一设备。 -- (NSString *)getDeviceId; - -///------------------------------- -#pragma mark Track Event -///------------------------------- - -/// 发送一个自定义事件 -/// @param eventName 自定义事件名称 -- (void)trackCustomEvent:(NSString *)eventName; - -/// 发送一个自定义事件 -/// @param eventName 自定义事件名称 -/// @param attributes 事件发生时所伴随的维度信息 -- (void)trackCustomEvent:(NSString *)eventName withAttributes:(NSDictionary *)attributes; - -/// 初始化事件计时器 -/// @param eventName 自定义事件名称 -/// @return 计时器唯一标识 -- (nullable NSString *)trackTimerStart:(NSString *)eventName; - -/// 暂停事件计时器 -/// @param timerId 计时器唯一标识 -- (void)trackTimerPause:(NSString *)timerId; - -/// 恢复事件计时器 -/// @param timerId 计时器唯一标识 -- (void)trackTimerResume:(NSString *)timerId; - -/// 停止事件计时器,并发送一个自定义事件 -/// @param timerId 计时器唯一标识 -- (void)trackTimerEnd:(NSString *)timerId; - -/// 停止事件计时器,并发送一个自定义事件 -/// @param timerId 计时器唯一标识 -/// @param attributes 事件发生时所伴随的维度信息 -- (void)trackTimerEnd:(NSString *)timerId withAttributes:(NSDictionary *)attributes; - -/// 删除事件计时器 -/// @param timerId 计时器唯一标识 -- (void)removeTimer:(NSString *)timerId; - -/// 清除所有事件计时器 -- (void)clearTrackTimer; - -///------------------------------- -#pragma mark Unavailable -///------------------------------- - -- (instancetype)init NS_UNAVAILABLE; - -@end - -// imp半自动打点 -@interface UIView (GrowingImpression) - -/** - 以下为元素展示打点事件 - 在元素展示前调用即可,GIO负责监听元素展示并触发事件 - 事件类型为自定义事件(cstm) - @param eventName 自定义事件名称 - */ -- (void)growingTrackImpression:(NSString *)eventName; - -/** - 以下为元素展示打点事件 - 在元素展示前调用即可,GIO负责监听元素展示并触发事件 - 事件类型为自定义事件(cstm) - @param eventName 自定义事件名称 - @param attributes 自定义属性 - */ -- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *)attributes; - -// 停止该元素展示追踪 -// 通常应用于列表中的重用元素 -// 例如您只想追踪列表中的第一行元素的展示,但当第四行出现时重用了第一行的元素,此时您可调用此函数避免事件触发 -- (void)growingStopTrackImpression; - -@end - -// 该属性setter方法均使用 objc_setAssociatedObject实现 -// 如果是自定义的View建议优先使用重写getter方法来实现 以提高性能 -@interface UIView (GrowingAttributes) - -// 手动标识该view的忽略策略,请在该view被初始化后立刻赋值 -@property (nonatomic, assign) GrowingIgnorePolicy growingViewIgnorePolicy; - -// 手动标识该view的取值,请在该view被初始化后立刻赋值 -@property (nonatomic, copy) NSString *growingViewCustomContent; - -// 手动标识该view的tag -// 这个tag必须是全局唯一的,在代码结构改变时也请保持不变 -@property (nonatomic, copy) NSString *growingUniqueTag; - -@end - -// 该属性setter方法均使用 objc_setAssociatedObject实现 -// 如果是自定义的UIViewController不要使用重写getter方法来实现,因为SDK在set方法内部有逻辑处理 -@interface UIViewController (GrowingAttributes) - -// 手动标识该页面的标题,必须在该UIViewController显示之前设置 -@property (nonatomic, copy) NSString *growingPageAlias; - -@property (nonatomic, copy) NSDictionary *growingPageAttributes; - -@property (nonatomic, assign) GrowingIgnorePolicy growingPageIgnorePolicy; - -@end - -NS_ASSUME_NONNULL_END diff --git a/GrowingAutotracker-cdp/GrowingAutotracker.m b/GrowingAutotracker-cdp/GrowingAutotracker.m deleted file mode 100644 index dd6d5961b..000000000 --- a/GrowingAutotracker-cdp/GrowingAutotracker.m +++ /dev/null @@ -1,74 +0,0 @@ -// -// GrowingAutotracker.m -// GrowingAnalytics-cdp -// -// Created by sheng on 2020/11/24. -// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "GrowingAutotracker-cdp/GrowingAutotracker.h" -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" - -static GrowingAutotracker *sharedInstance = nil; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wincomplete-implementation" - -@implementation GrowingAutotracker -- (instancetype)initWithRealAutotracker:(GrowingRealAutotracker *)realAutotracker { - self = [super initWithTarget:realAutotracker]; - return self; -} - -+ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions { - if (![NSThread isMainThread]) { - @throw [NSException - exceptionWithName:@"初始化异常" - reason:@"请在applicationDidFinishLaunching中调用startWithConfiguration函数,并且确保在主线程中" - userInfo:nil]; - } - - if (!configuration.projectId.length) { - @throw [NSException exceptionWithName:@"初始化异常" reason:@"ProjectId不能为空" userInfo:nil]; - } - - if (!configuration.dataSourceId.length) { - @throw [NSException exceptionWithName:@"初始化异常" reason:@"dataSourceId不能为空" userInfo:nil]; - } - - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - GrowingRealAutotracker *autotracker = [GrowingRealAutotracker trackerWithConfiguration:configuration - launchOptions:launchOptions]; - sharedInstance = [[self alloc] initWithRealAutotracker:autotracker]; - [[GrowingSession currentSession] generateVisit]; - }); -} - -+ (instancetype)sharedInstance { - if (!sharedInstance) { - @throw [NSException - exceptionWithName:@"GrowingAutotracker未初始化" - reason:@"请在applicationDidFinishLaunching中调用startWithConfiguration函数,并且确保在主线程中" - userInfo:nil]; - } - return sharedInstance; -} - -@end - -#pragma clang diagnostic pop diff --git a/GrowingTracker-cdp/GrowingTracker.h b/GrowingTracker-cdp/GrowingTracker.h deleted file mode 100644 index e495f3854..000000000 --- a/GrowingTracker-cdp/GrowingTracker.h +++ /dev/null @@ -1,125 +0,0 @@ -// -// GrowingCdpRealTracker.h -// GrowingAnalytics-cdp -// -// Created by sheng on 2020/11/24. -// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "GrowingAttributesBuilder.h" -#import "GrowingDynamicProxy.h" -#import "GrowingTrackConfiguration.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface GrowingTracker : GrowingDynamicProxy - -///------------------------------- -#pragma mark Initialization -///------------------------------- - -/// 初始化方法 -/// @param configuration 配置信息 -/// @param launchOptions 启动参数 -+ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions; - -/// 单例获取 -+ (instancetype)sharedInstance; - -///------------------------------- -#pragma mark Configuration -///------------------------------- - -/// 打开或关闭数据采集 -/// @param enabled 打开或者关闭 -- (void)setDataCollectionEnabled:(BOOL)enabled; - -/// 当用户登录之后调用setLoginUserId API,设置登录用户ID。 -/// @param userId 用户ID -- (void)setLoginUserId:(NSString *)userId; - -/// 支持设置userId的类型, 存储方式与userId保持一致, userKey默认为null -/// @param userId 用户ID -/// @param userKey 用户ID对应的类型key值 -- (void)setLoginUserId:(NSString *)userId userKey:(NSString *)userKey; - -/// 当用户登出之后调用cleanLoginUserId,清除已经设置的登录用户ID。 -- (void)cleanLoginUserId; - -/// 设置经纬度坐标 -/// @param latitude 纬度 -/// @param longitude 经度 -- (void)setLocation:(double)latitude longitude:(double)longitude; - -/// 清除地理位置 -- (void)cleanLocation; - -/// 以登录用户的身份定义用户属性变量,用于用户信息相关分析。 -/// @param attributes 用户属性信息 -- (void)setLoginUserAttributes:(NSDictionary *)attributes; - -/// 同步获取设备id,又称为匿名用户id,SDK 自动生成用来定义唯一设备。 -- (NSString *)getDeviceId; - -///------------------------------- -#pragma mark Track Event -///------------------------------- - -/// 发送一个自定义事件 -/// @param eventName 自定义事件名称 -- (void)trackCustomEvent:(NSString *)eventName; - -/// 发送一个自定义事件 -/// @param eventName 自定义事件名称 -/// @param attributes 事件发生时所伴随的维度信息 -- (void)trackCustomEvent:(NSString *)eventName withAttributes:(NSDictionary *)attributes; - -/// 初始化事件计时器 -/// @param eventName 自定义事件名称 -/// @return 计时器唯一标识 -- (nullable NSString *)trackTimerStart:(NSString *)eventName; - -/// 暂停事件计时器 -/// @param timerId 计时器唯一标识 -- (void)trackTimerPause:(NSString *)timerId; - -/// 恢复事件计时器 -/// @param timerId 计时器唯一标识 -- (void)trackTimerResume:(NSString *)timerId; - -/// 停止事件计时器,并发送一个自定义事件 -/// @param timerId 计时器唯一标识 -- (void)trackTimerEnd:(NSString *)timerId; - -/// 停止事件计时器,并发送一个自定义事件 -/// @param timerId 计时器唯一标识 -/// @param attributes 事件发生时所伴随的维度信息 -- (void)trackTimerEnd:(NSString *)timerId withAttributes:(NSDictionary *)attributes; - -/// 删除事件计时器 -/// @param timerId 计时器唯一标识 -- (void)removeTimer:(NSString *)timerId; - -/// 清除所有事件计时器 -- (void)clearTrackTimer; - -///------------------------------- -#pragma mark Unavailable -///------------------------------- - -- (instancetype)init NS_UNAVAILABLE; - -@end - -NS_ASSUME_NONNULL_END diff --git a/GrowingTracker-cdp/GrowingTracker.m b/GrowingTracker-cdp/GrowingTracker.m deleted file mode 100644 index b436ab68a..000000000 --- a/GrowingTracker-cdp/GrowingTracker.m +++ /dev/null @@ -1,74 +0,0 @@ -// -// GrowingCdpRealTracker.m -// GrowingAnalytics-cdp -// -// Created by sheng on 2020/11/24. -// Copyright (C) 2017 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "GrowingTracker-cdp/GrowingTracker.h" -#import "GrowingTrackerCore/GrowingRealTracker.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" - -static GrowingTracker *sharedInstance = nil; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wincomplete-implementation" - -@implementation GrowingTracker -- (instancetype)initWithRealTracker:(GrowingRealTracker *)realTracker { - self = [super initWithTarget:realTracker]; - return self; -} - -+ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions { - if (![NSThread isMainThread]) { - @throw [NSException - exceptionWithName:@"初始化异常" - reason:@"请在applicationDidFinishLaunching中调用startWithConfiguration函数,并且确保在主线程中" - userInfo:nil]; - } - - if (!configuration.projectId.length) { - @throw [NSException exceptionWithName:@"初始化异常" reason:@"ProjectId不能为空" userInfo:nil]; - } - - if (!configuration.dataSourceId.length) { - @throw [NSException exceptionWithName:@"初始化异常" reason:@"dataSourceId不能为空" userInfo:nil]; - } - - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - GrowingRealTracker *realTracker = [GrowingRealTracker trackerWithConfiguration:configuration - launchOptions:launchOptions]; - sharedInstance = [[self alloc] initWithRealTracker:realTracker]; - [[GrowingSession currentSession] generateVisit]; - }); -} - -+ (instancetype)sharedInstance { - if (!sharedInstance) { - @throw [NSException - exceptionWithName:@"GrowingTracker未初始化" - reason:@"请在applicationDidFinishLaunching中调用startWithConfiguration函数,并且确保在主线程中" - userInfo:nil]; - } - return sharedInstance; -} - -@end - -#pragma clang diagnostic pop diff --git a/Package.swift b/Package.swift index 074144b03..18e530f7d 100644 --- a/Package.swift +++ b/Package.swift @@ -26,14 +26,6 @@ let package = Package( name: "GrowingAnalytics", platforms: [.iOS(.v10), .macCatalyst(.v13), .macOS(.v10_12)], products: [ - .library( - name: "GrowingAutotracker_cdp", - targets: ["GrowingAutotracker_cdp_Wrapper"] - ), - .library( - name: "GrowingTracker_cdp", - targets: ["GrowingTracker_cdp_Wrapper"] - ), .library( name: "GrowingAutotracker", targets: ["GrowingAutotracker_Wrapper"] @@ -42,14 +34,6 @@ let package = Package( name: "GrowingTracker", targets: ["GrowingTracker_Wrapper"] ), - .library( - name: "GrowingAutotracker_cdp_NoIDFA", - targets: ["GrowingAutotracker_cdp_NoIDFA_Wrapper"] - ), - .library( - name: "GrowingTracker_cdp_NoIDFA", - targets: ["GrowingTracker_cdp_NoIDFA_Wrapper"] - ), .library( name: "GrowingAutotracker_NoIDFA", targets: ["GrowingAutotracker_NoIDFA_Wrapper"] @@ -92,28 +76,6 @@ let package = Package( targets: [ // MARK: - GrowingAnalytics Wrapper - .target( - name: "GrowingAutotracker_cdp_Wrapper", - dependencies: [ - "GrowingAutotracker_cdp", - "GrowingUserIdentifier", - "GrowingModule_DefaultServices", - .target(name: "GrowingModule_Hybrid", condition: .when(platforms: [.iOS, .macCatalyst])), - .target(name: "GrowingModule_MobileDebugger", condition: .when(platforms: [.iOS])), - .target(name: "GrowingModule_WebCircle", condition: .when(platforms: [.iOS])), - ], - path: "SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper" - ), - .target( - name: "GrowingTracker_cdp_Wrapper", - dependencies: [ - "GrowingTracker_cdp", - "GrowingUserIdentifier", - "GrowingModule_DefaultServices", - .target(name: "GrowingModule_MobileDebugger", condition: .when(platforms: [.iOS])), - ], - path: "SwiftPM-Wrap/GrowingTracker-cdp-Wrapper" - ), .target( name: "GrowingAutotracker_Wrapper", dependencies: [ @@ -139,26 +101,6 @@ let package = Package( // MARK: - GrowingAnalytics Public API - .target( - name: "GrowingAutotracker_cdp", - dependencies: [ - "GrowingAutotrackerCore", - ], - path: "GrowingAutotracker-cdp", - publicHeadersPath: ".", - cSettings: [ - .headerSearchPath(".."), - ] - ), - .target( - name: "GrowingTracker_cdp", - dependencies: ["GrowingTrackerCore"], - path: "GrowingTracker-cdp", - publicHeadersPath: ".", - cSettings: [ - .headerSearchPath(".."), - ] - ), .target( name: "GrowingAutotracker", dependencies: ["GrowingAutotrackerCore"], @@ -393,28 +335,6 @@ let package = Package( // MARK: - GrowingAnalytics Wrapper (No IDFA) - .target( - name: "GrowingAutotracker_cdp_NoIDFA_Wrapper", - dependencies: [ - "GrowingAutotracker_cdp", - "GrowingUserIdentifier_NoIDFA", - "GrowingModule_DefaultServices", - .target(name: "GrowingModule_Hybrid", condition: .when(platforms: [.iOS, .macCatalyst])), - .target(name: "GrowingModule_MobileDebugger", condition: .when(platforms: [.iOS])), - .target(name: "GrowingModule_WebCircle", condition: .when(platforms: [.iOS])), - ], - path: "SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper" - ), - .target( - name: "GrowingTracker_cdp_NoIDFA_Wrapper", - dependencies: [ - "GrowingTracker_cdp", - "GrowingUserIdentifier_NoIDFA", - "GrowingModule_DefaultServices", - .target(name: "GrowingModule_MobileDebugger", condition: .when(platforms: [.iOS])), - ], - path: "SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper" - ), .target( name: "GrowingAutotracker_NoIDFA_Wrapper", dependencies: [ diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 000000000..16bca09af --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,162 @@ +PODS: + - GrowingAnalytics/Advert (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/APM (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAPM/Core + - GrowingAnalytics/Autotracker (3.5.0): + - GrowingAnalytics/AutotrackerCore (= 3.5.0) + - GrowingAnalytics/DefaultServices (= 3.5.0) + - GrowingAnalytics/Hybrid (= 3.5.0) + - GrowingAnalytics/MobileDebugger (= 3.5.0) + - GrowingAnalytics/WebCircle (= 3.5.0) + - GrowingAnalytics/AutotrackerCore (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingUtils/AutotrackerCore (= 0.0.5) + - GrowingAnalytics/Compression (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/Database (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/DefaultServices (3.5.0): + - GrowingAnalytics/Compression (= 3.5.0) + - GrowingAnalytics/Database (= 3.5.0) + - GrowingAnalytics/Encryption (= 3.5.0) + - GrowingAnalytics/Network (= 3.5.0) + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/Encryption (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/Hybrid (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/MobileDebugger (3.5.0): + - GrowingAnalytics/Screenshot (= 3.5.0) + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/WebSocket (= 3.5.0) + - GrowingAnalytics/Network (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/Protobuf (3.5.0): + - GrowingAnalytics/Database (= 3.5.0) + - GrowingAnalytics/Protobuf/Proto (= 3.5.0) + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/Protobuf/Proto (3.5.0): + - GrowingAnalytics/Database (= 3.5.0) + - GrowingAnalytics/TrackerCore (= 3.5.0) + - Protobuf + - GrowingAnalytics/Screenshot (3.5.0): + - GrowingAnalytics/TrackerCore + - GrowingAnalytics/Tracker (3.5.0): + - GrowingAnalytics/DefaultServices (= 3.5.0) + - GrowingAnalytics/MobileDebugger (= 3.5.0) + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/TrackerCore (3.5.0): + - GrowingUtils/TrackerCore (= 0.0.5) + - GrowingAnalytics/WebCircle (3.5.0): + - GrowingAnalytics/AutotrackerCore (= 3.5.0) + - GrowingAnalytics/Hybrid (= 3.5.0) + - GrowingAnalytics/Screenshot (= 3.5.0) + - GrowingAnalytics/WebSocket (= 3.5.0) + - GrowingAnalytics/WebSocket (3.5.0): + - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAPM (0.0.14): + - GrowingAPM/Core (= 0.0.14) + - GrowingAPM/CrashMonitor (= 0.0.14) + - GrowingAPM/UIMonitor (= 0.0.14) + - GrowingAPM/Core (0.0.14): + - GrowingUtils/TrackerCore + - GrowingAPM/CrashMonitor (0.0.14): + - GrowingAPM/Core + - GrowingAPM/UIMonitor (0.0.14): + - GrowingAPM/Core + - GrowingToolsKit (1.1.3): + - GrowingToolsKit/Default (= 1.1.3) + - GrowingToolsKit/APMCore (1.1.3): + - GrowingAPM/Core + - GrowingToolsKit/Core + - GrowingToolsKit/Core (1.1.3) + - GrowingToolsKit/CrashMonitor (1.1.3): + - GrowingAPM/CrashMonitor + - GrowingToolsKit/APMCore + - GrowingToolsKit/Default (1.1.3): + - GrowingToolsKit/Core + - GrowingToolsKit/CrashMonitor + - GrowingToolsKit/EventsList + - GrowingToolsKit/LaunchTime + - GrowingToolsKit/NetFlow + - GrowingToolsKit/Realtime + - GrowingToolsKit/SDKInfo + - GrowingToolsKit/Settings + - GrowingToolsKit/XPathTrack + - GrowingToolsKit/EventsList (1.1.3): + - GrowingToolsKit/Core + - GrowingToolsKit/LaunchTime (1.1.3): + - GrowingAPM/UIMonitor + - GrowingToolsKit/APMCore + - GrowingToolsKit/NetFlow (1.1.3): + - GrowingToolsKit/Core + - GrowingToolsKit/Realtime (1.1.3): + - GrowingToolsKit/Core + - GrowingToolsKit/SDKInfo (1.1.3): + - GrowingToolsKit/Core + - GrowingToolsKit/Settings (1.1.3): + - GrowingToolsKit/Core + - GrowingToolsKit/XPathTrack (1.1.3): + - GrowingToolsKit/Core + - GrowingUtils/AutotrackerCore (0.0.5): + - GrowingUtils/TrackerCore + - GrowingUtils/TrackerCore (0.0.5) + - KIF (3.8.9): + - KIF/Core (= 3.8.9) + - KIF/Core (3.8.9) + - LBXScan/LBXNative (2.3): + - LBXScan/Types (~> 2.2) + - LBXScan/Types (2.3) + - LBXScan/UI (2.3): + - LBXScan/Types (~> 2.2) + - Protobuf (3.23.3) + - SDCycleScrollView (1.82): + - SDWebImage (>= 5.0.0) + - SDWebImage (5.16.0): + - SDWebImage/Core (= 5.16.0) + - SDWebImage/Core (5.16.0) + +DEPENDENCIES: + - GrowingAnalytics/Advert (from `./`) + - GrowingAnalytics/APM (from `./`) + - GrowingAnalytics/Autotracker (from `./`) + - GrowingAnalytics/Protobuf (from `./`) + - GrowingAnalytics/Tracker (from `./`) + - GrowingAPM + - GrowingToolsKit (>= 1.1.3) + - KIF + - LBXScan/LBXNative (= 2.3) + - LBXScan/UI (= 2.3) + - SDCycleScrollView (~> 1.75) + +SPEC REPOS: + trunk: + - GrowingAPM + - GrowingToolsKit + - GrowingUtils + - KIF + - LBXScan + - Protobuf + - SDCycleScrollView + - SDWebImage + +EXTERNAL SOURCES: + GrowingAnalytics: + :path: "./" + +SPEC CHECKSUMS: + GrowingAnalytics: 9c4c3c7e33523f3daba012a06f0f419b77e02544 + GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a + GrowingToolsKit: 88b144e858f8895f1d84c518642ce34ce0f5aa07 + GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 + KIF: 7660c626b0f2d4562533590960db70a36d640558 + LBXScan: e51449f0832d1fe17da632af0d22adeb3cfa3543 + Protobuf: d9c3d7e5a3574aa6a5d521f2d9f733c76d294be8 + SDCycleScrollView: a0d74c3384caa72bdfc81470bdbc8c14b3e1fbcf + SDWebImage: 2aea163b50bfcb569a2726b6a754c54a4506fcf6 + +PODFILE CHECKSUM: 35caa7945daf79d82b68a3ed0e3fe6f47130bac1 + +COCOAPODS: 1.12.1 diff --git a/SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/dummy.m b/SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/dummy.m deleted file mode 100644 index c675faf71..000000000 --- a/SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/dummy.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. diff --git a/SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/include/dummy.h b/SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/include/dummy.h deleted file mode 100644 index 71bfa56a9..000000000 --- a/SwiftPM-Wrap/GrowingAutotracker-cdp-NoIDFA-Wrapper/include/dummy.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Prevent a missing umbrella header warning. diff --git a/SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/dummy.m b/SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/dummy.m deleted file mode 100644 index c675faf71..000000000 --- a/SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/dummy.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. diff --git a/SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/include/dummy.h b/SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/include/dummy.h deleted file mode 100644 index 71bfa56a9..000000000 --- a/SwiftPM-Wrap/GrowingAutotracker-cdp-Wrapper/include/dummy.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Prevent a missing umbrella header warning. diff --git a/SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/dummy.m b/SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/dummy.m deleted file mode 100644 index c675faf71..000000000 --- a/SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/dummy.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. diff --git a/SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/include/dummy.h b/SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/include/dummy.h deleted file mode 100644 index 71bfa56a9..000000000 --- a/SwiftPM-Wrap/GrowingTracker-cdp-NoIDFA-Wrapper/include/dummy.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Prevent a missing umbrella header warning. diff --git a/SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/dummy.m b/SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/dummy.m deleted file mode 100644 index c675faf71..000000000 --- a/SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/dummy.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. diff --git a/SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/include/dummy.h b/SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/include/dummy.h deleted file mode 100644 index 71bfa56a9..000000000 --- a/SwiftPM-Wrap/GrowingTracker-cdp-Wrapper/include/dummy.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// dummy.h -// GrowingAnalytics -// -// Created by YoloMao on 2022/3/28. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Prevent a missing umbrella header warning. From 60d3163bd71bb8403d5c13c5529777330ece085e Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 6 Jul 2023 17:37:13 +0800 Subject: [PATCH 008/126] =?UTF-8?q?refactor:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Category/UIAlertController+GrowingNode.m | 12 ++++++--- .../Category/UITableView+GrowingNode.m | 25 ++++++++++++++++++ .../GrowingNode/Category/UIView+GrowingNode.h | 6 ----- .../GrowingNode/Category/UIView+GrowingNode.m | 26 ------------------- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m index d059d80f0..d2922fc6e 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m @@ -80,21 +80,25 @@ + (void)addAutoTrackSwizzles { } - (NSString *)growingNodeSubPath { - NSString *subpath = @"Button"; + return @"Button"; +} +- (NSString *)growingNodeSubIndex { + NSString *subIndex = @"0"; UIViewController *responderVC = [self growingHelper_viewController]; if ([responderVC isKindOfClass:UIAlertController.class]) { UIAlertController *alertVC = (UIAlertController *)responderVC; - UIAlertAction *action = [UIAlertController growing_actionForActionView:(id)self]; NSInteger index = -1; if (alertVC.actions && action) { index = [alertVC.actions indexOfObject:action]; } - subpath = (index < 0) ? subpath : [NSString stringWithFormat:@"Button[%ld]", (long)index]; + if (index >= 0) { + subIndex = [NSString stringWithFormat:@"%ld", (long)index]; + } } - return subpath; + return subIndex; } - (BOOL)growingNodeUserInteraction { diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m index f7c89a1ed..4e7cd4ce7 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m @@ -105,3 +105,28 @@ - (BOOL)growingNodeDonotCircle { } @end + +@implementation UITableViewHeaderFooterView (GrowingNode) + +- (NSString *)growingNodeSubIndex { + UIView *view = self; + do { + view = view.superview; + } while (view && ![view isKindOfClass:[UITableView class]]); + + if (view) { + UITableView *tableView = (UITableView *)view; + for (NSInteger i = 0; i < tableView.numberOfSections; i++) { + if (self == [tableView headerViewForSection:i]) { + return [NSString stringWithFormat:@"%ld", (long)i]; + } + if (self == [tableView footerViewForSection:i]) { + return [NSString stringWithFormat:@"%ld", (long)i]; + } + } + } + + return [super growingNodeSubIndex]; +} + +@end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h index b8a126e14..b47581baf 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h @@ -32,9 +32,3 @@ - (BOOL)growingViewDontTrack; @end - -#pragma mark - section - -@interface UITableViewHeaderFooterView (GrowingNode) - -@end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index 539b5005e..d8b2fd297 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -330,32 +330,6 @@ - (GrowingIgnorePolicy)growingViewIgnorePolicy { @end -#pragma mark - section - -@implementation UITableViewHeaderFooterView (GrowingNode) - -- (NSString *)growingNodeSubPath { - UITableView *tableView = (UITableView *)self.superview; - - while (![tableView isKindOfClass:UITableView.class]) { - tableView = (UITableView *)tableView.superview; - if (!tableView) { - return super.growingNodeSubPath; - } - } - for (NSInteger i = 0; i < tableView.numberOfSections; i++) { - if (self == [tableView headerViewForSection:i]) { - return [NSString stringWithFormat:@"%@[%ld]", NSStringFromClass([self class]), (long)i]; - } - if (self == [tableView footerViewForSection:i]) { - return [NSString stringWithFormat:@"%@[%ld]", NSStringFromClass([self class]), (long)i]; - } - } - return [super growingNodeSubPath]; -} - -@end - @implementation UIView (GrowingImpression) - (void)growingTrackImpression:(NSString *)eventName { From 55ed788d74b90338e2ee449c6a067bb904964d2f Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 6 Jul 2023 17:42:00 +0800 Subject: [PATCH 009/126] test: update ci --- Example/Example.xcodeproj/project.pbxproj | 150 ------------------ ...IOMeasurementProtocolTableViewController.m | 18 +++ .../Hybrid/gio_hybrideventtest.html | 4 +- .../A0GrowingAnalyticsTest.m | 98 +++++++++--- .../GrowingNodeTests/NodeTest.m | 9 +- .../Helper/ManualTrackHelper.h | 2 - .../Helper/ManualTrackHelper.m | 18 +-- .../Event/A1ViewClickEventsTest.m | 26 +-- .../HybridTests/HybridTest_HostApp.m | 23 +-- .../ModulesTests/HybridTests/HybridTest.m | 1 - .../ProtobufTests/ProtobufDatabaseTest.m | 4 - .../ProtobufTests/ProtobufEventsTest.m | 5 - .../WebCircleTests/WebCircleTest.m | 16 +- .../DatabaseTests/JSONDatabaseTest.m | 2 - Podfile.lock | 2 +- 15 files changed, 141 insertions(+), 237 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index e4d8fba71..49802943e 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -123,7 +123,6 @@ 34AC7ACE279829FC00C0DFA5 /* GrowingUIKitHelpersTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AC7AC82798270500C0DFA5 /* GrowingUIKitHelpersTest.m */; }; 34AC7AD127982BEE00C0DFA5 /* GrowingSwizzleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AC7AD027982BEE00C0DFA5 /* GrowingSwizzleTest.m */; }; 34AE0FE8279AADA7009C8166 /* NSNotificationCenterAutotrackTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AE0FE7279AADA7009C8166 /* NSNotificationCenterAutotrackTest.m */; }; - 34B014BB28C861AD00903B99 /* InvocationHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34BF77B027951D5D00CA18BA /* InvocationHelper.m */; }; 34B2147C27966142004E2CE3 /* DatabaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B2147B27966142004E2CE3 /* DatabaseTest.m */; }; 34B2147E2796664E004E2CE3 /* JSONPersistenceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B2147D2796664E004E2CE3 /* JSONPersistenceTest.m */; }; 34B2148727969562004E2CE3 /* DynamicProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B2148627969562004E2CE3 /* DynamicProxyTest.m */; }; @@ -162,8 +161,6 @@ 34BF77CB279562AC00CA18BA /* ManualTrackHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4962653224DA66B600032551 /* ManualTrackHelper.m */; }; 34C0BF3A277EA7C90047ADC4 /* DataTrafficTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C0BF39277EA7C90047ADC4 /* DataTrafficTest.m */; }; 34C0BF3D277EA9BA0047ADC4 /* MobileDebuggerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C0BF3C277EA9BA0047ADC4 /* MobileDebuggerTest.m */; }; - 34D932FE27BF8C640038430E /* MockEventQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 4962653324DA66B600032551 /* MockEventQueue.m */; }; - 34D9330027BF943F0038430E /* A0GrowingAnalyticsCDPTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D932F927BF8A400038430E /* A0GrowingAnalyticsCDPTest.m */; }; 46B566A91FF28564AA03491F /* Pods_ProtobufTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2E2C01C3AC89773BC3F4BE1 /* Pods_ProtobufTests.framework */; }; 4916270F24E157BB00444AF2 /* GIOPresentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4916270E24E157BB00444AF2 /* GIOPresentViewController.m */; }; 4916271224E157CF00444AF2 /* GIOPagingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4916271124E157CF00444AF2 /* GIOPagingViewController.m */; }; @@ -386,7 +383,6 @@ 34BF77C52795568B00CA18BA /* GrowingKeyChainTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GrowingKeyChainTest.m; sourceTree = ""; }; 34C0BF39277EA7C90047ADC4 /* DataTrafficTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DataTrafficTest.m; sourceTree = ""; }; 34C0BF3C277EA9BA0047ADC4 /* MobileDebuggerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MobileDebuggerTest.m; sourceTree = ""; }; - 34D932F727BF8A400038430E /* GrowingAnalyticsCDPTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GrowingAnalyticsCDPTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 34D932F927BF8A400038430E /* A0GrowingAnalyticsCDPTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = A0GrowingAnalyticsCDPTest.m; sourceTree = ""; }; 3D63F725A31AE372B485C361 /* Pods-HostApplicationTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HostApplicationTests.debug.xcconfig"; path = "../Example/Pods/Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests.debug.xcconfig"; sourceTree = ""; }; 42ADE26B250B292900CA7268 /* HybridTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HybridTest.m; sourceTree = ""; }; @@ -501,13 +497,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 34D932F427BF8A400038430E /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; 6003F587195388D20070C39A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1303,7 +1292,6 @@ 34BA7B2F277C63D00030AC21 /* ProtobufTests.xctest */, 34AB4E47279000F5002549FF /* GrowingAnalyticsStartTests.xctest */, 34BF77B82795561300CA18BA /* HostApplicationTests.xctest */, - 34D932F727BF8A400038430E /* GrowingAnalyticsCDPTests.xctest */, 3494DCF828597E1A00A6CE46 /* GrowingAnalyticsUITests.xctest */, 3494DD0E2859E07500A6CE46 /* ExampleiOS13.app */, 3494DD2D2859E27B00A6CE46 /* GrowingAnalyticsiOS13UITests.xctest */, @@ -1509,23 +1497,6 @@ productReference = 34BF77B82795561300CA18BA /* HostApplicationTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 34D932F627BF8A400038430E /* GrowingAnalyticsCDPTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 34D932FB27BF8A400038430E /* Build configuration list for PBXNativeTarget "GrowingAnalyticsCDPTests" */; - buildPhases = ( - 34D932F327BF8A400038430E /* Sources */, - 34D932F427BF8A400038430E /* Frameworks */, - 34D932F527BF8A400038430E /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = GrowingAnalyticsCDPTests; - productName = GrowingAnalyticsCDPTests; - productReference = 34D932F727BF8A400038430E /* GrowingAnalyticsCDPTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; 6003F589195388D20070C39A /* Example */ = { isa = PBXNativeTarget; buildConfigurationList = 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "Example" */; @@ -1612,11 +1583,6 @@ ProvisioningStyle = Automatic; TestTargetID = 6003F589195388D20070C39A; }; - 34D932F627BF8A400038430E = { - CreatedOnToolsVersion = 13.1; - DevelopmentTeam = SXBU677CPT; - ProvisioningStyle = Automatic; - }; 6003F589195388D20070C39A = { DevelopmentTeam = SXBU677CPT; ProvisioningStyle = Automatic; @@ -1641,7 +1607,6 @@ 04A6FAE624E4F0F4006C72F0 /* CodeCheck */, 04A6FAEB24E50EE0006C72F0 /* CodeFormat */, 34BA7B16277C61250030AC21 /* GrowingAnalyticsTests */, - 34D932F627BF8A400038430E /* GrowingAnalyticsCDPTests */, 34AB4E46279000F5002549FF /* GrowingAnalyticsStartTests */, 34BF77B72795561300CA18BA /* HostApplicationTests */, 34BA7B2E277C63D00030AC21 /* ProtobufTests */, @@ -1723,13 +1688,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 34D932F527BF8A400038430E /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; 6003F588195388D20070C39A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -2274,16 +2232,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 34D932F327BF8A400038430E /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 34D932FE27BF8C640038430E /* MockEventQueue.m in Sources */, - 34B014BB28C861AD00903B99 /* InvocationHelper.m in Sources */, - 34D9330027BF943F0038430E /* A0GrowingAnalyticsCDPTest.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 6003F586195388D20070C39A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -3291,95 +3239,6 @@ }; name = Release; }; - 34D932FC27BF8A400038430E /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - DEVELOPMENT_TEAM = SXBU677CPT; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GENERATE_INFOPLIST_FILE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - "\"$(SRCROOT)/..\"", - ); - IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.0; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.growingio.GrowingAnalyticsCDPTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 34D932FD27BF8A400038430E /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CODE_SIGN_STYLE = Automatic; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEVELOPMENT_TEAM = SXBU677CPT; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GENERATE_INFOPLIST_FILE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - "\"$(SRCROOT)/..\"", - ); - IPHONEOS_DEPLOYMENT_TARGET = 11.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.0; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.growingio.GrowingAnalyticsCDPTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; 6003F5BD195388D20070C39A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -3617,15 +3476,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 34D932FB27BF8A400038430E /* Build configuration list for PBXNativeTarget "GrowingAnalyticsCDPTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 34D932FC27BF8A400038430E /* Debug */, - 34D932FD27BF8A400038430E /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; 6003F585195388D10070C39A /* Build configuration list for PBXProject "Example" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m index cd5e88da2..50ab8e418 100644 --- a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m +++ b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m @@ -44,6 +44,10 @@ - (IBAction)setDataCollectionEnabled:(UISwitch *)sender { #endif } +- (void)buttonAction { + +} + #pragma mark - Table view data source - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { @@ -71,6 +75,20 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger } vHeader.textLabel.text = [self tableView:tableView titleForHeaderInSection:section]; + + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + button.translatesAutoresizingMaskIntoConstraints = NO; + [button setTitle:@"button" forState:UIControlStateNormal]; + [button setBackgroundColor:UIColor.grayColor]; + [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; + [vHeader addSubview:button]; + + [NSLayoutConstraint activateConstraints:@[ + [button.centerYAnchor constraintEqualToAnchor:vHeader.centerYAnchor], + [button.trailingAnchor constraintEqualToAnchor:vHeader.trailingAnchor constant:-15.0f], + [button.widthAnchor constraintEqualToConstant:60.0f], + [button.heightAnchor constraintEqualToConstant:35.0f] + ]]; return vHeader; } diff --git a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html index ecb56fa2d..65217bd00 100644 --- a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html +++ b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html @@ -196,7 +196,8 @@ "globalSequenceId": 99, "eventSequenceId": 3, "textValue": "登录", - "xpath": "/div/button#abc", + "xpath": "/div/button", + "xcontent": "/divClass/buttonId", "index": 1, "hyperlink": "https://www.growingio.com" }; @@ -219,6 +220,7 @@ "eventSequenceId": 3, "textValue": "输入内容", "xpath": "/div/form/input", + "xcontent": "/divClass/formClass/inputId", "index": 1 }; sendMockEvent(event); diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m index 909c17504..88a2e8eeb 100644 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m +++ b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m @@ -19,6 +19,8 @@ #import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" #import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" #import "GrowingTrackerCore/Event/GrowingTrackEventType.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" static NSString * const kGrowingEventDuration = @"event_duration"; @@ -635,19 +637,6 @@ - (void)testSetLocation { [self waitForExpectationsWithTimeout:10.0f handler:nil]; } -- (void)testSetLocationSendVisit { - [[GrowingAutotracker sharedInstance] cleanLocation]; - double latitude = 30.11; - double longitude = 32.22; - [[GrowingAutotracker sharedInstance] setLocation:latitude longitude:longitude]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; - XCTAssertEqual(events.count, 1); - - GrowingVisitEvent *event = (GrowingVisitEvent *)events.firstObject; - XCTAssertEqual(event.latitude, latitude); - XCTAssertEqual(event.longitude, longitude); -} - - (void)testSetDataCollectionEnabled { NSString *eventName = @"name"; [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:NO]; @@ -681,13 +670,84 @@ - (void)testSetDataCollectionEnabled { #pragma mark - GrowingAutoTracker API Test -- (void)testPageVariableToViewControllerTest { - UIViewController *vc = [UIViewController new]; - vc.growingPageAttributes = @{@"key" : @"value"}; - XCTAssertEqualObjects(vc.growingPageAttributes[@"key"], @"value"); +- (void)testAutotrackPageWithoutAttributesNotTrackTest { + UIViewController *controller = [[UIViewController alloc] init]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest"]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithoutAttributesNotTrackTest Test failed : timeout"]; + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertEqual(events.count, 0); + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:3.0f handler:nil]; +} + +- (void)testAutotrackPageWithoutAttributesTest { + UIViewController *controller = [[UIViewController alloc] init]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest"]; + [controller viewDidAppear:NO]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithoutAttributesTest Test failed : timeout"]; + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertEqual(events.count, 1); + + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; + XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); + XCTAssertEqualObjects(event.pageName, @"XCTest"); + XCTAssertEqualObjects(event.attributes[@"key"], nil); + + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); + XCTAssertEqualObjects(dic[@"path"], @"XCTest"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); + + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:3.0f handler:nil]; +} + +- (void)testAutotrackPageWithAttributesNotTrackTest { + UIViewController *controller = [[UIViewController alloc] init]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @"value"}]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithAttributesNotTrackTest Test failed : timeout"]; + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertEqual(events.count, 0); + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:3.0f handler:nil]; +} + +- (void)testAutotrackPageWithAttributesTest { + UIViewController *controller = [[UIViewController alloc] init]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @"value"}]; + [controller viewDidAppear:NO]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithAttributesTest Test failed : timeout"]; + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertEqual(events.count, 1); + + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; + XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); + XCTAssertEqualObjects(event.pageName, @"XCTest"); + XCTAssertEqualObjects(event.attributes[@"key"], @"value"); + + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); + XCTAssertEqualObjects(dic[@"path"], @"XCTest"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + + [expectation fulfill]; + }); - vc.growingPageAttributes = nil; - XCTAssertEqualObjects(vc.growingPageAttributes[@"key"], nil); + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } @end diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m index 474d629f2..cb406252a 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m @@ -45,7 +45,8 @@ -(void)testGrowingUIViewController { [vc1 performSelector:@selector(growingNodeContent)]; [vc1 performSelector:@selector(growingNodeKeyIndex)]; [vc1 performSelector:@selector(growingNodeSubPath)]; - [vc1 performSelector:@selector(growingNodeSubSimilarPath)]; + [vc1 performSelector:@selector(growingNodeSubIndex)]; + [vc1 performSelector:@selector(growingNodeSubSimilarIndex)]; [vc1 performSelector:@selector(growingNodeChilds)]; #pragma clang diagnostic pop } @@ -63,7 +64,8 @@ - (void)testGrowingUICollectionView { [view1 performSelector:@selector(growingNodeChilds)]; [cell performSelector:@selector(growingNodeKeyIndex)]; [cell performSelector:@selector(growingNodeSubPath)]; - [cell performSelector:@selector(growingNodeSubSimilarPath)]; + [cell performSelector:@selector(growingNodeSubIndex)]; + [cell performSelector:@selector(growingNodeSubSimilarIndex)]; [cell performSelector:@selector(growingNodeDonotCircle)]; [cell performSelector:@selector(growingNodeUserInteraction)]; [cell performSelector:@selector(growingViewUserInteraction)]; @@ -79,7 +81,8 @@ - (void)testGrowingUIView { UIView *view2 = [[UIView alloc] init]; [view2 performSelector:@selector(growingNodeKeyIndex)]; [view2 performSelector:@selector(growingNodeSubPath)]; - [view2 performSelector:@selector(growingNodeSubSimilarPath)]; + [view2 performSelector:@selector(growingNodeSubIndex)]; + [view2 performSelector:@selector(growingNodeSubSimilarIndex)]; [view2 performSelector:@selector(growingNodeChilds)]; [view2 performSelector:@selector(growingNodeParent)]; [view2 performSelector:@selector(growingViewNodeIsInvisiable)]; diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h index 2296c9ae7..02a0cff20 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h @@ -31,8 +31,6 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event; -+ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event; - + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event; @end diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m index c4e9008d9..b1d23c8a9 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m @@ -75,8 +75,8 @@ + (BOOL)viewClickEventCheck:(NSDictionary *)event { if (event.count == 0) { return NO; } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"xpath"]]; - NSArray *optional = @[@"textValue", @"index", @"hyperlink", @"query"]; + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"xpath"]]; + NSArray *optional = @[@"path", @"textValue", @"index", @"hyperlink", @"query", @"xindex", @"xcontent"]; return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } @@ -84,17 +84,8 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event { if (event.count == 0) { return NO; } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"xpath"]]; - NSArray *optional = @[@"textValue", @"index", @"hyperlink", @"query"]; - return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; -} - -+ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event { - if (event.count == 0) { - return NO; - } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"path", @"pageShowTimestamp", @"xpath"]]; - NSArray *optional = @[@"index", @"query"]; + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"xpath"]]; + NSArray *optional = @[@"path", @"textValue", @"index", @"hyperlink", @"query", @"xindex", @"xcontent"]; return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } @@ -261,7 +252,6 @@ + (NSArray *)context { @"domain", @"urlScheme", @"appState", - @"globalSequenceId", @"eventSequenceId", @"networkState", @"screenHeight", diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index b5eec1766..3f5e0443a 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -53,13 +53,11 @@ - (void)test01AlertButtonClick { XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], - @"/UITabBarController/UINavigationController[1]/GIOLabelAttributeViewController[0]"); + XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"取消"); XCTAssertEqualObjects(dic[@"xpath"], - @"/Page/UIAlertController/UIView[0]/_UIAlertControllerInterfaceActionGroupView[0]/UIView[0]/" - @"_UIInterfaceActionRepresentationsSequenceView[0]/_UIInterfaceActionSeparatableSequenceView[0]/" - @"UIStackView[0]/_UIInterfaceActionCustomViewRepresentationView[1]/Button[0]"); + @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/_UIAlertControllerPhoneTVMacView/UIView/_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfaceActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/0/0/0/0/0/1/0"); } { @@ -69,10 +67,10 @@ - (void)test01AlertButtonClick { XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], - @"/UITabBarController/UINavigationController[1]/GIOLabelAttributeViewController[0]"); + XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"ShowAlert"); - XCTAssertEqualObjects(dic[@"xpath"], @"/Page/UIButton[3]"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/3"); } } @@ -137,7 +135,8 @@ - (void)test03ButtonWithImageViewClick { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"Food"); - XCTAssertEqualObjects(dic[@"xpath"], @"/Page/UIView[0]/UIButton[0]"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/0"); } } @@ -158,7 +157,8 @@ - (void)test04UIViewButtonClick { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"Fire"); - XCTAssertEqualObjects(dic[@"xpath"], @"/Page/UIView[0]/UIButton[1]"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/1"); } } @@ -180,8 +180,9 @@ - (void)test05UISegmentedControlClick { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"Third"); - XCTAssertEqualObjects(dic[@"xpath"], @"/Page/UISegmentedControl[0]/UISegment[-]"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UISegmentedControl/UISegment"); XCTAssertEqualObjects(dic[@"index"], @(2)); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/-"); } } @@ -208,7 +209,8 @@ - (void)test06ClickCustomContent { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"Water"); - XCTAssertEqualObjects(dic[@"xpath"], @"/Page/UIView[0]/UIButton[1]"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/1"); } [[viewTester usingLabel:@"好的"] tap]; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m index ca539b7b9..4dda091e9 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m @@ -198,6 +198,8 @@ - (void)test09SendMockViewClickEvent { XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); + XCTAssertEqualObjects(dic[@"xpath"], @"/div/button"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/divClass/buttonId"); XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); XCTAssertEqualObjects(dic[@"textValue"], @"登录"); } @@ -218,29 +220,12 @@ - (void)test10SendMockViewChangeEvent { XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); + XCTAssertEqualObjects(dic[@"xpath"], @"/div/form/input"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/divClass/formClass/inputId"); XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); XCTAssertEqualObjects(dic[@"textValue"], @"输入内容"); } -- (void)test11SendMockFormSubmitEvent { - KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; - [self webView:actor.view evaluateJavaScript:@"sendMockFormSubmitEvent()"]; - [viewTester waitForTimeInterval:1]; - - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeFormSubmit]; - XCTAssertEqual(events.count, 1); - - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)events.firstObject; - NSDictionary *dic = event.toDictionary; - XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeFormSubmit); - XCTAssertTrue([ManualTrackHelper hybridFormSubmitEventCheck:dic]); - XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - - XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); - XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); - XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); -} - - (void)test12MockSetUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockSetUserId('xctest_userId_hybrid')"]; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m index 722e925fc..61fab98e1 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m @@ -76,7 +76,6 @@ - (void)testGrowingHybridBridgeProvider { .setAppState(0) .setExtraParams(@{}) .setSessionId(@"testSessionId") - .setGlobalSequenceId(0) .setEventSequenceId(0) .setPlatformVersion(@"testPlatformVersion"); XCTAssertNotNil(builder); diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m index 18d8d969c..d555aefa1 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m @@ -135,7 +135,6 @@ - (void)testDatabaseEventIO { .setDomain(@"com.bundle.id") .setUrlScheme(@"growing.xxxxxx") .setAppState(GrowingAppStateForeground) - .setGlobalSequenceId(999) .setEventSequenceId(999) .setExtraParams(@{@"dataSourceId" : @"123456", @"gioId" : @"654321"}) @@ -153,7 +152,6 @@ - (void)testDatabaseEventIO { .setSdkVersion(@"3.3.3") .setUserKey(@"iPhone") .setDataSourceId(@"1234567890") - .setGioId(@"1111") .build); NSString *uuid = [NSUUID UUID].UUIDString; GrowingEventProtobufPersistence *persistenceIn = [GrowingEventProtobufPersistence persistenceEventWithEvent:event @@ -184,10 +182,8 @@ - (void)testDatabaseEventIO { XCTAssertEqualObjects(event.domain ?: @"", protobuf.domain); XCTAssertEqualObjects(event.urlScheme ?: @"", protobuf.URLScheme); XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), protobuf.appState); - XCTAssertEqual(event.globalSequenceId, protobuf.globalSequenceId); XCTAssertEqual(event.eventSequenceId, protobuf.eventSequenceId); XCTAssertEqualObjects(event.dataSourceId, protobuf.dataSourceId); - XCTAssertEqualObjects(event.gioId, protobuf.gioId); // 3.2.0 XCTAssertEqualObjects(event.networkState ?: @"", protobuf.networkState); XCTAssertEqualObjects(event.appChannel ?: @"", protobuf.appChannel); diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m index eb62f972a..e9696eba2 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m @@ -475,7 +475,6 @@ - (void)testEventConvertToPB_FormSubmit { GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder .setEventType(GrowingEventTypeFormSubmit) .setPath(@"path") - .setPageShowTimestamp(1638857558209) .setXpath(@"xpath") .setIndex(1) .setQuery(@"query") @@ -485,7 +484,6 @@ - (void)testEventConvertToPB_FormSubmit { XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); XCTAssertEqual(GrowingPBEventType_FormSubmit, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); XCTAssertEqualObjects(event.query ?: @"", protobuf.query); @@ -499,7 +497,6 @@ - (void)testEventConvertToPB_FormSubmit { XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); XCTAssertEqual(GrowingPBEventType_FormSubmit, protobuf.eventType); XCTAssertEqualObjects(event.path ?: @"", protobuf.path); - XCTAssertEqual(event.pageShowTimestamp, protobuf.pageShowTimestamp); XCTAssertEqualObjects(event.xpath ?: @"", protobuf.xpath); XCTAssertEqual(event.index, protobuf.index); XCTAssertEqualObjects(event.query ?: @"", protobuf.query); @@ -522,10 +519,8 @@ - (void)contrastOfDefaultParamter:(GrowingBaseEvent *)event protobuf:(GrowingPBE XCTAssertEqualObjects(event.domain ?: @"", protobuf.domain); XCTAssertEqualObjects(event.urlScheme ?: @"", protobuf.URLScheme); XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), protobuf.appState); - XCTAssertEqual(event.globalSequenceId, protobuf.globalSequenceId); XCTAssertEqual(event.eventSequenceId, protobuf.eventSequenceId); XCTAssertEqualObjects(event.extraParams[@"dataSourceId"] ?: @"", protobuf.dataSourceId); - XCTAssertEqualObjects(event.extraParams[@"gioId"] ?: @"", protobuf.gioId); // 3.2.0 XCTAssertEqualObjects(event.networkState ?: @"", protobuf.networkState); XCTAssertEqualObjects(event.appChannel ?: @"", protobuf.appChannel); diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index 2308a6a32..34b0c9cb3 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -33,7 +33,7 @@ @interface GrowingWebCircle (XCTest) -- (NSMutableDictionary *)dictFromPage:(id)aNode xPath:(NSString *)xPath; +- (NSMutableDictionary *)dictFromPage:(GrowingPage *)page; - (unsigned long)getSnapshotKey; @@ -66,6 +66,12 @@ - (void)webSocket:(id )webSocket didReceiveMessage:(id) @end +@interface GrowingPageManager (XCTest) + +- (GrowingPage *)createdViewControllerPage:(UIViewController *)controller; + +@end + @interface WebCircleTest : XCTestCase @end @@ -107,7 +113,7 @@ - (void)testWebCircle { [[GrowingPageManager sharedInstance] createdViewControllerPage:current]; page = [current growingPageObject]; } - XCTAssertNotNil([circle dictFromPage:(id)current xPath:page.path]); + XCTAssertNotNil([circle dictFromPage:page]); XCTAssertNotNil([circle elements]); [circle sendScreenShot]; @@ -131,8 +137,9 @@ - (void)testWebCircleElement { .setZLevel(10) .setContent(@"test") .setXpath(@"Xpath") + .setXindex(@"xindex") .setNodeType(@"Button") - .setParentXPath(@"parentXPath") + .setParentXpath(@"parentXpath") .setIsContainer(YES) .setIndex(10) .setPage(@"page") @@ -147,10 +154,11 @@ - (void)testWebCircleElement { XCTAssertEqualObjects(dic[@"zLevel"], @10); XCTAssertEqualObjects(dic[@"content"], @"test"); XCTAssertEqualObjects(dic[@"xpath"], @"Xpath"); + XCTAssertEqualObjects(dic[@"xindex"], @"xindex"); XCTAssertEqualObjects(dic[@"nodeType"], @"Button"); XCTAssertEqualObjects(dic[@"isContainer"], @1); XCTAssertEqualObjects(dic[@"index"], @10); - XCTAssertEqualObjects(dic[@"parentXPath"], @"parentXPath"); + XCTAssertEqualObjects(dic[@"parentXpath"], @"parentXpath"); XCTAssertEqualObjects(dic[@"page"], @"page"); XCTAssertEqualObjects(dic[@"domain"], [GrowingDeviceInfo currentDeviceInfo].bundleID); } diff --git a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m index 55df2566d..3a0a617d3 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m @@ -129,7 +129,6 @@ - (void)testDatabaseEventIO { .setDomain(@"com.bundle.id") .setUrlScheme(@"growing.xxxxxx") .setAppState(GrowingAppStateForeground) - .setGlobalSequenceId(999) .setEventSequenceId(999) .setExtraParams(@{@"dataSourceId": @"123456", @"gioId": @"654321"}) .setNetworkState(@"5G") @@ -177,7 +176,6 @@ - (void)testDatabaseEventIO { XCTAssertEqualObjects(event.urlScheme ?: @"", jsonObject[@"urlScheme"]); XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), jsonObject[@"appState"]); - XCTAssertEqual(event.globalSequenceId, ((NSNumber *)(jsonObject[@"globalSequenceId"])).longLongValue); XCTAssertEqual(event.eventSequenceId, ((NSNumber *)(jsonObject[@"eventSequenceId"])).longLongValue); // 3.2.0 XCTAssertEqualObjects(event.networkState ?: @"", jsonObject[@"networkState"]); diff --git a/Podfile.lock b/Podfile.lock index 16bca09af..51ee40855 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -147,7 +147,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: 9c4c3c7e33523f3daba012a06f0f419b77e02544 + GrowingAnalytics: 80b480f3c662876f701eea99caf3164661f1aee4 GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 88b144e858f8895f1d84c518642ce34ce0f5aa07 GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 From 2270fac18edaea9692871338030a8fa27432c5f8 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 6 Jul 2023 09:43:05 +0000 Subject: [PATCH 010/126] style: code format --- .../GrowingNode/Category/UITableView+GrowingNode.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m index 4e7cd4ce7..573fa2703 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m @@ -113,7 +113,7 @@ - (NSString *)growingNodeSubIndex { do { view = view.superview; } while (view && ![view isKindOfClass:[UITableView class]]); - + if (view) { UITableView *tableView = (UITableView *)view; for (NSInteger i = 0; i < tableView.numberOfSections; i++) { @@ -125,7 +125,7 @@ - (NSString *)growingNodeSubIndex { } } } - + return [super growingNodeSubIndex]; } From 8057dde60ec14a14c76eb7f702e0edf4c556e4e4 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 6 Jul 2023 18:53:08 +0800 Subject: [PATCH 011/126] test: update ci --- .../Hybrid/gio_hybrideventtest.html | 1 - .../Helper/ManualTrackHelper.h | 2 + .../Helper/ManualTrackHelper.m | 9 ++++ .../HybridTests/HybridTest_HostApp.m | 20 +++++++++ GrowingAnalytics-cdp.podspec | 43 ------------------- 5 files changed, 31 insertions(+), 44 deletions(-) delete mode 100644 GrowingAnalytics-cdp.podspec diff --git a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html index 65217bd00..ff32f2183 100644 --- a/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html +++ b/Example/Example/UICategoryTests/Hybrid/gio_hybrideventtest.html @@ -240,7 +240,6 @@ "referralPage": "http://test-browser.growingio.com/push", "globalSequenceId": 99, "eventSequenceId": 3, - "pageShowTimestamp": 1602485626878, "xpath": "/div/form/input", "index": 1 }; diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h index 02a0cff20..2296c9ae7 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.h @@ -31,6 +31,8 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event; ++ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event; + + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event; @end diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m index b1d23c8a9..f819ce385 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m @@ -89,6 +89,15 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event { return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } ++ (BOOL)hybridFormSubmitEventCheck:(NSDictionary *)event { + if (event.count == 0) { + return NO; + } + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"xpath"]]; + NSArray *optional = @[@"path", @"index", @"query"]; + return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; +} + /// 验证测量协议中通用非必需字段不为空(需在生成事件前赋值对应字段,如userId、userKey等) /// @param event 事件 + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event { diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m index 4dda091e9..23b234ee4 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m @@ -226,6 +226,26 @@ - (void)test10SendMockViewChangeEvent { XCTAssertEqualObjects(dic[@"textValue"], @"输入内容"); } +- (void)test11SendMockFormSubmitEvent { + KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; + [self webView:actor.view evaluateJavaScript:@"sendMockFormSubmitEvent()"]; + [viewTester waitForTimeInterval:1]; + + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeFormSubmit]; + XCTAssertEqual(events.count, 1); + + GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)events.firstObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeFormSubmit); + XCTAssertTrue([ManualTrackHelper hybridFormSubmitEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); + XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); + XCTAssertEqualObjects(dic[@"xpath"], @"/div/form/input"); + XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); +} + - (void)test12MockSetUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockSetUserId('xctest_userId_hybrid')"]; diff --git a/GrowingAnalytics-cdp.podspec b/GrowingAnalytics-cdp.podspec deleted file mode 100644 index 3afda2dd5..000000000 --- a/GrowingAnalytics-cdp.podspec +++ /dev/null @@ -1,43 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'GrowingAnalytics-cdp' - s.version = '3.7.0' - s.summary = 'iOS SDK of GrowingIO.' - s.description = <<-DESC -GrowingAnalytics-cdp基于GrowingAnalytics,同样具备自动采集基本的用户行为事件,比如访问和行为数据等。 -目前支持代码埋点、无埋点、可视化圈选、热图等功能。适用于CDP客户。 - DESC - - s.homepage = 'https://www.growingio.com/' - s.license = { :type => 'Apache2.0', :file => 'LICENSE' } - s.author = { 'GrowingIO' => 'support@growingio.com' } - s.source = { :git => 'https://github.com/growingio/growingio-sdk-ios-autotracker.git', :tag => s.version.to_s } - s.ios.deployment_target = '10.0' - s.osx.deployment_target = '10.12' - s.ios.framework = 'WebKit' - s.requires_arc = true - s.default_subspec = "Autotracker" - s.pod_target_xcconfig = { 'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}" "${PODS_ROOT}/GrowingAnalytics"' } - - s.subspec 'Autotracker' do |autotracker| - autotracker.ios.deployment_target = '10.0' - autotracker.source_files = 'GrowingAutotracker-cdp/**/*{.h,.m,.c,.cpp,.mm}' - autotracker.public_header_files = 'GrowingAutotracker-cdp/*.h' - autotracker.dependency 'GrowingAnalytics/AutotrackerCore', s.version.to_s - - # Modules - autotracker.ios.dependency 'GrowingAnalytics/Hybrid', s.version.to_s - autotracker.ios.dependency 'GrowingAnalytics/MobileDebugger', s.version.to_s - autotracker.ios.dependency 'GrowingAnalytics/WebCircle', s.version.to_s - autotracker.dependency 'GrowingAnalytics/DefaultServices', s.version.to_s - end - - s.subspec 'Tracker' do |tracker| - tracker.source_files = 'GrowingTracker-cdp/**/*{.h,.m,.c,.cpp,.mm}' - tracker.public_header_files = 'GrowingTracker-cdp/*.h' - tracker.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s - - # Modules - tracker.ios.dependency 'GrowingAnalytics/MobileDebugger', s.version.to_s - tracker.dependency 'GrowingAnalytics/DefaultServices', s.version.to_s - end -end From a48efe1e1f80e1ab5b66718518391075428c12a1 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 7 Jul 2023 11:27:44 +0800 Subject: [PATCH 012/126] =?UTF-8?q?refactor:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GrowingNode/GrowingNodeHelper.m | 12 ++++++------ .../GrowingNode/GrowingViewChangeProvider.m | 4 ++-- .../GrowingNode/GrowingViewClickProvider.m | 4 ++-- .../GrowingNode/GrowingViewNode.h | 3 +++ .../GrowingNode/GrowingViewNode.m | 15 +++++++++++++++ Modules/WebCircle/GrowingWebCircle.m | 17 +++++++++++------ Modules/WebCircle/GrowingWebCircleElement.h | 3 +++ Modules/WebCircle/GrowingWebCircleElement.m | 11 ++++++++++- 8 files changed, 52 insertions(+), 17 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 8414f82ba..267152908 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -40,12 +40,12 @@ + (void)recalculateXpath:(UIView *)view continue; } [viewPathArray addObject:node.growingNodeSubPath]; - [xindexArray addObject:node.growingNodeSubIndex]; + [originxindexArray addObject:node.growingNodeSubIndex]; if (isSimilar) { - [originxindexArray addObject:node.growingNodeSubSimilarIndex]; + [xindexArray addObject:node.growingNodeSubSimilarIndex]; isSimilar = NO; } else { - [originxindexArray addObject:node.growingNodeSubIndex]; + [xindexArray addObject:node.growingNodeSubIndex]; } node = node.growingNodeParent; @@ -118,9 +118,9 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA return GrowingViewNode.builder.setView(rootview) .setIndex(-1) .setViewContent([self buildElementContentForNode:rootview]) - .setXpath(@"") - .setXindex(@"") - .setOriginXindex(@"") + .setXpath(rootview.growingNodeSubPath) + .setXindex(rootview.growingNodeSubSimilarIndex) + .setOriginXindex(rootview.growingNodeSubIndex) .setNodeType([self getViewNodeType:rootview]) .build; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index 485b3a12a..d35dcdc59 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -42,8 +42,8 @@ + (void)viewOnChange:(UIView *)view { NSString *pagexindex = pathInfo[@"xindex"]; GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange) .setPath(@"") - .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) + .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) .setIndex(node.index) .setTextValue(node.viewContent); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index 413373ca0..d8b54853c 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -43,8 +43,8 @@ + (void)viewOnClick:(UIView *)view { NSString *pagexindex = pathInfo[@"xindex"]; GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick) .setPath(@"") - .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) + .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) .setIndex(node.index) .setTextValue(node.viewContent); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h index cec11c5b6..a667fa577 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h @@ -33,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *_Nonnull originxindex; // 可点击的父节点xpath @property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXpath; +@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXindex; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; @@ -64,6 +65,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *_Nonnull originxindex; // 可点击的父节点xpath @property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXpath; +@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXindex; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; @@ -78,6 +80,7 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingViewNodeBuilder * (^)(NSString *value))setXindex; - (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXindex; - (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXpath; +- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXindex; - (GrowingViewNodeBuilder * (^)(int value))setIndex; - (GrowingViewNodeBuilder * (^)(int value))setPosition; - (GrowingViewNodeBuilder * (^)(long long value))setTimestamp; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m index 87caa8fce..5dbd740fd 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m @@ -43,6 +43,7 @@ - (instancetype)initWithBuilder:(GrowingViewNodeBuilder *)builder { _xindex = builder.xindex; _originxindex = builder.originxindex; _clickableParentXpath = builder.clickableParentXpath; + _clickableParentXindex = builder.clickableParentXindex; _nodeType = builder.nodeType; _index = builder.index; _position = builder.position; @@ -82,6 +83,7 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { .setXindex(self.xindex) .setOriginXindex(self.originxindex) .setClickableParentXpath(self.clickableParentXpath) + .setClickableParentXindex(self.clickableParentXindex) .setHasListParent(self.hasListParent) .setViewContent(self.viewContent) .setPosition(self.position) @@ -104,6 +106,7 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { } NSString *parentXpath = self.view.growingNodeUserInteraction ? self.xpath : self.clickableParentXpath; + NSString *parentXindex = self.view.growingNodeUserInteraction ? self.xindex : self.clickableParentXindex; NSString *content = view.growingNodeContent; return GrowingViewNode.builder.setView(view) @@ -112,6 +115,7 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { .setXindex([self.originxindex stringByAppendingFormat:@"/%@", view.growingNodeSubSimilarIndex]) .setOriginXindex([self.originxindex stringByAppendingFormat:@"/%@", view.growingNodeSubIndex]) .setClickableParentXpath(parentXpath) + .setClickableParentXindex(parentXindex) .setHasListParent(haslistParent) .setViewContent(content ? [content growingHelper_safeSubStringWithLength:50] : nil) .setPosition((int)view.growingNodeKeyIndex) @@ -158,18 +162,28 @@ @implementation GrowingViewNodeBuilder return self; }; } + +- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXindex { + return ^(NSString *value) { + self->_clickableParentXindex = value; + return self; + }; +} + - (GrowingViewNodeBuilder * (^)(int value))setIndex { return ^(int value) { self->_index = value; return self; }; } + - (GrowingViewNodeBuilder * (^)(int value))setPosition { return ^(int value) { self->_position = value; return self; }; } + - (GrowingViewNodeBuilder * (^)(long long value))setTimestamp { return ^(long long value) { self->_timestamp = value; @@ -183,6 +197,7 @@ @implementation GrowingViewNodeBuilder return self; }; } + - (GrowingViewNodeBuilder * (^)(NSString *value))setNodeType { return ^(NSString *value) { self->_nodeType = value; diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 5ad6954ba..273dde931 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -145,19 +145,24 @@ - (NSMutableDictionary *)dictFromPage:(GrowingPage *)page { - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node { GrowingPage *page = [[GrowingPageManager sharedInstance] findPageByView:node.view]; + GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page]; if (!page) { self.isPageDontShow = YES; GIOLogDebug(@"[GrowingWebCircle] page of view %@ not found", node.view); } + NSDictionary *pathInfo = page.pathInfo; + NSString *pagexpath = pathInfo[@"xpath"]; + NSString *pagexindex = pathInfo[@"xindex"]; GrowingWebCircleElement *element = GrowingWebCircleElement.builder.setRect(node.view.growingNodeFrame) .setContent(node.viewContent) .setZLevel(self.zLevel++) .setIndex(node.index) - .setXpath(node.xpath) - .setXindex(node.xindex) - .setParentXpath(node.clickableParentXpath) + .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) + .setParentXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXpath]) + .setParentXindex([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXindex]) .setNodeType(node.nodeType) - .setPage(page.alias) + .setPage(autotrackPage ? autotrackPage.alias : @"") .build; return [NSMutableDictionary dictionaryWithDictionary:element.toDictionary]; @@ -258,8 +263,8 @@ - (void)fillAllViewsForWebCircle:(NSDictionary *)dataDict completion:(void (^)(N .setIndex(-1) .setViewContent([GrowingNodeHelper buildElementContentForNode:topwindow]) .setXpath(topwindow.growingNodeSubPath) - .setXindex(topwindow.growingNodeSubIndex) - .setOriginXindex(topwindow.growingNodeSubSimilarIndex) + .setXindex(topwindow.growingNodeSubSimilarIndex) + .setOriginXindex(topwindow.growingNodeSubIndex) .setNodeType([GrowingNodeHelper getViewNodeType:topwindow]) .build]; if (self.isPageDontShow) { diff --git a/Modules/WebCircle/GrowingWebCircleElement.h b/Modules/WebCircle/GrowingWebCircleElement.h index 87b79793b..f0b9f51e5 100644 --- a/Modules/WebCircle/GrowingWebCircleElement.h +++ b/Modules/WebCircle/GrowingWebCircleElement.h @@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *_Nonnull xindex; @property (nonatomic, copy, readonly) NSString *_Nonnull nodeType; @property (nonatomic, copy, readonly) NSString *_Nullable parentXpath; +@property (nonatomic, copy, readonly) NSString *_Nullable parentXindex; @property (nonatomic, assign, readonly) BOOL isContainer; @property (nonatomic, assign, readonly) int index; @property (nonatomic, copy, readonly) NSString *_Nonnull page; @@ -53,6 +54,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *_Nonnull xindex; @property (nonatomic, copy, readonly) NSString *_Nonnull nodeType; @property (nonatomic, copy, readonly) NSString *_Nullable parentXpath; +@property (nonatomic, copy, readonly) NSString *_Nullable parentXindex; @property (nonatomic, assign, readonly) BOOL isContainer; @property (nonatomic, assign, readonly) int index; @property (nonatomic, copy, readonly) NSString *_Nonnull page; @@ -64,6 +66,7 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingWebCircleElementBuilder * (^)(NSString *value))setXindex; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setNodeType; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXpath; +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXindex; - (GrowingWebCircleElementBuilder * (^)(BOOL value))setIsContainer; - (GrowingWebCircleElementBuilder * (^)(int value))setIndex; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setPage; diff --git a/Modules/WebCircle/GrowingWebCircleElement.m b/Modules/WebCircle/GrowingWebCircleElement.m index 77ba2bfb1..f23b1a222 100644 --- a/Modules/WebCircle/GrowingWebCircleElement.m +++ b/Modules/WebCircle/GrowingWebCircleElement.m @@ -37,6 +37,7 @@ - (instancetype)initWithBuilder:(GrowingWebCircleElementBuilder *)builder { _isContainer = builder.isContainer; _index = builder.index; _parentXpath = builder.parentXpath; + _parentXindex = builder.parentXindex; _page = builder.page; _domain = [GrowingDeviceInfo currentDeviceInfo].bundleID; } @@ -57,7 +58,8 @@ - (NSDictionary *)toDictionary { dataDict[@"nodeType"] = self.nodeType; dataDict[@"isContainer"] = @(self.isContainer); dataDict[@"index"] = self.index >= 0 ? @(self.index) : nil; - dataDict[@"parentXpath"] = self.parentXpath; + dataDict[@"parentXPath"] = self.parentXpath; + dataDict[@"parentXIndex"] = self.parentXindex; dataDict[@"page"] = self.page; dataDict[@"domain"] = self.domain; return [dataDict copy]; @@ -116,6 +118,13 @@ @implementation GrowingWebCircleElementBuilder }; } +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXindex { + return ^(NSString *value) { + self->_parentXindex = value; + return self; + }; +} + - (GrowingWebCircleElementBuilder * (^)(BOOL value))setIsContainer { return ^(BOOL value) { self->_isContainer = value; From f4d1d39b74ffc43f64b9c88a6836698de28f2f47 Mon Sep 17 00:00:00 2001 From: runner Date: Fri, 7 Jul 2023 03:28:44 +0000 Subject: [PATCH 013/126] style: code format --- Modules/WebCircle/GrowingWebCircle.m | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 273dde931..07cfadd65 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -153,17 +153,18 @@ - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node { NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; NSString *pagexindex = pathInfo[@"xindex"]; - GrowingWebCircleElement *element = GrowingWebCircleElement.builder.setRect(node.view.growingNodeFrame) - .setContent(node.viewContent) - .setZLevel(self.zLevel++) - .setIndex(node.index) - .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) - .setParentXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXpath]) - .setParentXindex([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXindex]) - .setNodeType(node.nodeType) - .setPage(autotrackPage ? autotrackPage.alias : @"") - .build; + GrowingWebCircleElement *element = + GrowingWebCircleElement.builder.setRect(node.view.growingNodeFrame) + .setContent(node.viewContent) + .setZLevel(self.zLevel++) + .setIndex(node.index) + .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) + .setParentXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXpath]) + .setParentXindex([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXindex]) + .setNodeType(node.nodeType) + .setPage(autotrackPage ? autotrackPage.alias : @"") + .build; return [NSMutableDictionary dictionaryWithDictionary:element.toDictionary]; } From 6c7d7ca08474fd446a00847c042516ae45ff276d Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 7 Jul 2023 15:02:27 +0800 Subject: [PATCH 014/126] feat: add autotrackEnabled/ignoreViewClass/ignoreViewClasses --- GrowingAutotracker/GrowingAutotracker.h | 6 ++++ .../GrowingAutotrackConfiguration+Private.h | 33 +++++++++++++++++ .../GrowingAutotrackConfiguration.m | 36 ++++++++++++++++++- .../GrowingNode/Category/UIView+GrowingNode.m | 12 +++++-- .../GrowingRealAutotracker.m | 25 ++++++++++--- .../Public/GrowingAutotrackConfiguration.h | 1 + GrowingTrackerCore/GrowingRealTracker.m | 2 +- .../Manager/GrowingConfigurationManager.m | 5 --- 8 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h diff --git a/GrowingAutotracker/GrowingAutotracker.h b/GrowingAutotracker/GrowingAutotracker.h index b1f04e1e1..3431963b8 100644 --- a/GrowingAutotracker/GrowingAutotracker.h +++ b/GrowingAutotracker/GrowingAutotracker.h @@ -73,6 +73,12 @@ NS_ASSUME_NONNULL_BEGIN /// 同步获取设备id,又称为匿名用户id,SDK 自动生成用来定义唯一设备。 - (NSString *)getDeviceId; +/// 配置忽略追踪的元素类型 +- (void)ignoreViewClass:(Class)clazz; + +/// 配置忽略追踪的元素类型数组 +- (void)ignoreViewClasses:(NSArray *)classes; + ///------------------------------- #pragma mark Track Event ///------------------------------- diff --git a/GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h b/GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h new file mode 100644 index 000000000..4f3c8edf4 --- /dev/null +++ b/GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h @@ -0,0 +1,33 @@ +// +// GrowingAutotrackConfiguration+Private.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/7. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingAutotrackConfiguration (Private) + +@property (nonatomic, strong, readonly) NSMutableSet *ignoreViewClasses; + +- (void)ignoreViewClass:(Class)clazz; +- (void)ignoreViewClasses:(NSArray *)classes; + +@end + +NS_ASSUME_NONNULL_END diff --git a/GrowingAutotrackerCore/GrowingAutotrackConfiguration.m b/GrowingAutotrackerCore/GrowingAutotrackConfiguration.m index 28192e56c..72573a207 100644 --- a/GrowingAutotrackerCore/GrowingAutotrackConfiguration.m +++ b/GrowingAutotrackerCore/GrowingAutotrackConfiguration.m @@ -18,13 +18,47 @@ // limitations under the License. #import "GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h" +#import "GrowingTrackerCore/Utils/GrowingInternalMacros.h" -@implementation GrowingAutotrackConfiguration +@interface GrowingAutotrackConfiguration () + +@property (nonatomic, strong, readwrite) NSMutableSet *ignoreViewClasses; + +@end + +@implementation GrowingAutotrackConfiguration { + GROWING_LOCK_DECLARE(lock); +} + +- (instancetype)initWithProjectId:(NSString *)projectId { + if (self = [super initWithProjectId:projectId]) { + _autotrackEnabled = YES; + _impressionScale = 0.0f; + GROWING_LOCK_INIT(lock); + _ignoreViewClasses = [NSMutableSet set]; + } + + return self; +} - (id)copyWithZone:(NSZone *)zone { GrowingAutotrackConfiguration *configuration = (GrowingAutotrackConfiguration *)[super copyWithZone:zone]; + configuration->_autotrackEnabled = _autotrackEnabled; configuration->_impressionScale = _impressionScale; + configuration->_ignoreViewClasses = _ignoreViewClasses; return configuration; } +- (void)ignoreViewClass:(Class)clazz { + GROWING_LOCK(lock); + [self.ignoreViewClasses addObject:clazz]; + GROWING_UNLOCK(lock); +} + +- (void)ignoreViewClasses:(NSArray *)classes { + GROWING_LOCK(lock); + [self.ignoreViewClasses addObjectsFromArray:classes]; + GROWING_UNLOCK(lock); +} + @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index d8b2fd297..04fe09c64 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -24,7 +24,7 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" -#import "GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h" +#import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" #import "GrowingTrackerCore/Public/GrowingBaseEvent.h" @@ -136,7 +136,7 @@ - (BOOL)growingImpNodeIsVisible { BOOL isInScreen; double impScale = 0.0; GrowingTrackConfiguration *configuration = GrowingConfigurationManager.sharedInstance.trackConfiguration; - if ([configuration isKindOfClass:NSClassFromString(@"GrowingAutotrackConfiguration")]) { + if ([configuration isKindOfClass:[GrowingAutotrackConfiguration class]]) { impScale = ((GrowingAutotrackConfiguration *)configuration).impressionScale; } @@ -177,6 +177,14 @@ - (BOOL)growingNodeDonotTrack { - (BOOL)growingViewDontTrack { // judge self firstly + GrowingTrackConfiguration *configuration = GrowingConfigurationManager.sharedInstance.trackConfiguration; + if ([configuration isKindOfClass:[GrowingAutotrackConfiguration class]]) { + NSSet *ignoreViewClasses = ((GrowingAutotrackConfiguration *)configuration).ignoreViewClasses; + if ([ignoreViewClasses containsObject:[self class]]) { + return YES; + } + } + GrowingIgnorePolicy selfPolicy = self.growingViewIgnorePolicy; if (GrowingIgnoreAll == selfPolicy || GrowingIgnoreSelf == selfPolicy) { return YES; diff --git a/GrowingAutotrackerCore/GrowingRealAutotracker.m b/GrowingAutotrackerCore/GrowingRealAutotracker.m index 3e8c507cf..1bdbaf158 100644 --- a/GrowingAutotrackerCore/GrowingRealAutotracker.m +++ b/GrowingAutotrackerCore/GrowingRealAutotracker.m @@ -29,6 +29,7 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" +#import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" #import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" @@ -36,21 +37,37 @@ #import "GrowingULSwizzle.h" #import "GrowingULViewControllerLifecycle.h" +@interface GrowingRealAutotracker (Private) + +@property (nonatomic, strong) GrowingAutotrackConfiguration *configuration; + +@end + @implementation GrowingRealAutotracker - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions { self = [super initWithConfiguration:configuration launchOptions:launchOptions]; if (self) { - [self addAutoTrackSwizzles]; - [GrowingULViewControllerLifecycle setup]; - [GrowingPageManager.sharedInstance start]; - [GrowingImpressionTrack.sharedInstance start]; + if (self.configuration.autotrackEnabled) { + [self addAutoTrackSwizzles]; + [GrowingULViewControllerLifecycle setup]; + [GrowingPageManager.sharedInstance start]; + [GrowingImpressionTrack.sharedInstance start]; + } } return self; } +- (void)ignoreViewClass:(Class)clazz { + [self.configuration ignoreViewClass:clazz]; +} + +- (void)ignoreViewClasses:(NSArray *)classes { + [self.configuration ignoreViewClasses:classes]; +} + - (void)autotrackPage:(UIViewController *)controller alias:(NSString *)alias { [GrowingPageManager.sharedInstance autotrackPage:controller alias:alias attributes:nil]; } diff --git a/GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h b/GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h index 3eb123e83..1a0acb8f7 100644 --- a/GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h +++ b/GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h @@ -30,6 +30,7 @@ typedef NS_ENUM(NSUInteger, GrowingIgnorePolicy) { @interface GrowingAutotrackConfiguration : GrowingTrackConfiguration +@property (nonatomic, assign) BOOL autotrackEnabled; @property (nonatomic, assign) float impressionScale; @end diff --git a/GrowingTrackerCore/GrowingRealTracker.m b/GrowingTrackerCore/GrowingRealTracker.m index 29ee3f81a..31b8e9b72 100644 --- a/GrowingTrackerCore/GrowingRealTracker.m +++ b/GrowingTrackerCore/GrowingRealTracker.m @@ -56,7 +56,7 @@ - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration if (self) { _configuration = [configuration copyWithZone:nil]; _launchOptions = [launchOptions copy]; - GrowingConfigurationManager.sharedInstance.trackConfiguration = self.configuration; + GrowingConfigurationManager.sharedInstance.trackConfiguration = _configuration; if (configuration.urlScheme.length > 0) { [GrowingDeviceInfo configUrlScheme:configuration.urlScheme.copy]; } diff --git a/GrowingTrackerCore/Manager/GrowingConfigurationManager.m b/GrowingTrackerCore/Manager/GrowingConfigurationManager.m index 493e78003..eb2dce0d7 100644 --- a/GrowingTrackerCore/Manager/GrowingConfigurationManager.m +++ b/GrowingTrackerCore/Manager/GrowingConfigurationManager.m @@ -21,7 +21,6 @@ #import "GrowingTrackerCore/Public/GrowingTrackConfiguration.h" @implementation GrowingConfigurationManager -@synthesize trackConfiguration = _trackConfiguration; + (instancetype)sharedInstance { static id _sharedInstance = nil; @@ -33,8 +32,4 @@ + (instancetype)sharedInstance { return _sharedInstance; } -- (void)setTrackConfiguration:(GrowingTrackConfiguration *)configuration { - _trackConfiguration = [configuration copyWithZone:nil]; -} - @end From f7aad9aeaf82df584d4bb9d10397cdf9fa981f6d Mon Sep 17 00:00:00 2001 From: runner Date: Fri, 7 Jul 2023 07:03:47 +0000 Subject: [PATCH 015/126] style: code format --- .../GrowingNode/Category/UIView+GrowingNode.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index 04fe09c64..7e27a7d60 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -20,11 +20,11 @@ #import "GrowingAutotrackerCore/Autotrack/GrowingPropertyDefine.h" #import "GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.h" #import "GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.h" +#import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" -#import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" #import "GrowingTrackerCore/Public/GrowingBaseEvent.h" From 225063c66d327cc348c6095d5a46b68f21d26712 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 7 Jul 2023 16:34:30 +0800 Subject: [PATCH 016/126] =?UTF-8?q?refactor:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebCircleTests/WebCircleTest.m | 2 +- .../GrowingNode/GrowingNodeHelper.m | 4 +-- Modules/WebCircle/GrowingWebCircle.m | 28 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index 34b0c9cb3..5ec335940 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -158,7 +158,7 @@ - (void)testWebCircleElement { XCTAssertEqualObjects(dic[@"nodeType"], @"Button"); XCTAssertEqualObjects(dic[@"isContainer"], @1); XCTAssertEqualObjects(dic[@"index"], @10); - XCTAssertEqualObjects(dic[@"parentXpath"], @"parentXpath"); + XCTAssertEqualObjects(dic[@"parentXPath"], @"parentXpath"); XCTAssertEqualObjects(dic[@"page"], @"page"); XCTAssertEqualObjects(dic[@"domain"], [GrowingDeviceInfo currentDeviceInfo].bundleID); } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 267152908..db51f4a15 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -53,7 +53,7 @@ + (void)recalculateXpath:(UIView *)view NSString * (^toStringBlock)(NSArray *) = ^(NSArray *array) { NSArray *reverse = array.reverseObjectEnumerator.allObjects; - return [@"/" stringByAppendingString:[reverse componentsJoinedByString:@"/"]]; + return [reverse componentsJoinedByString:@"/"]; }; NSString *xpath = toStringBlock(viewPathArray); @@ -94,7 +94,7 @@ + (NSString *)buildElementContentForNode:(id _Nullable)view { + (GrowingViewNode *)getViewNode:(UIView *)view { NSPointerArray *weakArray = [NSPointerArray weakObjectsPointerArray]; GrowingViewNode *viewNode = [self getTopViewNode:view array:weakArray]; - for (int i = (int)weakArray.count - 1; i >= 0; i--) { + for (int i = (int)weakArray.count - 2; i >= 0; i--) { UIView *parent = [weakArray pointerAtIndex:i]; if (parent) { viewNode = [viewNode appendNode:parent isRecalculate:NO]; diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 07cfadd65..1d65e1cdb 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -153,19 +153,21 @@ - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node { NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; NSString *pagexindex = pathInfo[@"xindex"]; - GrowingWebCircleElement *element = - GrowingWebCircleElement.builder.setRect(node.view.growingNodeFrame) - .setContent(node.viewContent) - .setZLevel(self.zLevel++) - .setIndex(node.index) - .setXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@%@", pagexindex, node.xindex]) - .setParentXpath([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXpath]) - .setParentXindex([NSString stringWithFormat:@"%@%@", pagexpath, node.clickableParentXindex]) - .setNodeType(node.nodeType) - .setPage(autotrackPage ? autotrackPage.alias : @"") - .build; - + GrowingWebCircleElementBuilder *builder = GrowingWebCircleElement.builder + .setRect(node.view.growingNodeFrame) + .setContent(node.viewContent) + .setZLevel(self.zLevel++) + .setIndex(node.index) + .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) + .setNodeType(node.nodeType) + .setPage(autotrackPage ? autotrackPage.alias : @""); + if (node.clickableParentXpath) { + builder = builder.setParentXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.clickableParentXpath]) + .setParentXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.clickableParentXindex]); + } + GrowingWebCircleElement *element = builder.build; + return [NSMutableDictionary dictionaryWithDictionary:element.toDictionary]; } From 6862594b142f2b310fb437e49a721fcdf2182147 Mon Sep 17 00:00:00 2001 From: runner Date: Fri, 7 Jul 2023 08:35:20 +0000 Subject: [PATCH 017/126] style: code format --- Modules/WebCircle/GrowingWebCircle.m | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 1d65e1cdb..81abcea08 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -153,21 +153,21 @@ - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node { NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; NSString *pagexindex = pathInfo[@"xindex"]; - GrowingWebCircleElementBuilder *builder = GrowingWebCircleElement.builder - .setRect(node.view.growingNodeFrame) - .setContent(node.viewContent) - .setZLevel(self.zLevel++) - .setIndex(node.index) - .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) - .setNodeType(node.nodeType) - .setPage(autotrackPage ? autotrackPage.alias : @""); + GrowingWebCircleElementBuilder *builder = + GrowingWebCircleElement.builder.setRect(node.view.growingNodeFrame) + .setContent(node.viewContent) + .setZLevel(self.zLevel++) + .setIndex(node.index) + .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) + .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) + .setNodeType(node.nodeType) + .setPage(autotrackPage ? autotrackPage.alias : @""); if (node.clickableParentXpath) { builder = builder.setParentXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.clickableParentXpath]) - .setParentXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.clickableParentXindex]); + .setParentXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.clickableParentXindex]); } GrowingWebCircleElement *element = builder.build; - + return [NSMutableDictionary dictionaryWithDictionary:element.toDictionary]; } From 542a5a79f3b06021aee5b9806346f6e21d7fd7c9 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 10 Jul 2023 10:39:10 +0800 Subject: [PATCH 018/126] test: update ci --- Example/Example.xcodeproj/project.pbxproj | 4 +- .../A0GrowingAnalyticsCDPTest.m | 657 ------------------ .../A0GrowingAnalyticsTest.m | 2 +- 3 files changed, 2 insertions(+), 661 deletions(-) delete mode 100644 Example/GrowingAnalyticsTests/A0GrowingAnalyticsCDPTest.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 49802943e..38ee4c6b2 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -383,8 +383,7 @@ 34BF77C52795568B00CA18BA /* GrowingKeyChainTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GrowingKeyChainTest.m; sourceTree = ""; }; 34C0BF39277EA7C90047ADC4 /* DataTrafficTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DataTrafficTest.m; sourceTree = ""; }; 34C0BF3C277EA9BA0047ADC4 /* MobileDebuggerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MobileDebuggerTest.m; sourceTree = ""; }; - 34D932F927BF8A400038430E /* A0GrowingAnalyticsCDPTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = A0GrowingAnalyticsCDPTest.m; sourceTree = ""; }; - 3D63F725A31AE372B485C361 /* Pods-HostApplicationTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HostApplicationTests.debug.xcconfig"; path = "../Example/Pods/Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests.debug.xcconfig"; sourceTree = ""; }; + 3D63F725A31AE372B485C361 /* Pods-HostApplicationTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HostApplicationTests.debug.xcconfig"; path = "Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests.debug.xcconfig"; sourceTree = ""; }; 42ADE26B250B292900CA7268 /* HybridTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HybridTest.m; sourceTree = ""; }; 42F5EA0EFE2552358C35A0F5 /* Pods_HostApplicationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HostApplicationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4916270D24E157BB00444AF2 /* GIOPresentViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GIOPresentViewController.h; sourceTree = ""; }; @@ -1013,7 +1012,6 @@ isa = PBXGroup; children = ( 047BF3A224F638BB0028FE94 /* A0GrowingAnalyticsTest.m */, - 34D932F927BF8A400038430E /* A0GrowingAnalyticsCDPTest.m */, 4962652C24DA66B600032551 /* Helper */, 34BF77B92795561300CA18BA /* HostApplicationTests */, 3494DCF928597E1A00A6CE46 /* GrowingAnalyticsUITests */, diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsCDPTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsCDPTest.m deleted file mode 100644 index 4045c3a18..000000000 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsCDPTest.m +++ /dev/null @@ -1,657 +0,0 @@ -// -// GrowingAnalyticsCDPTests.m -// GrowingAnalytics -// -// Created by YoloMao on 2022/2/18. -// Copyright (C) 2021 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import -#import "GrowingAutotracker.h" -#import "GrowingTracker.h" -#import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" -#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" -#import "GrowingTrackerCore/Event/GrowingEventManager.h" -#import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" -#import "GrowingTrackerCore/Event/GrowingTrackEventType.h" -#import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" -#import "GrowingTrackerCore/Thread/GrowingThread.h" -#import "InvocationHelper.h" -#import "MockEventQueue.h" - -static NSString *const kGrowingEventDuration = @"event_duration"; - -@interface A0GrowingAnalyticsCDPTest : XCTestCase - -@end - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnonnull" - -@implementation A0GrowingAnalyticsCDPTest - -+ (void)setUp { - GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; - configuration.dataSourceId = @"test"; - configuration.idMappingEnabled = YES; - configuration.sessionInterval = 10.0f; - configuration.urlScheme = @"growing.xctest"; - [GrowingAutotracker startWithConfiguration:configuration launchOptions:nil]; - [GrowingTracker startWithConfiguration:configuration launchOptions:nil]; -} - -- (void)setUp { - [MockEventQueue.sharedQueue cleanQueue]; - [[GrowingEventManager sharedInstance] addInterceptor:self]; -} - -- (void)tearDown { - [[GrowingEventManager sharedInstance] removeInterceptor:self]; -} - -#pragma mark - GrowingEventInterceptor - -- (void)growingEventManagerEventDidBuild:(GrowingBaseEvent *)event { - XCTAssertTrue([NSThread currentThread] == [GrowingThread sharedThread]); -} - -#pragma mark - GrowingCoreKit API Test - -- (void)testSetUserId { - [[GrowingAutotracker sharedInstance] cleanLoginUserId]; - NSString *userId = @"123456789"; - [[GrowingAutotracker sharedInstance] setLoginUserId:userId]; - - [GrowingDispatchManager - dispatchInGrowingThread:^{ - XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, userId); - } - waitUntilDone:YES]; - - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; - XCTAssertEqual(events.count, 1); -} - -- (void)testClearUserId { - [[GrowingAutotracker sharedInstance] cleanLoginUserId]; - - [GrowingDispatchManager - dispatchInGrowingThread:^{ - XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, nil); - } - waitUntilDone:YES]; -} - -- (void)testSetUserIdAndUserKeyTest { - [[GrowingAutotracker sharedInstance] cleanLoginUserId]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"setUserIdAndUserKey Test failed : timeout"]; - expectation.expectedFulfillmentCount = 2; - - NSString *userId = @"123456789"; - [[GrowingAutotracker sharedInstance] setLoginUserId:userId userKey:@"number"]; - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, userId); - XCTAssertEqualObjects([GrowingSession currentSession].loginUserKey, @"number"); - [expectation fulfill]; - }]; - - userId = @"223344"; - [[GrowingAutotracker sharedInstance] setLoginUserId:userId]; - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, userId); - XCTAssertEqualObjects([GrowingSession currentSession].loginUserKey, nil); - [expectation fulfill]; - }]; - [self waitForExpectationsWithTimeout:10.0f handler:nil]; -} - -- (void)testSetLoginUserAttributes { - { - [[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@"key": @"value"}]; - NSArray *events = - [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; - XCTAssertEqual(events.count, 1); - - GrowingLoginUserAttributesEvent *event = (GrowingLoginUserAttributesEvent *)events.firstObject; - XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - } - - { - [MockEventQueue.sharedQueue cleanQueue]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wincompatible-pointer-types" -#pragma clang diagnostic ignored "-Wobjc-literal-conversion" - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@"value"]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@1: @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@"key": @1}]); -#pragma clang diagnostic pop - NSArray *events = - [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; - XCTAssertEqual(events.count, 0); - } -} - -- (void)testTrackCustomEvent { - { - [[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName"]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertEqualObjects(event.attributes[@"key"], nil); - } - - { - [MockEventQueue.sharedQueue cleanQueue]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-literal-conversion" -#pragma clang diagnostic ignored "-Wincompatible-pointer-types" - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@""]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@1]); -#pragma clang diagnostic pop - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } -} - -- (void)testTrackCustomEventWithAttributes { - { - [[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" withAttributes:@{@"key": @"value"}]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - } - - { - [MockEventQueue.sharedQueue cleanQueue]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wincompatible-pointer-types" -#pragma clang diagnostic ignored "-Wobjc-literal-conversion" - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:nil withAttributes:@{@"key": @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"" withAttributes:@{@"key": @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@1 withAttributes:@{@"key": @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" withAttributes:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" withAttributes:@"value"]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" - withAttributes:@{ - @1: @"value" - }]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" - withAttributes:@{ - @"key": @1 - }]); -#pragma clang diagnostic pop - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } -} - -- (void)testTrackTimer { - { - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; - - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertEqualObjects(event.attributes[@"key"], nil); - XCTAssertNotNil(event.attributes[kGrowingEventDuration]); - } - - { - // wrong eventName - [MockEventQueue.sharedQueue cleanQueue]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-literal-conversion" -#pragma clang diagnostic ignored "-Wincompatible-pointer-types" - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerStart:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerStart:@""]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerStart:@1]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerPause:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerPause:@""]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerPause:@1]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerResume:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerResume:@""]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerResume:@1]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@""]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@1]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] removeTimer:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] removeTimer:@""]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] removeTimer:@1]); -#pragma clang diagnostic pop - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } - - { - // wrong timerId - [MockEventQueue.sharedQueue cleanQueue]; - [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName"]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - - [[GrowingAutotracker sharedInstance] clearTrackTimer]; - } - - { - // remove timer - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] removeTimer:timerId]; - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } - - { - // clear all timers - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] clearTrackTimer]; - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } - - { - // pause - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; - sleep(1); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertLessThan(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 1.0); - } - - { - // pause timer that not exist - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerPause:@"eventName"]); - - // pause twice - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerPause:timerId]); - - [[GrowingAutotracker sharedInstance] clearTrackTimer]; - } - - { - // pause + resume - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; - [[GrowingAutotracker sharedInstance] trackTimerResume:timerId]; - sleep(1); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, - 0.6); // sleep 不准 - } - - { - // resume timer that not exist - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerResume:@"eventName"]); - - // resume twice - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; - [[GrowingAutotracker sharedInstance] trackTimerResume:timerId]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerResume:timerId]); - - [[GrowingAutotracker sharedInstance] clearTrackTimer]; - } - - { - // timer all pause & all resume - [MockEventQueue.sharedQueue cleanQueue]; - - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - - [GrowingSession.currentSession performSelector:@selector(applicationDidEnterBackground)]; - NSNumber *sessionInterval = [GrowingSession.currentSession safePerformSelector:@selector(sessionInterval)]; - sleep((int)(sessionInterval.longLongValue / 1000LL) + 1); - - NSString *oldSessionId = GrowingSession.currentSession.sessionId; - [GrowingSession.currentSession performSelector:@selector(applicationDidBecomeActive)]; - - sleep(1); // 2 > duration > 1 - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, - 0.6); // sleep 不准 - // 不会算上前后台切换的时间 - XCTAssertLessThan(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 2.0); - } -} - -- (void)testTrackTimerWithAttributes { - { - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; - - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - XCTAssertNotNil(event.attributes[kGrowingEventDuration]); - } - - { - // wrong timerId - [MockEventQueue.sharedQueue cleanQueue]; - [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@{@"key": @"value"}]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - - [[GrowingAutotracker sharedInstance] clearTrackTimer]; - } - - { - // remove timer - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] removeTimer:timerId]; - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } - - { - // clear all timers - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); - [[GrowingAutotracker sharedInstance] clearTrackTimer]; - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } - - { - // pause - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; - sleep(1); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - XCTAssertLessThan(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 1.0); - } - - { - // pause + resume - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; - [[GrowingAutotracker sharedInstance] trackTimerResume:timerId]; - sleep(1); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, - 0.6); // sleep 不准 - } - - { - [MockEventQueue.sharedQueue cleanQueue]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wincompatible-pointer-types" -#pragma clang diagnostic ignored "-Wobjc-literal-conversion" - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:nil withAttributes:@{@"key": @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"" withAttributes:@{@"key": @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@1 withAttributes:@{@"key": @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@"value"]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" - withAttributes:@{ - @1: @"value" - }]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@{@"key": @1}]); -#pragma clang diagnostic pop - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } -} - -- (void)testTrackTimerWithAttributesBuilder { - { - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setString:@"value" forKey:@"key"]; - [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@"key2"]; - [builder setArray:@[@1, @2, @3] forKey:@"key3"]; - [builder setArray:@[@[@"1"], @[@"2"], @[@"3"]] forKey:@"key4"]; - [builder setArray:@[@{@"value": @"key"}, @{@"value": @"key"}, @{@"value": @"key"}] forKey:@"key5"]; - [builder setArray:@[NSObject.new, NSObject.new, NSObject.new] forKey:@"key6"]; - [builder setArray:@[NSNull.new, NSNull.new, NSNull.new] forKey:@"key7"]; - [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@""]; - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 1); - - GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; - XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - XCTAssertEqualObjects(event.attributes[@"key2"], @"value1||value2||value3"); - XCTAssertEqualObjects(event.attributes[@"key3"], @"1||2||3"); - XCTAssertEqualObjects(event.attributes[@"key4"], @"(\n 1\n)||(\n 2\n)||(\n 3\n)"); - XCTAssertEqualObjects(event.attributes[@"key5"], - @"{\n value = key;\n}" - @"||{\n value = key;\n}" - @"||{\n value = key;\n}"); - XCTAssertNotNil(event.attributes[@"key6"]); - XCTAssertEqualObjects(event.attributes[@"key7"], @"||||"); - XCTAssertEqualObjects(event.attributes[@""], @"value1||value2||value3"); - XCTAssertNotNil(event.attributes[kGrowingEventDuration]); - } - - { - [MockEventQueue.sharedQueue cleanQueue]; - NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wincompatible-pointer-types" -#pragma clang diagnostic ignored "-Wobjc-literal-conversion" - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setString:@"value" forKey:@"key"]; - [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@"key2"]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:nil withAttributes:builder.build]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"" withAttributes:builder.build]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@1 withAttributes:builder.build]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:nil]); - - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setString:nil forKey:@"key"]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setString:@1 forKey:@"key"]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setString:@"value" forKey:nil]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setString:@"value" forKey:@1]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setArray:nil forKey:@"key"]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setArray:@[] forKey:@"key"]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setArray:@"value" forKey:@"key"]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setArray:@[@"value1", @"value2", @"value3"] forKey:nil]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } - { - GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; - [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@1]; - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]); - } -#pragma clang diagnostic pop - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; - XCTAssertEqual(events.count, 0); - } -} - -- (void)testGetDeviceId { - XCTAssertNotNil([[GrowingAutotracker sharedInstance] getDeviceId]); -} - -- (void)testGetSessionId { - XCTAssertNotNil([[GrowingSession currentSession] sessionId]); -} - -- (void)testSetLocation { - double latitude = 31.111111111; - double longitude = 32.2222222222; - [[GrowingAutotracker sharedInstance] setLocation:latitude longitude:longitude]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"testCleanLocation Test failed : timeout"]; - expectation.expectedFulfillmentCount = 2; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqual([GrowingSession currentSession].latitude, latitude); - XCTAssertEqual([GrowingSession currentSession].longitude, longitude); - - [expectation fulfill]; - }]; - - [[GrowingAutotracker sharedInstance] cleanLocation]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqual([GrowingSession currentSession].latitude, 0); - XCTAssertEqual([GrowingSession currentSession].longitude, 0); - - [expectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:10.0f handler:nil]; -} - -- (void)testSetLocationSendVisit { - [[GrowingAutotracker sharedInstance] cleanLocation]; - double latitude = 30.11; - double longitude = 32.22; - [[GrowingAutotracker sharedInstance] setLocation:latitude longitude:longitude]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; - XCTAssertEqual(events.count, 1); - - GrowingVisitEvent *event = (GrowingVisitEvent *)events.firstObject; - XCTAssertEqual(event.latitude, latitude); - XCTAssertEqual(event.longitude, longitude); -} - -- (void)testSetDataCollectionEnabled { - NSString *eventName = @"name"; - [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:NO]; - - [[GrowingAutotracker sharedInstance] trackCustomEvent:eventName]; - [GrowingDispatchManager - dispatchInGrowingThread:^{ - NSArray *events = MockEventQueue.sharedQueue.allEvent; - XCTAssertEqual(events.count, 0); - } - waitUntilDone:YES]; - - [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:YES]; - [GrowingDispatchManager - dispatchInGrowingThread:^{ - NSArray *events = MockEventQueue.sharedQueue.allEvent; - XCTAssertEqual(events.count, 1); // VISIT - - GrowingBaseEvent *event = [MockEventQueue.sharedQueue lastEventFor:GrowingEventTypeVisit]; - XCTAssertTrue([event isKindOfClass:[GrowingVisitEvent class]]); - } - waitUntilDone:YES]; - - [[GrowingAutotracker sharedInstance] trackCustomEvent:eventName]; - [GrowingDispatchManager - dispatchInGrowingThread:^{ - NSArray *events = MockEventQueue.sharedQueue.allEvent; - XCTAssertEqual(events.count, 2); // VISIT + CUSTOM - - GrowingBaseEvent *event = [MockEventQueue.sharedQueue lastEventFor:GrowingEventTypeCustom]; - XCTAssertTrue([event isKindOfClass:[GrowingCustomEvent class]]); - GrowingCustomEvent *customEvent = (GrowingCustomEvent *)event; - XCTAssertEqualObjects(customEvent.eventName, eventName); - } - waitUntilDone:YES]; -} - -@end - -#pragma clang diagnostic pop diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m index 88a2e8eeb..39fa2953f 100644 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m +++ b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m @@ -69,7 +69,7 @@ - (void)testSetUserId { } waitUntilDone:YES]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; - XCTAssertEqual(events.count, 1); + XCTAssertEqual(events.count, 0); } - (void)testClearUserId { From 00b3c75897d9dd6dfff6d635aa64eb44e8ad9f8a Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 10 Jul 2023 11:24:06 +0800 Subject: [PATCH 019/126] test: update ci --- Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m | 4 ++++ .../TrackerCoreTests/UtilsTests/DeviceInfoTest.m | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m index 39fa2953f..0ed4e8aaa 100644 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m +++ b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m @@ -21,6 +21,7 @@ #import "GrowingTrackerCore/Event/GrowingTrackEventType.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" +#import "GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h" static NSString * const kGrowingEventDuration = @"event_duration"; @@ -34,6 +35,9 @@ @interface A0GrowingAnalyticsTest : XCTestCase @implementation A0GrowingAnalyticsTest + (void)setUp { + [[GrowingPersistenceDataProvider sharedInstance] setLoginUserId:nil]; + [[GrowingPersistenceDataProvider sharedInstance] setLoginUserKey:nil]; + GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; configuration.dataSourceId = @"test"; configuration.idMappingEnabled = YES; diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m index fe966c367..f8d43a2cb 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m @@ -41,7 +41,6 @@ - (void)testGrowingDeviceInfoPrivateMethods { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" GrowingDeviceInfo *deviceInfo = GrowingDeviceInfo.currentDeviceInfo; - XCTAssertNoThrow([deviceInfo safePerformSelector:@selector(handleStatusBarOrientationChange)]); XCTAssertNoThrow([deviceInfo safePerformSelector:@selector(applicationDidBecomeActive)]); XCTAssertNoThrow([deviceInfo safePerformSelector:@selector(applicationWillResignActive)]); XCTAssertNoThrow([deviceInfo safePerformSelector:@selector(updateAppState)]); From 00ba693c1234af745495802a66b5491eeba188e9 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 10 Jul 2023 11:46:08 +0800 Subject: [PATCH 020/126] test: update ci --- .../ModulesTests/ProtobufTests/ProtobufDatabaseTest.m | 6 +++--- .../ServicesTests/DatabaseTests/JSONDatabaseTest.m | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m index d555aefa1..24bcc66ff 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m @@ -136,8 +136,6 @@ - (void)testDatabaseEventIO { .setUrlScheme(@"growing.xxxxxx") .setAppState(GrowingAppStateForeground) .setEventSequenceId(999) - .setExtraParams(@{@"dataSourceId" : @"123456", - @"gioId" : @"654321"}) .setNetworkState(@"5G") .setScreenHeight(1334) .setScreenWidth(750) @@ -183,7 +181,6 @@ - (void)testDatabaseEventIO { XCTAssertEqualObjects(event.urlScheme ?: @"", protobuf.URLScheme); XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), protobuf.appState); XCTAssertEqual(event.eventSequenceId, protobuf.eventSequenceId); - XCTAssertEqualObjects(event.dataSourceId, protobuf.dataSourceId); // 3.2.0 XCTAssertEqualObjects(event.networkState ?: @"", protobuf.networkState); XCTAssertEqualObjects(event.appChannel ?: @"", protobuf.appChannel); @@ -200,6 +197,9 @@ - (void)testDatabaseEventIO { XCTAssertEqualObjects(event.sdkVersion ?: @"", protobuf.sdkVersion); // 3.3.0 XCTAssertEqualObjects(event.userKey ?: @"", protobuf.userKey); + // 3.5.0 + XCTAssertEqualObjects(event.dataSourceId ?: @"", protobuf.dataSourceId); + // CUSTOM XCTAssertEqual(GrowingPBEventType_Custom, protobuf.eventType); XCTAssertEqualObjects(event.eventName ?: @"", protobuf.eventName); XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); diff --git a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m index 3a0a617d3..c79d41dc9 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m @@ -130,7 +130,6 @@ - (void)testDatabaseEventIO { .setUrlScheme(@"growing.xxxxxx") .setAppState(GrowingAppStateForeground) .setEventSequenceId(999) - .setExtraParams(@{@"dataSourceId": @"123456", @"gioId": @"654321"}) .setNetworkState(@"5G") .setScreenHeight(1334) .setScreenWidth(750) @@ -144,6 +143,7 @@ - (void)testDatabaseEventIO { .setLongitude(32.22) .setSdkVersion(@"3.3.3") .setUserKey(@"iPhone") + .setDataSourceId(@"1234567890") .build); NSString *uuid = [NSUUID UUID].UUIDString; GrowingEventJSONPersistence *persistenceIn = [GrowingEventJSONPersistence persistenceEventWithEvent:event @@ -192,6 +192,8 @@ - (void)testDatabaseEventIO { XCTAssertEqualObjects(event.sdkVersion ?: @"", jsonObject[@"sdkVersion"]); // 3.3.0 XCTAssertEqualObjects(event.userKey ?: @"", jsonObject[@"userKey"]); + // 3.5.0 + XCTAssertEqualObjects(event.dataSourceId ?: @"", jsonObject[@"dataSourceId"]); // CUSTOM XCTAssertEqualObjects(event.eventName ?: @"", jsonObject[@"eventName"]); XCTAssertEqualObjects(event.attributes ?: @{}, jsonObject[@"attributes"]); From ae7f66c0960dfd86682e95efa9f1458ddd12898c Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 10 Jul 2023 18:57:54 +0800 Subject: [PATCH 021/126] =?UTF-8?q?refactor:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/Example.xcodeproj/project.pbxproj | 6 + .../PageEvent/GIOPageEventViewController.h | 2 +- .../PageEvent/GIOPageEventViewController.m | 42 +++- .../GrowingAutotrackPageViewController.h | 37 ++++ .../GrowingAutotrackPageViewController.m | 80 +++++++ .../Storyboard/MeasurementProtocol.storyboard | 207 ++++++++++++------ .../Page/GrowingPageManager.m | 15 +- 7 files changed, 310 insertions(+), 79 deletions(-) create mode 100644 Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.h create mode 100644 Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 38ee4c6b2..d20749b88 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -161,6 +161,7 @@ 34BF77CB279562AC00CA18BA /* ManualTrackHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4962653224DA66B600032551 /* ManualTrackHelper.m */; }; 34C0BF3A277EA7C90047ADC4 /* DataTrafficTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C0BF39277EA7C90047ADC4 /* DataTrafficTest.m */; }; 34C0BF3D277EA9BA0047ADC4 /* MobileDebuggerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C0BF3C277EA9BA0047ADC4 /* MobileDebuggerTest.m */; }; + 34ECFDBF2A5C082A0059F87C /* GrowingAutotrackPageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34ECFDBE2A5C082A0059F87C /* GrowingAutotrackPageViewController.m */; }; 46B566A91FF28564AA03491F /* Pods_ProtobufTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2E2C01C3AC89773BC3F4BE1 /* Pods_ProtobufTests.framework */; }; 4916270F24E157BB00444AF2 /* GIOPresentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4916270E24E157BB00444AF2 /* GIOPresentViewController.m */; }; 4916271224E157CF00444AF2 /* GIOPagingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4916271124E157CF00444AF2 /* GIOPagingViewController.m */; }; @@ -383,6 +384,8 @@ 34BF77C52795568B00CA18BA /* GrowingKeyChainTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GrowingKeyChainTest.m; sourceTree = ""; }; 34C0BF39277EA7C90047ADC4 /* DataTrafficTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DataTrafficTest.m; sourceTree = ""; }; 34C0BF3C277EA9BA0047ADC4 /* MobileDebuggerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MobileDebuggerTest.m; sourceTree = ""; }; + 34ECFDBD2A5C082A0059F87C /* GrowingAutotrackPageViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingAutotrackPageViewController.h; sourceTree = ""; }; + 34ECFDBE2A5C082A0059F87C /* GrowingAutotrackPageViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingAutotrackPageViewController.m; sourceTree = ""; }; 3D63F725A31AE372B485C361 /* Pods-HostApplicationTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HostApplicationTests.debug.xcconfig"; path = "Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests.debug.xcconfig"; sourceTree = ""; }; 42ADE26B250B292900CA7268 /* HybridTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HybridTest.m; sourceTree = ""; }; 42F5EA0EFE2552358C35A0F5 /* Pods_HostApplicationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HostApplicationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -580,6 +583,8 @@ 046530F924DD4271002D254C /* GIOFirstViewController.m */, 046530F624DD4271002D254C /* GIOSecondViewController.h */, 046530FA24DD4271002D254C /* GIOSecondViewController.m */, + 34ECFDBD2A5C082A0059F87C /* GrowingAutotrackPageViewController.h */, + 34ECFDBE2A5C082A0059F87C /* GrowingAutotrackPageViewController.m */, ); path = PageEvent; sourceTree = ""; @@ -2239,6 +2244,7 @@ 349F1489285B503B00437F53 /* GIOH5BrowserViewController.m in Sources */, 0465314424DD4272002D254C /* GIOMeasurementProtocolTableViewController.m in Sources */, 0465314024DD4272002D254C /* GIOKeyValueCell.m in Sources */, + 34ECFDBF2A5C082A0059F87C /* GrowingAutotrackPageViewController.m in Sources */, 0465314D24DD4272002D254C /* AppDelegate.m in Sources */, 0465315024DD4272002D254C /* GIOCollectionViewController.m in Sources */, 0465315424DD4272002D254C /* GIOSimpleUIElemtsViewController.m in Sources */, diff --git a/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.h b/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.h index 1a5861a78..188165c94 100644 --- a/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.h +++ b/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.h @@ -8,6 +8,6 @@ #import -@interface GIOPageEventViewController : UIViewController +@interface GIOPageEventViewController : UITableViewController @end diff --git a/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.m b/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.m index b6455726d..ea135c1d9 100644 --- a/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.m +++ b/Example/Example/MeasurementProtocol/PageEvent/GIOPageEventViewController.m @@ -8,6 +8,7 @@ #import "GIOPageEventViewController.h" #import "GIOContainerViewController.h" +#import "GrowingAutotrackPageViewController.h" @interface GIOPageEventViewController () @@ -17,19 +18,38 @@ @implementation GIOPageEventViewController - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + switch (indexPath.row) { + case 0: { + GrowingAutotrackPageViewController *controller = [[GrowingAutotrackPageViewController alloc] init]; + controller.type = GrowingDemoAutotrackPageTypeDefault; + [self.navigationController pushViewController:controller animated:YES]; + } break; + case 1: { + GrowingAutotrackPageViewController *controller = [[GrowingAutotrackPageViewController alloc] init]; + controller.type = GrowingDemoAutotrackPageTypeDelay; + [self.navigationController pushViewController:controller animated:YES]; + } break; + case 2: { + GrowingAutotrackPageViewController *controller = [[GrowingAutotrackPageViewController alloc] init]; + controller.type = GrowingDemoAutotrackPageTypeNotViewDidAppear; + [self.navigationController pushViewController:controller animated:YES]; + } break; + case 3: { + GrowingAutotrackPageViewController *controller = [[GrowingAutotrackPageViewController alloc] init]; + controller.type = GrowingDemoAutotrackPageTypeDelayNotViewDidAppear; + [self.navigationController pushViewController:controller animated:YES]; + } break; + case 4: { + // 参考:https://onevcat.com/2012/02/uiviewcontroller/ + GIOContainerViewController *container = [GIOContainerViewController new]; + [self.navigationController pushViewController:container animated:YES]; + } break; + default: + break; + } } -//参考:https://onevcat.com/2012/02/uiviewcontroller/ -- (IBAction)toViewControllerWhichContainTwoChildControllers:(id)sender { - GIOContainerViewController *container = [GIOContainerViewController new]; - [self.navigationController pushViewController:container animated:YES]; -} - - @end diff --git a/Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.h b/Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.h new file mode 100644 index 000000000..cfd416054 --- /dev/null +++ b/Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.h @@ -0,0 +1,37 @@ +// +// GrowingAutotrackPageViewController.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/10. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, GrowingDemoAutotrackPageType) { + GrowingDemoAutotrackPageTypeDefault, + GrowingDemoAutotrackPageTypeDelay, + GrowingDemoAutotrackPageTypeNotViewDidAppear, + GrowingDemoAutotrackPageTypeDelayNotViewDidAppear, +}; + +@interface GrowingAutotrackPageViewController : UIViewController + +@property (nonatomic, assign) GrowingDemoAutotrackPageType type; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.m b/Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.m new file mode 100644 index 000000000..bcbfee023 --- /dev/null +++ b/Example/Example/MeasurementProtocol/PageEvent/GrowingAutotrackPageViewController.m @@ -0,0 +1,80 @@ +// +// GrowingAutotrackPageViewController.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/10. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingAutotrackPageViewController.h" + +@interface GrowingAutotrackPageViewController () + +@property (nonatomic, strong) UIButton *button; + +@end + +@implementation GrowingAutotrackPageViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + self.view.backgroundColor = UIColor.whiteColor; + + UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; + button.translatesAutoresizingMaskIntoConstraints = NO; + [button setTitle:@"Button" forState:UIControlStateNormal]; + [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:button]; + self.button = button; + + [NSLayoutConstraint activateConstraints:@[ + [button.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor], + [button.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], + [button.widthAnchor constraintEqualToConstant:60.0f], + [button.heightAnchor constraintEqualToConstant:35.0f] + ]]; + + if (self.type == GrowingDemoAutotrackPageTypeDefault + || self.type == GrowingDemoAutotrackPageTypeNotViewDidAppear) { + [self autotrackPage]; + } else if (self.type == GrowingDemoAutotrackPageTypeDelay + || self.type == GrowingDemoAutotrackPageTypeDelayNotViewDidAppear) { + // 模拟网络请求,此时autotrackPage的调用在viewDidAppear之后 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self autotrackPage]; + }); + } +} + +- (void)viewDidAppear:(BOOL)animated { + if (self.type == GrowingDemoAutotrackPageTypeNotViewDidAppear + || self.type == GrowingDemoAutotrackPageTypeDelayNotViewDidAppear) { + return; + } + [super viewDidAppear:animated]; +} + +- (void)buttonAction { + +} + +- (void)autotrackPage { +#if defined(AUTOTRACKER) +#if defined(SDK3rd) + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"页面测试" attributes:@{@"key" : @"value"}]; +#endif +#endif +} + +@end diff --git a/Example/Example/Storyboard/MeasurementProtocol.storyboard b/Example/Example/Storyboard/MeasurementProtocol.storyboard index 1d6042dba..90cd28ce4 100644 --- a/Example/Example/Storyboard/MeasurementProtocol.storyboard +++ b/Example/Example/Storyboard/MeasurementProtocol.storyboard @@ -1,14 +1,152 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -400,67 +538,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -779,7 +856,7 @@ - + @@ -851,7 +928,7 @@ - + diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.m b/GrowingAutotrackerCore/Page/GrowingPageManager.m index 74e96ce00..302c36197 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.m +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.m @@ -74,6 +74,9 @@ - (void)viewControllerDidDisappear:(UIViewController *)controller { enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(GrowingPage *page, NSUInteger idx, BOOL *_Nonnull stop) { if (page.carrier == controller) { + if (page.parent != nil) { + [page.parent removeChildrenPage:page]; + } [self.visiablePages removePointerAtIndex:idx]; } }]; @@ -163,8 +166,9 @@ - (GrowingPage *)findPageByViewController:(UIViewController *)controller { GrowingPage *page = controller.growingPageObject; if (!page) { - // 一般来说,page对象在viewDidAppear时就已创建 - // 此处兼容viewDidAppear未执行的特殊情况,比如: + // 执行到此,执行流程大概是view -> findPageByView -> findPageByViewController + // view所在viewcontroller必定到了viewDidAppear生命周期 + // 一般来说,page对象在viewDidAppear时就已创建,此处兼容page对象未生成的特殊情况,比如: // 用户未在自定义的ViewController viewDidAppear中调用super viewDidAppear page = [self createdPage:controller]; } @@ -186,6 +190,13 @@ - (void)autotrackPage:(UIViewController *)controller BOOL needAutotrackPage = NO; GrowingPage *page = controller.growingPageObject; + if (!page) { + // 如果没有page对象,那么可能是(1)controller还未执行到viewDidAppear; + // (2)controller到了viewDidAppear但未生成page对象,这里兼容(2) + if (controller.isViewLoaded && controller.view.window) { + page = [self createdPage:controller]; + } + } if (page && !page.isAutotrack) { // 当前页面已经进入viewDidAppear,但未发送过PAGE事件,需要补发 needAutotrackPage = YES; From 29dbce371f8a13bc796d18cef78d9eccfa35164d Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 11 Jul 2023 17:53:05 +0800 Subject: [PATCH 022/126] =?UTF-8?q?refactor:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PageEvent/GIOFirstViewController.m | 28 ++++-------------- .../PageEvent/GIOSecondViewController.m | 29 ++++--------------- .../GrowingNode/GrowingNodeHelper.m | 13 +++++++-- 3 files changed, 23 insertions(+), 47 deletions(-) diff --git a/Example/Example/MeasurementProtocol/PageEvent/GIOFirstViewController.m b/Example/Example/MeasurementProtocol/PageEvent/GIOFirstViewController.m index e8619406a..8a790b431 100644 --- a/Example/Example/MeasurementProtocol/PageEvent/GIOFirstViewController.m +++ b/Example/Example/MeasurementProtocol/PageEvent/GIOFirstViewController.m @@ -16,29 +16,13 @@ @implementation GIOFirstViewController - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor blueColor]; -} - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - NSLog(@"GIOFirstViewController viewWillAppear"); -} -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - NSLog(@"GIOFirstViewController viewDidAppear"); -} -- (void)viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - NSLog(@"GIOFirstViewController viewWillDisappear"); -} -- (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear: animated]; - NSLog(@"GIOFirstViewController viewDidDisappear"); -} -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + +#if defined(AUTOTRACKER) +#if defined(SDK3rd) + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"子页面1"]; +#endif +#endif } @end diff --git a/Example/Example/MeasurementProtocol/PageEvent/GIOSecondViewController.m b/Example/Example/MeasurementProtocol/PageEvent/GIOSecondViewController.m index 0c1ca6fd2..b00a9d5be 100644 --- a/Example/Example/MeasurementProtocol/PageEvent/GIOSecondViewController.m +++ b/Example/Example/MeasurementProtocol/PageEvent/GIOSecondViewController.m @@ -16,30 +16,13 @@ @implementation GIOSecondViewController - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor redColor]; -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - NSLog(@"GIOSecondViewController viewWillAppear"); -} -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - NSLog(@"GIOSecondViewController viewDidAppear"); -} -- (void)viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - NSLog(@"GIOSecondViewController viewWillDisappear"); -} -- (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; - NSLog(@"GIOSecondViewController viewDidDisappear"); + +#if defined(AUTOTRACKER) +#if defined(SDK3rd) + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"子页面2"]; +#endif +#endif } @end diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index db51f4a15..04b755dd4 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -36,9 +36,11 @@ + (void)recalculateXpath:(UIView *)view NSMutableArray *originxindexArray = [NSMutableArray array]; BOOL isSimilar = YES; while (node && [node isKindOfClass:[UIView class]]) { - if (node.growingNodeSubPath == nil) { + if (node.growingNodeSubPath == nil || [self isIgnoredPrivateView:node]) { + node = node.growingNodeParent; continue; } + [viewPathArray addObject:node.growingNodeSubPath]; [originxindexArray addObject:node.growingNodeSubIndex]; if (isSimilar) { @@ -110,7 +112,9 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA id parent = view; do { - [weakArray addPointer:(void *)parent]; + if (![self isIgnoredPrivateView:parent]) { + [weakArray addPointer:(void *)parent]; + } parent = parent.growingNodeParent; } while ([parent isKindOfClass:[UIView class]]); @@ -125,6 +129,11 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA .build; } ++ (BOOL)isIgnoredPrivateView:(id)view { + NSArray *ignoredViews = @[@"_UIAlertControllerPhoneTVMacView", @"_UIAlertControllerView", @"UITableViewWrapperView"]; + return [ignoredViews containsObject:NSStringFromClass(view.class)]; +} + // 文本 static NSString *const kGrowingViewNodeText = @"TEXT"; // 按钮 From 184a93ff05cda94bb64afc065fd69f9b4960bc52 Mon Sep 17 00:00:00 2001 From: runner Date: Tue, 11 Jul 2023 09:53:57 +0000 Subject: [PATCH 023/126] style: code format --- GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 04b755dd4..c897ca31a 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -40,7 +40,7 @@ + (void)recalculateXpath:(UIView *)view node = node.growingNodeParent; continue; } - + [viewPathArray addObject:node.growingNodeSubPath]; [originxindexArray addObject:node.growingNodeSubIndex]; if (isSimilar) { @@ -130,7 +130,8 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA } + (BOOL)isIgnoredPrivateView:(id)view { - NSArray *ignoredViews = @[@"_UIAlertControllerPhoneTVMacView", @"_UIAlertControllerView", @"UITableViewWrapperView"]; + NSArray *ignoredViews = + @[@"_UIAlertControllerPhoneTVMacView", @"_UIAlertControllerView", @"UITableViewWrapperView"]; return [ignoredViews containsObject:NSStringFromClass(view.class)]; } From a2d8893b2187823bd8d8a810ae441f161ffbf6f2 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 11 Jul 2023 19:25:04 +0800 Subject: [PATCH 024/126] =?UTF-8?q?refactor:=20=E6=97=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/A1ViewClickEventsTest.m | 2 +- .../GrowingNode/GrowingNodeHelper.h | 3 -- .../GrowingNode/GrowingNodeHelper.m | 29 +------------------ .../Foundation/NSString+GrowingHelper.h | 5 ---- .../Foundation/NSString+GrowingHelper.m | 27 ----------------- GrowingTrackerCore/Utils/GrowingDeviceInfo.h | 1 - Modules/WebCircle/GrowingWebCircle.m | 2 +- 7 files changed, 3 insertions(+), 66 deletions(-) diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 3f5e0443a..3c0f301e4 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -56,7 +56,7 @@ - (void)test01AlertButtonClick { XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"取消"); XCTAssertEqualObjects(dic[@"xpath"], - @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/_UIAlertControllerPhoneTVMacView/UIView/_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfaceActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"); + @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfaceActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/0/0/0/0/0/1/0"); } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h index 0befa35e0..6a08aefbb 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h @@ -26,9 +26,6 @@ NS_ASSUME_NONNULL_BEGIN + (void)recalculateXpath:(UIView *)view block:(void (^)(NSString *xpath, NSString *xindex, NSString *originxindex))block; - -+ (NSString *)buildElementContentForNode:(id _Nullable)view; - + (GrowingViewNode *)getViewNode:(UIView *)view; + (NSString *)getViewNodeType:(UIView *)view; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index c897ca31a..01830b3ce 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -66,33 +66,6 @@ + (void)recalculateXpath:(UIView *)view } } -+ (NSString *)buildElementContentForNode:(id _Nullable)view { - NSString *content = [view growingNodeContent]; - if (!content) { - content = @""; - } else if ([content isKindOfClass:NSDictionary.class]) { - content = [[(NSDictionary *)content allValues] componentsJoinedByString:@""]; - } else if ([content isKindOfClass:NSArray.class]) { - content = [(NSArray *)content componentsJoinedByString:@""]; - } else { - content = content.description; - } - - if (![content isKindOfClass:NSString.class]) { - content = @""; - } - - content = [content growingHelper_safeSubStringWithLength:100]; - - if (content.growingHelper_isLegal) { - content = @""; - } else { - content = content.growingHelper_encryptString; - } - - return content; -} - + (GrowingViewNode *)getViewNode:(UIView *)view { NSPointerArray *weakArray = [NSPointerArray weakObjectsPointerArray]; GrowingViewNode *viewNode = [self getTopViewNode:view array:weakArray]; @@ -121,7 +94,7 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA UIView *rootview = [weakArray pointerAtIndex:weakArray.count - 1]; return GrowingViewNode.builder.setView(rootview) .setIndex(-1) - .setViewContent([self buildElementContentForNode:rootview]) + .setViewContent(rootview.growingNodeContent) .setXpath(rootview.growingNodeSubPath) .setXindex(rootview.growingNodeSubSimilarIndex) .setOriginXindex(rootview.growingNodeSubIndex) diff --git a/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.h b/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.h index b1c1ea795..36aa87ae8 100644 --- a/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.h +++ b/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.h @@ -33,13 +33,8 @@ - (NSString *)growingHelper_sha1; -- (BOOL)growingHelper_isLegal; - - (BOOL)growingHelper_isValidU; -// 若用户设置加密method 则返回加密后的string,否则返回原值 -- (NSString *)growingHelper_encryptString; - - (instancetype)initWithJsonObject_growingHelper:(id)obj; + (BOOL)growingHelper_isBlankString:(NSString *)string; diff --git a/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m b/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m index c9f4089aa..5c8456978 100644 --- a/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m +++ b/GrowingTrackerCore/Helpers/Foundation/NSString+GrowingHelper.m @@ -22,8 +22,6 @@ #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" -static NSString *const kGrowingSpecialCharactersString = @"_!@#$%^&*()-=+|\\[]{},.<>/?"; - @implementation NSString (GrowingHelper) - (NSString *)growingHelper_safeSubStringWithLength:(NSInteger)length { @@ -73,23 +71,6 @@ - (NSString *)growingHelper_sha1 { return output; } -- (BOOL)growingHelper_isLegal { - if (self.length != 1) { - return NO; - } - - unichar character = [self characterAtIndex:0]; - - BOOL isNum = isdigit(character); - BOOL isLetter = (character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z'); - BOOL isSpecialCharacter = ([kGrowingSpecialCharactersString rangeOfString:self].location != NSNotFound); - if (isNum || isLetter || isSpecialCharacter) { - return YES; - } else { - return NO; - } -} - - (BOOL)growingHelper_isValidU { if (!self.length) { return NO; @@ -108,14 +89,6 @@ - (BOOL)growingHelper_isValidU { return NO; } -- (NSString *)growingHelper_encryptString { - if ([GrowingDeviceInfo currentDeviceInfo].encryptStringBlock) { - return [GrowingDeviceInfo currentDeviceInfo].encryptStringBlock(self); - } else { - return self; - } -} - - (instancetype)initWithJsonObject_growingHelper:(id)obj { if (!obj || ![NSJSONSerialization isValidJSONObject:obj]) { return nil; diff --git a/GrowingTrackerCore/Utils/GrowingDeviceInfo.h b/GrowingTrackerCore/Utils/GrowingDeviceInfo.h index 4d1f6ebd5..a0acb3932 100644 --- a/GrowingTrackerCore/Utils/GrowingDeviceInfo.h +++ b/GrowingTrackerCore/Utils/GrowingDeviceInfo.h @@ -39,7 +39,6 @@ @property (nonatomic, readonly, assign) int appState; @property (nonatomic, readonly, assign) CGFloat screenWidth; @property (nonatomic, readonly, assign) CGFloat screenHeight; -@property (nonatomic, copy) NSString * (^encryptStringBlock)(NSString *string); + (instancetype)currentDeviceInfo; + (void)configUrlScheme:(NSString *)urlScheme; diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 81abcea08..7d33b1b0c 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -264,7 +264,7 @@ - (void)fillAllViewsForWebCircle:(NSDictionary *)dataDict completion:(void (^)(N self.isPageDontShow = NO; [self traverseViewNode:GrowingViewNode.builder.setView(topwindow) .setIndex(-1) - .setViewContent([GrowingNodeHelper buildElementContentForNode:topwindow]) + .setViewContent(topwindow.growingNodeContent) .setXpath(topwindow.growingNodeSubPath) .setXindex(topwindow.growingNodeSubSimilarIndex) .setOriginXindex(topwindow.growingNodeSubIndex) From 3ba4195e79fe73ddecf313c82fc8c3dd73f6c514 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 12 Jul 2023 10:02:18 +0800 Subject: [PATCH 025/126] test: update ci --- .../AutotrackerTests/Event/A1ViewClickEventsTest.m | 2 +- .../HelpersTests/GrowingFoundationHelpersTest.m | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 3c0f301e4..6ceb1389a 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -57,7 +57,7 @@ - (void)test01AlertButtonClick { XCTAssertEqualObjects(dic[@"textValue"], @"取消"); XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfaceActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/0/0/0/0/0/1/0"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/0/0/0/0/1/0"); } { diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m index 5733dffb1..60e142031 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m @@ -89,9 +89,7 @@ - (void)testNSStringGrowingHelper { [a growingHelper_queryObject]; [a growingHelper_safeSubStringWithLength:1]; [a growingHelper_sha1]; - [a growingHelper_isLegal]; [a growingHelper_isValidU]; - [a growingHelper_encryptString]; XCTAssertNotNil([[NSString alloc] initWithJsonObject_growingHelper:@{@"key" : @"value"}]); XCTAssertFalse([NSString growingHelper_isBlankString:@"t"]); a = [@"https://www.baidu.com" growingHelper_absoluteURLStringWithPath:@"path" andQuery:@{@"key" : @"value"}]; From af208cdb45fefbd309535fbf5b7021fd25fe7aa2 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 12 Jul 2023 10:52:52 +0800 Subject: [PATCH 026/126] test: update ci --- Example/Example-macOS/AppDelegate.swift | 3 - .../Example-macOS/Base.lproj/Main.storyboard | 180 +++++++-------- Example/Example-macOS/ViewController.swift | 17 -- Example/Example.xcodeproj/project.pbxproj | 28 --- Example/Example/GrowingIO-Prefix.pch | 5 - .../GIOAttributesTrackViewController.h | 1 - .../GIOAttributesTrackViewController.m | 20 -- .../GIOPageAttributesEventViewController.h | 13 -- .../GIOPageAttributesEventViewController.m | 72 ------ .../VisitEvent/GIOVisitEventViewController.h | 17 -- .../VisitEvent/GIOVisitEventViewController.m | 82 ------- .../Storyboard/MeasurementProtocol.storyboard | 215 +----------------- Example/ExampleiOS13/AppDelegate.m | 1 + 13 files changed, 92 insertions(+), 562 deletions(-) delete mode 100644 Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.h delete mode 100644 Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m delete mode 100644 Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.h delete mode 100644 Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.m diff --git a/Example/Example-macOS/AppDelegate.swift b/Example/Example-macOS/AppDelegate.swift index 60e4ae77a..5a13cd960 100644 --- a/Example/Example-macOS/AppDelegate.swift +++ b/Example/Example-macOS/AppDelegate.swift @@ -29,9 +29,6 @@ import GrowingAnalytics @main class AppDelegate: NSObject, NSApplicationDelegate { - - - func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application let config = GrowingTrackConfiguration(projectId: "bcc4fc9dea27f25d") diff --git a/Example/Example-macOS/Base.lproj/Main.storyboard b/Example/Example-macOS/Base.lproj/Main.storyboard index fb72e4123..b160b9dab 100644 --- a/Example/Example-macOS/Base.lproj/Main.storyboard +++ b/Example/Example-macOS/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -707,11 +707,11 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + @@ -868,7 +886,7 @@ - + @@ -882,46 +900,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -933,7 +911,7 @@ - + diff --git a/Example/Example-macOS/ViewController.swift b/Example/Example-macOS/ViewController.swift index 988dfaca8..9a9b8da81 100644 --- a/Example/Example-macOS/ViewController.swift +++ b/Example/Example-macOS/ViewController.swift @@ -19,12 +19,7 @@ import Cocoa - -#if canImport(GrowingAnalytics_cdp) -import GrowingAnalytics_cdp -#elseif canImport(GrowingAnalytics) import GrowingAnalytics -#endif class ViewController: NSViewController { @@ -73,18 +68,6 @@ class ViewController: NSViewController { GrowingTracker.sharedInstance().setLoginUserAttributes(["key": "value"]) } - @IBAction func sendConversionVariablesEventAction(_ sender: Any) { -#if !canImport(GrowingAnalytics_cdp) - GrowingTracker.sharedInstance().setConversionVariables(["key": "value"]) -#endif - } - - @IBAction func sendVisitorAttributesEventAction(_ sender: Any) { -#if !canImport(GrowingAnalytics_cdp) - GrowingTracker.sharedInstance().setVisitorAttributes(["key": "value"]) -#endif - } - @IBAction func startTimerAction(_ sender: Any) { let timerId = GrowingTracker.sharedInstance().trackTimerStart(timerEventNameTextField.stringValue) guard let timerId = timerId else { diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index d20749b88..acd1a4536 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -42,11 +42,9 @@ 0465313F24DD4272002D254C /* GIOInputChangeEventViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530E824DD4271002D254C /* GIOInputChangeEventViewController.m */; }; 0465314024DD4272002D254C /* GIOKeyValueCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530EA24DD4271002D254C /* GIOKeyValueCell.m */; }; 0465314124DD4272002D254C /* GIOKeyValueCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 046530EB24DD4271002D254C /* GIOKeyValueCell.xib */; }; - 0465314224DD4272002D254C /* GIOPageAttributesEventViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530ED24DD4271002D254C /* GIOPageAttributesEventViewController.m */; }; 0465314324DD4272002D254C /* GIOClickEventViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530EE24DD4271002D254C /* GIOClickEventViewController.m */; }; 0465314424DD4272002D254C /* GIOMeasurementProtocolTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530EF24DD4271002D254C /* GIOMeasurementProtocolTableViewController.m */; }; 0465314524DD4272002D254C /* GIOCustomEventViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530F024DD4271002D254C /* GIOCustomEventViewController.m */; }; - 0465314624DD4272002D254C /* GIOVisitEventViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530F124DD4271002D254C /* GIOVisitEventViewController.m */; }; 0465314724DD4272002D254C /* GIOContainerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530F424DD4271002D254C /* GIOContainerViewController.m */; }; 0465314824DD4272002D254C /* GIOPageEventViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530F724DD4271002D254C /* GIOPageEventViewController.m */; }; 0465314924DD4272002D254C /* GIOFirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530F924DD4271002D254C /* GIOFirstViewController.m */; }; @@ -216,21 +214,17 @@ 046530DF24DD4271002D254C /* GIOInputChangeEventViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOInputChangeEventViewController.h; sourceTree = ""; }; 046530E024DD4271002D254C /* GIOAttributesTrackViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOAttributesTrackViewController.h; sourceTree = ""; }; 046530E124DD4271002D254C /* GIOUserIdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOUserIdViewController.m; sourceTree = ""; }; - 046530E224DD4271002D254C /* GIOVisitEventViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOVisitEventViewController.h; sourceTree = ""; }; 046530E324DD4271002D254C /* GIOCustomEventViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOCustomEventViewController.h; sourceTree = ""; }; 046530E424DD4271002D254C /* GIOMeasurementProtocolTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOMeasurementProtocolTableViewController.h; sourceTree = ""; }; 046530E524DD4271002D254C /* GIOClickEventViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOClickEventViewController.h; sourceTree = ""; }; - 046530E624DD4271002D254C /* GIOPageAttributesEventViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOPageAttributesEventViewController.h; sourceTree = ""; }; 046530E724DD4271002D254C /* GIOAttributesTrackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOAttributesTrackViewController.m; sourceTree = ""; }; 046530E824DD4271002D254C /* GIOInputChangeEventViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOInputChangeEventViewController.m; sourceTree = ""; }; 046530EA24DD4271002D254C /* GIOKeyValueCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOKeyValueCell.m; sourceTree = ""; }; 046530EB24DD4271002D254C /* GIOKeyValueCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GIOKeyValueCell.xib; sourceTree = ""; }; 046530EC24DD4271002D254C /* GIOKeyValueCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOKeyValueCell.h; sourceTree = ""; }; - 046530ED24DD4271002D254C /* GIOPageAttributesEventViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOPageAttributesEventViewController.m; sourceTree = ""; }; 046530EE24DD4271002D254C /* GIOClickEventViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOClickEventViewController.m; sourceTree = ""; }; 046530EF24DD4271002D254C /* GIOMeasurementProtocolTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOMeasurementProtocolTableViewController.m; sourceTree = ""; }; 046530F024DD4271002D254C /* GIOCustomEventViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOCustomEventViewController.m; sourceTree = ""; }; - 046530F124DD4271002D254C /* GIOVisitEventViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOVisitEventViewController.m; sourceTree = ""; }; 046530F224DD4271002D254C /* GIOUserIdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOUserIdViewController.h; sourceTree = ""; }; 046530F424DD4271002D254C /* GIOContainerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GIOContainerViewController.m; sourceTree = ""; }; 046530F524DD4271002D254C /* GIOFirstViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GIOFirstViewController.h; sourceTree = ""; }; @@ -559,11 +553,9 @@ 046530E424DD4271002D254C /* GIOMeasurementProtocolTableViewController.h */, 046530EF24DD4271002D254C /* GIOMeasurementProtocolTableViewController.m */, 046530F324DD4271002D254C /* PageEvent */, - 34BDC33F277070820030B3CE /* VisitEvent */, 34BDC340277070990030B3CE /* ClickEvent */, 34BDC341277070AC0030B3CE /* ViewChangeEvent */, 34BDC342277071200030B3CE /* AttributesEvent */, - 34BDC343277071360030B3CE /* PageAttributesEvent */, 34BDC34B2770719C0030B3CE /* CustomEvent */, 34BDC34D277071FE0030B3CE /* UserId */, 34986DF228C6EE0E00401612 /* TrackTimer */, @@ -1056,15 +1048,6 @@ path = FileStorageTests; sourceTree = ""; }; - 34BDC33F277070820030B3CE /* VisitEvent */ = { - isa = PBXGroup; - children = ( - 046530E224DD4271002D254C /* GIOVisitEventViewController.h */, - 046530F124DD4271002D254C /* GIOVisitEventViewController.m */, - ); - path = VisitEvent; - sourceTree = ""; - }; 34BDC340277070990030B3CE /* ClickEvent */ = { isa = PBXGroup; children = ( @@ -1092,15 +1075,6 @@ path = AttributesEvent; sourceTree = ""; }; - 34BDC343277071360030B3CE /* PageAttributesEvent */ = { - isa = PBXGroup; - children = ( - 046530E624DD4271002D254C /* GIOPageAttributesEventViewController.h */, - 046530ED24DD4271002D254C /* GIOPageAttributesEventViewController.m */, - ); - path = PageAttributesEvent; - sourceTree = ""; - }; 34BDC34B2770719C0030B3CE /* CustomEvent */ = { isa = PBXGroup; children = ( @@ -2254,7 +2228,6 @@ 0465315124DD4272002D254C /* GIOUICategoryViewController.m in Sources */, 0465314824DD4272002D254C /* GIOPageEventViewController.m in Sources */, 0465313E24DD4272002D254C /* GIOAttributesTrackViewController.m in Sources */, - 0465314624DD4272002D254C /* GIOVisitEventViewController.m in Sources */, 0465313924DD4272002D254C /* GIOConstants.m in Sources */, 0465313724DD4272002D254C /* GIODataProcessOperation.m in Sources */, 0465314924DD4272002D254C /* GIOFirstViewController.m in Sources */, @@ -2276,7 +2249,6 @@ 0465315324DD4272002D254C /* GIOActionSheetViewController.m in Sources */, 0465314C24DD4272002D254C /* main.m in Sources */, 0465314A24DD4272002D254C /* GIOSecondViewController.m in Sources */, - 0465314224DD4272002D254C /* GIOPageAttributesEventViewController.m in Sources */, 0465315724DD4272002D254C /* GIOMultiViewController.m in Sources */, 0465314324DD4272002D254C /* GIOClickEventViewController.m in Sources */, 349F148C285B52B700437F53 /* GIOScanViewController.m in Sources */, diff --git a/Example/Example/GrowingIO-Prefix.pch b/Example/Example/GrowingIO-Prefix.pch index bdd7c5446..cbb2d1555 100644 --- a/Example/Example/GrowingIO-Prefix.pch +++ b/Example/Example/GrowingIO-Prefix.pch @@ -27,11 +27,6 @@ #define GrowingSDKConfiguration GrowingTrackConfiguration #endif -#if (__has_include("GrowingTrackConfiguration+CdpTracker.h") || __has_include("Dummy-GrowingTrackerCore-cdp.h")) -// CDP SDK -#define SDKCDP -#endif - #if __has_include("GrowingAdvertising.h") // Advert Module #import "GrowingAdvertising.h" diff --git a/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.h b/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.h index aae907dd7..869f19a32 100644 --- a/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.h +++ b/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.h @@ -5,7 +5,6 @@ // Created by GrowingIO on 2020/6/10. // Copyright © 2020 GrowingIO. All rights reserved. // -// CONVERSION_VARIABLES, LOGIN_USER_ATTRIBUTES, VISITOR_ATTRIBUTES 事件的测试页面 #import diff --git a/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.m b/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.m index 43e104b3c..ce55c98e9 100644 --- a/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.m +++ b/Example/Example/MeasurementProtocol/AttributesEvent/GIOAttributesTrackViewController.m @@ -107,26 +107,6 @@ - (void)trackEventWithAttributes:(NSDictionary *)atts { [builder setString:@"LOGIN_USER_ATTRIBUTES" forKey:@"type"]; [GrowingSDK.sharedInstance setLoginUserAttributes:builder.build]; #endif -// } else if ([self.eventType isEqualToString:@"CONVERSION_VARIABLES"]) { -//#if defined(SDK3rd) && !defined(SDKCDP) -// [[GrowingSDK sharedInstance] setConversionVariables:atts]; -// -// GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; -// [builder setString:@"value" forKey:@"key"]; -// [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@"key2"]; -// [builder setString:@"CONVERSION_VARIABLES" forKey:@"type"]; -// [GrowingSDK.sharedInstance setConversionVariables:builder.build]; -//#endif -// } else if ([self.eventType isEqualToString:@"VISITOR_ATTRIBUTES"]) { -//#if defined(SDK3rd) && !defined(SDKCDP) -// [[GrowingSDK sharedInstance] setVisitorAttributes:atts]; -// -// GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; -// [builder setString:@"value" forKey:@"key"]; -// [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@"key2"]; -// [builder setString:@"VISITOR_ATTRIBUTES" forKey:@"type"]; -// [GrowingSDK.sharedInstance setVisitorAttributes:builder.build]; -//#endif } NSLog(@"track %@ 事件,attributes:%@", self.eventType, atts); diff --git a/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.h b/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.h deleted file mode 100644 index d6386b6a4..000000000 --- a/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// GIOPageAttributesEventViewController.h -// GrowingExample -// -// Created by GrowingIO on 2018/6/5. -// Copyright (C) 2018 Beijing Yishu Technology Co., Ltd. -// - -#import - -@interface GIOPageAttributesEventViewController : UIViewController - -@end diff --git a/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m b/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m deleted file mode 100644 index f332715cd..000000000 --- a/Example/Example/MeasurementProtocol/PageAttributesEvent/GIOPageAttributesEventViewController.m +++ /dev/null @@ -1,72 +0,0 @@ -// -// GIOPageAttributesEventViewController.m -// GrowingExample -// -// Created by GrowingIO on 2018/6/5. -// Copyright (C) 2018 Beijing Yishu Technology Co., Ltd. -// - -#import "GIOPageAttributesEventViewController.h" -#import "GIODataProcessOperation.h" -#import "GIOConstants.h" - -@interface GIOPageAttributesEventViewController () - -@property (nonatomic, strong) NSDictionary *pageAttributes; - -@end - -@implementation GIOPageAttributesEventViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - [self configRandomPageAttributes]; -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -- (void)configRandomPageAttributes { -#if defined(AUTOTRACKER) -#if defined(SDK3rd) - [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"页面属性测试" attributes:[self getRandomAttributes]]; -#endif -#endif -} - -- (IBAction)setPageAttributesBtnClick:(UIButton *)sender { - [self configRandomPageAttributes]; -} - -- (IBAction)setPageAttributesOutRangeBtnClick:(UIButton *)sender { - NSDictionary *pval = [GIOConstants getLargeDictionary]; -#if defined(AUTOTRACKER) -#if defined(SDK3rd) - [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"页面属性测试" attributes:pval]; -#endif -#endif - NSLog(@"setPageVariable largeDic length is:%ld",pval.count); -} - -- (NSDictionary *)getRandomAttributes { - NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; - for (int i = 0; i < 3; i ++) { - [attributes setObject:[self randomValue] forKey:[self randomKey]]; - } - return attributes; -} - -- (NSString *)randomKey { - int l = [GIODataProcessOperation getRandomLengthFrom:5 to:20]; - return [NSString stringWithFormat:@"k_%@", [GIODataProcessOperation randomStringWithLength:l]]; -} - -- (NSString *)randomValue { - int l = [GIODataProcessOperation getRandomLengthFrom:5 to:30]; - return [NSString stringWithFormat:@"v_%@", [GIODataProcessOperation randomStringWithLength:l]]; -} - - -@end diff --git a/Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.h b/Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.h deleted file mode 100644 index f933b57ac..000000000 --- a/Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// GIOVisitEventViewController.h -// GrowingExample -// -// Created by GrowingIO on 2020/2/28. -// Copyright © 2020 GrowingIO. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface GIOVisitEventViewController : UIViewController - -@end - -NS_ASSUME_NONNULL_END diff --git a/Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.m b/Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.m deleted file mode 100644 index b70f78e34..000000000 --- a/Example/Example/MeasurementProtocol/VisitEvent/GIOVisitEventViewController.m +++ /dev/null @@ -1,82 +0,0 @@ -// -// GIOVisitEventViewController.m -// GrowingExample -// -// Created by GrowingIO on 2020/2/28. -// Copyright © 2020 GrowingIO. All rights reserved. -// - -#import "GIOVisitEventViewController.h" -@import MapKit; - -@interface GIOVisitEventViewController () - -@property (weak, nonatomic) IBOutlet MKMapView *mapView; -@property (weak, nonatomic) IBOutlet UIButton *setLocationButton; -@property (weak, nonatomic) IBOutlet UILabel *locationDisplayLabel; - -@property (nonatomic, strong) CLLocationManager *locationManager; -@property (nonatomic, strong) CLLocation *location; - -@end - -@implementation GIOVisitEventViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - - self.navigationItem.title = @"visitor 事件"; - - [self setup]; -} - -- (void)setup { - if (![CLLocationManager locationServicesEnabled]) { - self.locationDisplayLabel.text = @"请在设置->隐私中打开定位服务"; - } - - if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { - [self.locationManager requestWhenInUseAuthorization]; - } - - MKCoordinateSpan span = MKCoordinateSpanMake(0.021251, 0.016093); - - self.mapView.showsUserLocation = YES; - self.mapView.userTrackingMode = MKUserTrackingModeFollow; - [self.mapView setRegion:MKCoordinateRegionMake(self.mapView.userLocation.coordinate, span) animated:YES]; -} - -- (IBAction)setLocationBtnClick:(UIButton *)sender { -// [Growing setLocation:self.location.coordinate.latitude longitude:self.location.coordinate.longitude]; -} - -- (IBAction)clearLocationBtnClick:(UIButton *)sender { -// [Growing cleanLocation]; -} - -#pragma mark MKMapViewDelegate - -- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { - if (userLocation) { - self.setLocationButton.enabled = YES; - self.location = userLocation.location; - - self.locationDisplayLabel.text = - [NSString stringWithFormat:@"lat: %f lng: %f", userLocation.location.coordinate.latitude, - userLocation.location.coordinate.longitude]; - - [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(userLocation.location.coordinate.latitude, - userLocation.location.coordinate.longitude)]; - } -} - -#pragma mark lazy load - -- (CLLocationManager *)locationManager { - if (!_locationManager) { - _locationManager = [[CLLocationManager alloc] init]; - } - return _locationManager; -} - -@end diff --git a/Example/Example/Storyboard/MeasurementProtocol.storyboard b/Example/Example/Storyboard/MeasurementProtocol.storyboard index 90cd28ce4..0d453090a 100644 --- a/Example/Example/Storyboard/MeasurementProtocol.storyboard +++ b/Example/Example/Storyboard/MeasurementProtocol.storyboard @@ -145,117 +145,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -353,7 +243,7 @@ - + @@ -536,7 +426,7 @@ - + @@ -931,28 +821,8 @@ - - - - - - - - - - - - - - - + @@ -972,7 +842,7 @@ - + @@ -996,7 +866,7 @@ - + @@ -1015,28 +885,8 @@ - - - - - - - - - - - - - - - + @@ -1055,52 +905,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1129,7 +939,7 @@ - + @@ -1149,7 +959,7 @@ - + @@ -1169,7 +979,7 @@ - + @@ -1388,11 +1198,10 @@ - + - diff --git a/Example/ExampleiOS13/AppDelegate.m b/Example/ExampleiOS13/AppDelegate.m index 8df2c9d43..c14bc2753 100644 --- a/Example/ExampleiOS13/AppDelegate.m +++ b/Example/ExampleiOS13/AppDelegate.m @@ -34,6 +34,7 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:kGrowingProjectId]; + configuration.dataSourceId = @"1234567890"; configuration.debugEnabled = YES; // 暂时设置host为mocky链接,防止请求404,实际是没有上传到服务器的,正式使用请去掉,或设置正确的host configuration.dataCollectionServerHost = @"https://run.mocky.io/v3/08999138-a180-431d-a136-051f3c6bd306"; From 1d489767f2bdd048047cbd9305d30008fdc71a73 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 12 Jul 2023 11:36:35 +0800 Subject: [PATCH 027/126] =?UTF-8?q?fix:=20UIAlertController/UISegment=20sw?= =?UTF-8?q?izzle=20=E5=BB=B6=E8=BF=9F=E5=88=B0=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GrowingNode/Category/UIAlertController+GrowingNode.h | 2 ++ .../GrowingNode/Category/UISegmentedControl+GrowingNode.h | 2 ++ GrowingAutotrackerCore/GrowingRealAutotracker.m | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h index 3d52f18ac..a0f7453c8 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h @@ -28,4 +28,6 @@ + (void)addAutoTrackSwizzles; ++ (void)addAutoTrackSwizzles; + @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h index e55f14083..600022ae8 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h +++ b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h @@ -27,4 +27,6 @@ + (void)addAutoTrackSwizzles; ++ (void)addAutoTrackSwizzles; + @end diff --git a/GrowingAutotrackerCore/GrowingRealAutotracker.m b/GrowingAutotrackerCore/GrowingRealAutotracker.m index 1bdbaf158..888ac8194 100644 --- a/GrowingAutotrackerCore/GrowingRealAutotracker.m +++ b/GrowingAutotrackerCore/GrowingRealAutotracker.m @@ -30,6 +30,8 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" +#import "GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h" +#import "GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h" #import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" @@ -51,6 +53,8 @@ - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration if (self) { if (self.configuration.autotrackEnabled) { [self addAutoTrackSwizzles]; + [GrowingAlertVCActionView addAutoTrackSwizzles]; + [GrowingSegmentButton addAutoTrackSwizzles]; [GrowingULViewControllerLifecycle setup]; [GrowingPageManager.sharedInstance start]; [GrowingImpressionTrack.sharedInstance start]; From 2c571f98620983b832324cd23a1f4c4e14d21e6b Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 12 Jul 2023 16:18:25 +0800 Subject: [PATCH 028/126] fix: delete unused codes --- GrowingAutotracker/GrowingAutotracker.m | 1 - .../Autotrack/NSNotificationCenter+GrowingAutotracker.m | 1 - .../Autotrack/UICollectionView+GrowingAutotracker.m | 2 -- .../Autotrack/UITableView+GrowingAutotracker.m | 2 -- .../Autotrack/UITapGestureRecognizer+GrowingAutotracker.m | 2 -- .../Autotrack/UIViewController+GrowingAutotracker.h | 3 +-- .../Autotrack/UIViewController+GrowingAutotracker.m | 2 -- .../GrowingNode/Category/UIAlertController+GrowingNode.h | 2 -- .../GrowingNode/Category/UISegmentedControl+GrowingNode.h | 2 -- .../GrowingNode/Category/UIView+GrowingNode.m | 3 --- .../GrowingNode/Category/UIViewController+GrowingNode.m | 1 - .../GrowingNode/Category/UIWindow+GrowingNode.m | 1 - GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h | 3 --- GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m | 8 -------- GrowingAutotrackerCore/GrowingRealAutotracker.m | 2 -- .../Impression/GrowingImpressionTrack.m | 1 - 16 files changed, 1 insertion(+), 35 deletions(-) diff --git a/GrowingAutotracker/GrowingAutotracker.m b/GrowingAutotracker/GrowingAutotracker.m index cdf590fb9..5a8686d21 100644 --- a/GrowingAutotracker/GrowingAutotracker.m +++ b/GrowingAutotracker/GrowingAutotracker.m @@ -20,7 +20,6 @@ #import "GrowingAutotracker/GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingRealAutotracker.h" #import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" static GrowingAutotracker *sharedInstance = nil; diff --git a/GrowingAutotrackerCore/Autotrack/NSNotificationCenter+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/NSNotificationCenter+GrowingAutotracker.m index 14f35a55f..4179c7311 100644 --- a/GrowingAutotrackerCore/Autotrack/NSNotificationCenter+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/NSNotificationCenter+GrowingAutotracker.m @@ -20,7 +20,6 @@ #import #import "GrowingAutotrackerCore/Autotrack/GrowingPropertyDefine.h" #import "GrowingAutotrackerCore/Autotrack/NSNotificationCenter+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.h" GrowingPropertyDefine(UITextField, NSString *, growingHookOldText, setGrowingHookOldText) diff --git a/GrowingAutotrackerCore/Autotrack/UICollectionView+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UICollectionView+GrowingAutotracker.m index 3a168af52..aafa77dca 100644 --- a/GrowingAutotrackerCore/Autotrack/UICollectionView+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UICollectionView+GrowingAutotracker.m @@ -18,9 +18,7 @@ // limitations under the License. #import "GrowingAutotrackerCore/Autotrack/UICollectionView+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.h" -#import "GrowingULSwizzle.h" #import "GrowingULSwizzler.h" @implementation UICollectionView (GrowingAutotracker) diff --git a/GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.m index 16209acdc..720c48f01 100644 --- a/GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.m @@ -18,9 +18,7 @@ // limitations under the License. #import "GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.h" -#import "GrowingULSwizzle.h" #import "GrowingULSwizzler.h" @implementation UITableView (GrowingAutotracker) diff --git a/GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.m index aa4869f38..9cf6129fb 100644 --- a/GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.m @@ -18,9 +18,7 @@ // limitations under the License. #import "GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.h" -#import "GrowingULSwizzle.h" @interface GrowingUIGestureRecognizerObserver : NSObject diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h index 3c9f7b397..e7a03eb97 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h @@ -25,13 +25,12 @@ NS_ASSUME_NONNULL_BEGIN @interface UIViewController (GrowingAutotracker) +@property (nonatomic, strong) GrowingPage *growingPageObject; @property (nonatomic, copy) NSString *growingPageAlias; @property (nonatomic, copy) NSDictionary *growingPageAttributes; - (BOOL)growingHookIsCustomAddVC; // 用来判断是否是没有使用addChildViewController方法的childVC - (nullable NSString *)growingPageTitle; -- (void)setGrowingPageObject:(GrowingPage *)page; -- (GrowingPage *)growingPageObject; @end diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m index 9cb1afe54..96c0fbb60 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m @@ -19,9 +19,7 @@ #import #import "GrowingAutotrackerCore/Autotrack/GrowingPropertyDefine.h" -#import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingAutotrackerCore/Page/GrowingPage.h" -#import "GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingTrackerCore/Utils/GrowingArgumentChecker.h" #import "GrowingULViewControllerLifecycle.h" diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h index a0f7453c8..3d52f18ac 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h @@ -28,6 +28,4 @@ + (void)addAutoTrackSwizzles; -+ (void)addAutoTrackSwizzles; - @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h index 600022ae8..e55f14083 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h +++ b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h @@ -27,6 +27,4 @@ + (void)addAutoTrackSwizzles; -+ (void)addAutoTrackSwizzles; - @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index 7e27a7d60..b35620082 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -18,16 +18,13 @@ // limitations under the License. #import "GrowingAutotrackerCore/Autotrack/GrowingPropertyDefine.h" -#import "GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.h" #import "GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" -#import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Public/GrowingBaseEvent.h" @implementation UIView (GrowingNode) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m index 346e2d47d..c81a76c5d 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m @@ -21,7 +21,6 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.h" -#import "GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" @implementation UIViewController (GrowingNode) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m index 0d44354bc..626cdedcb 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m @@ -18,7 +18,6 @@ // limitations under the License. #import "GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.h" -#import "GrowingAutotrackerCore/Page/GrowingPageManager.h" @implementation UIWindow (GrowingNode) diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h index a667fa577..1553b6e70 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h @@ -39,7 +39,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) int index; // 视图在父节点的排序index,称之为position,例如UIView下的第一个UIButton,postion=0 @property (nonatomic, assign, readonly) int position; -@property (nonatomic, assign, readonly) long long timestamp; @property (nonatomic, assign, readonly) BOOL hasListParent; // 当圈选时,从上至下的路径不一定和正常事件(从下至上)的路径一致,我们需要从新计算xpath @property (nonatomic, assign, readonly) BOOL needRecalculate; @@ -71,7 +70,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) int index; // 视图在父节点的排序index,称之为position,例如UIView下的第一个UIButton,postion=0 @property (nonatomic, assign, readonly) int position; -@property (nonatomic, assign, readonly) long long timestamp; @property (nonatomic, assign, readonly) BOOL hasListParent; @property (nonatomic, assign, readonly) BOOL needRecalculate; @@ -83,7 +81,6 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXindex; - (GrowingViewNodeBuilder * (^)(int value))setIndex; - (GrowingViewNodeBuilder * (^)(int value))setPosition; -- (GrowingViewNodeBuilder * (^)(long long value))setTimestamp; - (GrowingViewNodeBuilder * (^)(NSString *value))setViewContent; - (GrowingViewNodeBuilder * (^)(NSString *value))setNodeType; - (GrowingViewNodeBuilder * (^)(BOOL value))setHasListParent; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m index 5dbd740fd..43efaad8b 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m @@ -47,7 +47,6 @@ - (instancetype)initWithBuilder:(GrowingViewNodeBuilder *)builder { _nodeType = builder.nodeType; _index = builder.index; _position = builder.position; - _timestamp = builder.timestamp; _hasListParent = builder.hasListParent; _needRecalculate = builder.needRecalculate; if (_needRecalculate) { @@ -184,13 +183,6 @@ @implementation GrowingViewNodeBuilder }; } -- (GrowingViewNodeBuilder * (^)(long long value))setTimestamp { - return ^(long long value) { - self->_timestamp = value; - return self; - }; -} - - (GrowingViewNodeBuilder * (^)(NSString *value))setViewContent { return ^(NSString *value) { self->_viewContent = value; diff --git a/GrowingAutotrackerCore/GrowingRealAutotracker.m b/GrowingAutotrackerCore/GrowingRealAutotracker.m index 888ac8194..a77fb0d21 100644 --- a/GrowingAutotrackerCore/GrowingRealAutotracker.m +++ b/GrowingAutotrackerCore/GrowingRealAutotracker.m @@ -53,8 +53,6 @@ - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration if (self) { if (self.configuration.autotrackEnabled) { [self addAutoTrackSwizzles]; - [GrowingAlertVCActionView addAutoTrackSwizzles]; - [GrowingSegmentButton addAutoTrackSwizzles]; [GrowingULViewControllerLifecycle setup]; [GrowingPageManager.sharedInstance start]; [GrowingImpressionTrack.sharedInstance start]; diff --git a/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.m b/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.m index c03aa04b5..820f311d4 100644 --- a/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.m +++ b/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.m @@ -21,7 +21,6 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingTrackerCore/Event/GrowingEventGenerator.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingULAppLifecycle.h" From d2d2c4cec67f117291a195335c67e033604d1a39 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 12 Jul 2023 17:42:48 +0800 Subject: [PATCH 029/126] =?UTF-8?q?fix:=20=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E4=B8=8B=E8=B0=83=E7=94=A8=20autotrackPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClickEvent/GIOClickEventViewController.m | 5 - .../GIOInputChangeEventViewController.m | 3 +- .../GIOSimpleUIElemtsViewController.m | 2 + .../TextFields/GIOTextFieldViewController.m | 6 +- .../A0GrowingAnalyticsTest.m | 105 +++++++++--------- .../Event/A2ViewChangeEventsTest.m | 31 ++++++ .../UIViewController+GrowingAutotracker.m | 15 +-- .../GrowingNode/GrowingNodeHelper.m | 4 - .../GrowingRealAutotracker.m | 19 +++- .../Page/GrowingPageManager.m | 6 - 10 files changed, 112 insertions(+), 84 deletions(-) diff --git a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m index 95a86124c..eba861554 100644 --- a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m +++ b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m @@ -25,11 +25,6 @@ - (void)viewDidLoad { #if defined(AUTOTRACKER) #if defined(SDK3rd) [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"点击事件测试" attributes:@{@"greet": @"hello"}]; -#endif -#endif - -#if defined(AUTOTRACKER) -#if defined(SDK3rd) self.segmentControl.growingUniqueTag = @"language-selector"; [self.sendEventButton growingTrackImpression:@"hello_track_impression"]; [self.view growingTrackImpression:@"self_view_imp_track" attributes:@{@"self_view_key": @"self_view_value"}]; diff --git a/Example/Example/MeasurementProtocol/ViewChangeEvent/GIOInputChangeEventViewController.m b/Example/Example/MeasurementProtocol/ViewChangeEvent/GIOInputChangeEventViewController.m index 1881b7bae..47ed3c686 100644 --- a/Example/Example/MeasurementProtocol/ViewChangeEvent/GIOInputChangeEventViewController.m +++ b/Example/Example/MeasurementProtocol/ViewChangeEvent/GIOInputChangeEventViewController.m @@ -23,7 +23,7 @@ @implementation GIOInputChangeEventViewController - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. + self.searchbartest.placeholder = @"搜索"; self.searchbartest.accessibilityLabel = @"SearchBarTest"; //[self.searchbartest resignFirstResponder]; @@ -32,7 +32,6 @@ - (void)viewDidLoad { self.dataPickerOper.datePickerMode = UIDatePickerModeDate; self.dataPickerOper.accessibilityLabel = @"dataPickerOper"; [self.dataPickerOper addTarget:self action:@selector(dateChange:) forControlEvents:UIControlEventValueChanged]; - } - (void)didReceiveMemoryWarning { diff --git a/Example/Example/UICategoryTests/SimpleUIElements/GIOSimpleUIElemtsViewController.m b/Example/Example/UICategoryTests/SimpleUIElements/GIOSimpleUIElemtsViewController.m index 2aa140381..3b10a0895 100644 --- a/Example/Example/UICategoryTests/SimpleUIElements/GIOSimpleUIElemtsViewController.m +++ b/Example/Example/UICategoryTests/SimpleUIElements/GIOSimpleUIElemtsViewController.m @@ -27,6 +27,8 @@ @implementation GIOSimpleUIElemtsViewController - (void)viewDidLoad { [super viewDidLoad]; + self.defaultSlider.accessibilityLabel = @"defaultSlider"; + [self configureRightNavButtonItem]; [self configureSearchBar]; [self configureSegmentedControl]; diff --git a/Example/Example/UICategoryTests/TextFields/GIOTextFieldViewController.m b/Example/Example/UICategoryTests/TextFields/GIOTextFieldViewController.m index 089f3dd14..57bd813e2 100644 --- a/Example/Example/UICategoryTests/TextFields/GIOTextFieldViewController.m +++ b/Example/Example/UICategoryTests/TextFields/GIOTextFieldViewController.m @@ -22,7 +22,11 @@ @implementation GIOTextFieldViewController - (void)viewDidLoad { [super viewDidLoad]; - +#if defined(AUTOTRACKER) +#if defined(SDK3rd) + [[GrowingAutotracker sharedInstance] autotrackPage:self alias:@"输入事件测试" attributes:@{@"greet": @"hello"}]; +#endif +#endif [self configureTextField]; [self configureTintedTextField]; [self configureSecureTextField]; diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m index 0ed4e8aaa..bbf97d7f5 100644 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m +++ b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m @@ -108,31 +108,6 @@ - (void)testSetUserIdAndUserKeyTest { [self waitForExpectationsWithTimeout:10.0f handler:nil]; } -//- (void)testSetConversionVariables { -// { -// [[GrowingAutotracker sharedInstance] setConversionVariables:@{@"key" : @"value"}]; -// NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeConversionVariables]; -// XCTAssertEqual(events.count, 1); -// -// GrowingConversionVariableEvent *event = (GrowingConversionVariableEvent *)events.firstObject; -// XCTAssertEqualObjects(event.attributes[@"key"], @"value"); -// } -// -// { -// [MockEventQueue.sharedQueue cleanQueue]; -//#pragma clang diagnostic push -//#pragma clang diagnostic ignored "-Wincompatible-pointer-types" -//#pragma clang diagnostic ignored "-Wobjc-literal-conversion" -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setConversionVariables:nil]); -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setConversionVariables:@"value"]); -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setConversionVariables:@{@1 : @"value"}]); -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setConversionVariables:@{@"key" : @1}]); -//#pragma clang diagnostic pop -// NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeConversionVariables]; -// XCTAssertEqual(events.count, 0); -// } -//} - - (void)testSetLoginUserAttributes { { [[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@"key" : @"value"}]; @@ -158,31 +133,6 @@ - (void)testSetLoginUserAttributes { } } -//- (void)testSetVisitorAttributes { -// { -// [[GrowingAutotracker sharedInstance] setVisitorAttributes:@{@"key" : @"value"}]; -// NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisitorAttributes]; -// XCTAssertEqual(events.count, 1); -// -// GrowingVisitorAttributesEvent *event = (GrowingVisitorAttributesEvent *)events.firstObject; -// XCTAssertEqualObjects(event.attributes[@"key"], @"value"); -// } -// -// { -// [MockEventQueue.sharedQueue cleanQueue]; -//#pragma clang diagnostic push -//#pragma clang diagnostic ignored "-Wincompatible-pointer-types" -//#pragma clang diagnostic ignored "-Wobjc-literal-conversion" -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setVisitorAttributes:nil]); -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setVisitorAttributes:@"value"]); -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setVisitorAttributes:@{@1 : @"value"}]); -// XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setVisitorAttributes:@{@"key" : @1}]); -//#pragma clang diagnostic pop -// NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisitorAttributes]; -// XCTAssertEqual(events.count, 0); -// } -//} - - (void)testTrackCustomEvent { { [[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName"]; @@ -754,6 +704,61 @@ - (void)testAutotrackPageWithAttributesTest { [self waitForExpectationsWithTimeout:3.0f handler:nil]; } +- (void)testAutotrackPageWithInvalidAliasTest { + UIViewController *controller = [[UIViewController alloc] init]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wincompatible-pointer-types" + [[GrowingAutotracker sharedInstance] autotrackPage:nil alias:@"XCTest"]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:nil]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@""]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@1]; +#pragma clang diagnostic pop + [controller viewDidAppear:NO]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithInvalidAliasTest Test failed : timeout"]; + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertEqual(events.count, 0); + + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:3.0f handler:nil]; +} + +- (void)testAutotrackPageWithInvalidAttributesTest { + UIViewController *controller = [[UIViewController alloc] init]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wincompatible-pointer-types" +#pragma clang diagnostic ignored "-Wobjc-literal-conversion" + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:nil]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@"value"]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@1 : @"value"}]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @1}]; +#pragma clang diagnostic pop + [controller viewDidAppear:NO]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithInvalidAttributesTest Test failed : timeout"]; + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertEqual(events.count, 0); + + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:3.0f handler:nil]; +} + +- (void)testAutotrackPageInNotMainThreadTest { + { + UIViewController *controller = [[UIViewController alloc] init]; + dispatch_sync(dispatch_get_global_queue(0, 0), ^{ + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest"]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @"value"}]); + }); + } +} + @end #pragma clang diagnostic pop diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m index 292e17739..adf0042a5 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m @@ -101,4 +101,35 @@ - (void)test03DataPicker { [[viewTester usingLabel:@"协议/接口"] tap]; } +- (void)test04Slider { + [[viewTester usingLabel:@"UI界面"] tap]; + [[viewTester usingLabel:@"Simple UI Elements"] tap]; + [viewTester waitForAnimationsToFinish]; + + KIFUIViewTestActor *actor = [viewTester usingLabel:@"defaultSlider"]; + { + actor.view.growingViewIgnorePolicy = GrowingIgnoreSelf; + [actor setSliderValue:75.0f]; + + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; + XCTAssertEqual(events.count, 0); + } + + { + actor.view.growingViewIgnorePolicy = GrowingIgnoreNone; + [actor setSliderValue:50.0f]; + + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; + XCTAssertEqual(events.count, 1); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewChange); + XCTAssertTrue([ManualTrackHelper viewChangeEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + } + + [[viewTester usingLabel:@"UI界面"] tap]; +} + @end diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m index 96c0fbb60..63d8ceb7d 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m @@ -20,8 +20,6 @@ #import #import "GrowingAutotrackerCore/Autotrack/GrowingPropertyDefine.h" #import "GrowingAutotrackerCore/Page/GrowingPage.h" -#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" -#import "GrowingTrackerCore/Utils/GrowingArgumentChecker.h" #import "GrowingULViewControllerLifecycle.h" static char kGrowingPageObjectKey; @@ -56,18 +54,7 @@ - (GrowingPage *)growingPageObject { GrowingSafeStringPropertyImplementation(growingPageAlias, setGrowingPageAlias) - (void)setGrowingPageAttributes:(NSDictionary *)attributes { - [GrowingDispatchManager - trackApiSel:_cmd - dispatchInMainThread:^{ - if (!attributes || ([attributes isKindOfClass:NSDictionary.class] && attributes.count == 0)) { - objc_setAssociatedObject(self, &kGrowingPageAttributesKey, nil, OBJC_ASSOCIATION_COPY_NONATOMIC); - } else { - if ([GrowingArgumentChecker isIllegalAttributes:attributes]) { - return; - } - objc_setAssociatedObject(self, &kGrowingPageAttributesKey, attributes, OBJC_ASSOCIATION_COPY_NONATOMIC); - } - }]; + objc_setAssociatedObject(self, &kGrowingPageAttributesKey, attributes, OBJC_ASSOCIATION_COPY_NONATOMIC); } - (NSDictionary *)growingPageAttributes { diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 01830b3ce..46ede4ead 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -79,10 +79,6 @@ + (GrowingViewNode *)getViewNode:(UIView *)view { } + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakArray { - if (weakArray == nil) { - weakArray = [NSPointerArray weakObjectsPointerArray]; - } - id parent = view; do { if (![self isIgnoredPrivateView:parent]) { diff --git a/GrowingAutotrackerCore/GrowingRealAutotracker.m b/GrowingAutotrackerCore/GrowingRealAutotracker.m index a77fb0d21..8e5dba2c7 100644 --- a/GrowingAutotrackerCore/GrowingRealAutotracker.m +++ b/GrowingAutotrackerCore/GrowingRealAutotracker.m @@ -36,6 +36,8 @@ #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" +#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" +#import "GrowingTrackerCore/Utils/GrowingArgumentChecker.h" #import "GrowingULSwizzle.h" #import "GrowingULViewControllerLifecycle.h" @@ -71,13 +73,26 @@ - (void)ignoreViewClasses:(NSArray *)classes { } - (void)autotrackPage:(UIViewController *)controller alias:(NSString *)alias { - [GrowingPageManager.sharedInstance autotrackPage:controller alias:alias attributes:nil]; + [GrowingDispatchManager trackApiSel:_cmd + dispatchInMainThread:^{ + if ([GrowingArgumentChecker isIllegalEventName:alias]) { + return; + } + [GrowingPageManager.sharedInstance autotrackPage:controller alias:alias attributes:nil]; + }]; } - (void)autotrackPage:(UIViewController *)controller alias:(NSString *)alias attributes:(NSDictionary *)attributes { - [GrowingPageManager.sharedInstance autotrackPage:controller alias:alias attributes:attributes]; + [GrowingDispatchManager trackApiSel:_cmd + dispatchInMainThread:^{ + if ([GrowingArgumentChecker isIllegalEventName:alias] || + [GrowingArgumentChecker isIllegalAttributes:attributes]) { + return; + } + [GrowingPageManager.sharedInstance autotrackPage:controller alias:alias attributes:attributes]; + }]; } - (void)addAutoTrackSwizzles { diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.m b/GrowingAutotrackerCore/Page/GrowingPageManager.m index 302c36197..778c3d7e0 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.m +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.m @@ -181,12 +181,6 @@ - (void)autotrackPage:(UIViewController *)controller if (controller == nil) { return; } - if ([NSString growingHelper_isBlankString:alias]) { - return; - } - if (attributes != nil && [GrowingArgumentChecker isIllegalAttributes:attributes]) { - return; - } BOOL needAutotrackPage = NO; GrowingPage *page = controller.growingPageObject; From a39bdf9221c0632f73c70aa48ca685830860c39c Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 13 Jul 2023 16:15:24 +0800 Subject: [PATCH 030/126] =?UTF-8?q?refactor:=20ImpressionTrack=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8C=96=EF=BC=8C=E6=8C=89=E9=9C=80=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/Example.xcodeproj/project.pbxproj | 4 +- .../ClickEvent/GIOClickEventViewController.m | 1 + .../GrowingNodeTests/NodeTest.m | 1 - Example/Podfile | 7 +- GrowingAnalytics.podspec | 7 + GrowingAutotracker/GrowingAutotracker.h | 27 ---- .../Autotrack/UIView+GrowingAutotracker.m | 33 ----- .../Category/UIAlertController+GrowingNode.m | 18 --- .../UINavigationController+GrowingNode.m | 14 -- .../Category/UITabBarController+GrowingNode.m | 18 --- .../GrowingNode/Category/UIView+GrowingNode.h | 3 - .../GrowingNode/Category/UIView+GrowingNode.m | 105 ------------- .../Category/UIViewController+GrowingNode.m | 71 --------- .../GrowingRealAutotracker.m | 14 -- .../Event/GrowingNodeProtocol.h | 6 +- .../ImpressionTrack}/GrowingImpressionTrack.h | 18 +-- .../ImpressionTrack}/GrowingImpressionTrack.m | 121 ++++++++------- .../Public/UIView+GrowingImpression.h | 50 +++++++ .../UIView+GrowingImpressionInternal.h | 13 +- .../UIView+GrowingImpressionInternal.m | 138 ++++++++++++++++++ Package.swift | 13 ++ Podfile.lock | 7 +- 22 files changed, 302 insertions(+), 387 deletions(-) delete mode 100644 GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.m rename {GrowingAutotrackerCore/Impression => Modules/ImpressionTrack}/GrowingImpressionTrack.h (76%) rename {GrowingAutotrackerCore/Impression => Modules/ImpressionTrack}/GrowingImpressionTrack.m (90%) create mode 100644 Modules/ImpressionTrack/Public/UIView+GrowingImpression.h rename GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.h => Modules/ImpressionTrack/UIView+GrowingImpressionInternal.h (62%) create mode 100644 Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index acd1a4536..0e7cce2fd 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -1730,7 +1730,7 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Example/Pods-Example-frameworks.sh", "${BUILT_PRODUCTS_DIR}/GrowingAPM/GrowingAPM.framework", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-4a08faf1/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-411db831/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingToolsKit/GrowingToolsKit.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/LBXScan/LBXScan.framework", @@ -1937,7 +1937,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsTests/Pods-GrowingAnalyticsTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-0637fae5/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-bae859d0/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", ); name = "[CP] Embed Pods Frameworks"; diff --git a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m index eba861554..eb8818933 100644 --- a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m +++ b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m @@ -8,6 +8,7 @@ #import "GIOClickEventViewController.h" #import "AppDelegate.h" +#import "UIView+GrowingImpression.h" @interface GIOClickEventViewController () diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m index cb406252a..3c8162114 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m @@ -47,7 +47,6 @@ -(void)testGrowingUIViewController { [vc1 performSelector:@selector(growingNodeSubPath)]; [vc1 performSelector:@selector(growingNodeSubIndex)]; [vc1 performSelector:@selector(growingNodeSubSimilarIndex)]; - [vc1 performSelector:@selector(growingNodeChilds)]; #pragma clang diagnostic pop } diff --git a/Example/Podfile b/Example/Podfile index 074f901ff..88b9126dd 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -22,6 +22,8 @@ target 'Example' do # pod 'GrowingAPM/UIMonitor' # pod 'GrowingAPM/CrashMonitor' pod 'GrowingAnalytics/APM', :path => '../' + + pod 'GrowingAnalytics/ImpressionTrack', :path => '../' pod 'SDCycleScrollView', '~> 1.75' pod 'LBXScan/LBXNative', '2.3' @@ -33,11 +35,12 @@ end target 'GrowingAnalyticsTests' do pod 'GrowingAnalytics/Autotracker', :path => '../' pod 'GrowingAnalytics/Tracker', :path => '../' + pod 'GrowingAnalytics/ImpressionTrack', :path => '../' end target 'GrowingAnalyticsStartTests' do - pod 'GrowingAnalytics/Autotracker', :path => './' - pod 'GrowingAnalytics/Tracker', :path => './' + pod 'GrowingAnalytics/Autotracker', :path => '../' + pod 'GrowingAnalytics/Tracker', :path => '../' end target 'HostApplicationTests' do diff --git a/GrowingAnalytics.podspec b/GrowingAnalytics.podspec index 6a7575839..3222f9757 100644 --- a/GrowingAnalytics.podspec +++ b/GrowingAnalytics.podspec @@ -125,6 +125,13 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 webcircle.dependency 'GrowingAnalytics/Screenshot', s.version.to_s end + s.subspec 'ImpressionTrack' do |imptrack| + imptrack.ios.deployment_target = '9.0' + imptrack.source_files = 'Modules/ImpressionTrack/**/*{.h,.m,.c,.cpp,.mm}' + imptrack.public_header_files = 'Modules/ImpressionTrack/Public/*.h' + imptrack.dependency 'GrowingAnalytics/AutotrackerCore', s.version.to_s + end + s.subspec 'Hybrid' do |hybrid| hybrid.ios.deployment_target = '10.0' hybrid.source_files = 'Modules/Hybrid/**/*{.h,.m,.c,.cpp,.mm}' diff --git a/GrowingAutotracker/GrowingAutotracker.h b/GrowingAutotracker/GrowingAutotracker.h index 3431963b8..9dff07194 100644 --- a/GrowingAutotracker/GrowingAutotracker.h +++ b/GrowingAutotracker/GrowingAutotracker.h @@ -146,33 +146,6 @@ NS_ASSUME_NONNULL_BEGIN @end -// imp半自动打点 -@interface UIView (GrowingImpression) - -/** - 以下为元素展示打点事件 - 在元素展示前调用即可,GIO负责监听元素展示并触发事件 - 事件类型为自定义事件(cstm) - @param eventName 自定义事件名称 - */ -- (void)growingTrackImpression:(NSString *)eventName; - -/** - 以下为元素展示打点事件 - 在元素展示前调用即可,GIO负责监听元素展示并触发事件 - 事件类型为自定义事件(cstm) - @param eventName 自定义事件名称 - @param attributes 自定义属性 - */ -- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *)attributes; - -// 停止该元素展示追踪 -// 通常应用于列表中的重用元素 -// 例如您只想追踪列表中的第一行元素的展示,但当第四行出现时重用了第一行的元素,此时您可调用此函数避免事件触发 -- (void)growingStopTrackImpression; - -@end - // 该属性setter方法均使用 objc_setAssociatedObject实现 // 如果是自定义的View建议优先使用重写getter方法来实现 以提高性能 @interface UIView (GrowingAttributes) diff --git a/GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.m deleted file mode 100644 index bcaff4469..000000000 --- a/GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// UIView+GrowingAutoTrack.m -// GrowingAnalytics -// -// Created by GrowingIO on 2020/7/23. -// Copyright (C) 2020 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" - -@implementation UIView (GrowingAutotracker) - -- (void)growing_didMoveToSuperview { - [self growing_didMoveToSuperview]; - - if (self.superview && self.window) { - [[GrowingImpressionTrack sharedInstance] addNode:self inSubView:YES]; - } -} - -@end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m index d2922fc6e..bbb9ae059 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m @@ -29,24 +29,6 @@ - (CGRect)growingNodeFrame { return [self.view growingNodeFrame]; } -- (NSArray > *)growingNodeChilds { - NSMutableArray *childs = [NSMutableArray array]; - NSMapTable *allButton = [self growing_allActionViews]; - for (UIView *view in [allButton keyEnumerator]) { - [childs addObject:view]; - } - - UIView *view = nil; - if ([self.view growingHelper_getIvar:"_titleLabel" outObj:&view]) { - [childs addObject:view]; - } - if ([self.view growingHelper_getIvar:"_messageLabel" outObj:&view]) { - [childs addObject:view]; - } - - return childs; -} - @end @implementation GrowingAlertSwizzleHelper diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UINavigationController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UINavigationController+GrowingNode.m index 950f5b587..63d39a3cc 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UINavigationController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UINavigationController+GrowingNode.m @@ -37,19 +37,5 @@ - (CGRect)growingNodeFrame { return rect; } -- (NSArray> *)growingNodeChilds { - NSMutableArray *childs = [NSMutableArray array]; - if (self.presentedViewController) { - [childs addObject:self.presentedViewController]; - return childs; - } - - [childs addObject:self.topViewController]; - - if (self.isViewLoaded && [self.navigationBar growingImpNodeIsVisible]) { - [childs addObject:self.navigationBar]; - } - return childs; -} @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITabBarController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITabBarController+GrowingNode.m index f9f3f1205..d3a11037e 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITabBarController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITabBarController+GrowingNode.m @@ -22,24 +22,6 @@ @implementation UITabBarController (GrowingNode) -- (NSArray> *)growingNodeChilds { - NSMutableArray *childs = [NSMutableArray array]; - if (self.presentedViewController) { - [childs addObject:self.presentedViewController]; - return childs; - } - - if (self.selectedViewController) { - [childs addObject:self.selectedViewController]; - } - - if (self.isViewLoaded && [self.tabBar growingImpNodeIsVisible]) { - [childs addObject:self.tabBar]; - } - - return childs; -} - - (CGRect)growingNodeFrame { return self.view.growingNodeFrame; } diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h index b47581baf..f911d89af 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h @@ -23,9 +23,6 @@ @interface UIView (GrowingNode) -@property (nonatomic, assign) BOOL growingIMPTracked; -@property (nonatomic, copy) NSString *growingIMPTrackEventName; -@property (nonatomic, strong) NSDictionary *growingIMPTrackVariable; @property (nonatomic, copy) NSString *growingUniqueTag; - (BOOL)growingViewUserInteraction; - (NSString *)growingViewContent; diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index b35620082..60db21f1f 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -22,7 +22,6 @@ #import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" -#import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" @@ -118,52 +117,6 @@ - (BOOL)growingViewNodeIsInvisiable { return (self.hidden || self.alpha < 0.001 || !self.superview || !self.window); } -- (BOOL)growingImpNodeIsVisible { - if (!self.window || self.hidden || self.alpha < 0.001 || !self.superview) { - return NO; - } - - CGRect rect = [self growingNodeFrame]; - CGRect intersectionRect = CGRectIntersection([UIScreen mainScreen].bounds, rect); - - if (CGRectIsEmpty(intersectionRect) || CGRectIsNull(intersectionRect)) { - return NO; - } - - BOOL isInScreen; - double impScale = 0.0; - GrowingTrackConfiguration *configuration = GrowingConfigurationManager.sharedInstance.trackConfiguration; - if ([configuration isKindOfClass:[GrowingAutotrackConfiguration class]]) { - impScale = ((GrowingAutotrackConfiguration *)configuration).impressionScale; - } - - if (impScale == 0.0) { - isInScreen = YES; - } else { - if (intersectionRect.size.width * intersectionRect.size.height >= - self.bounds.size.width * self.bounds.size.height * impScale) { - isInScreen = YES; - } else { - isInScreen = NO; - } - } - - if (isInScreen) { - UIResponder *curNode = self.nextResponder; - while (curNode) { - if (!curNode.isProxy && [curNode isKindOfClass:[UIView class]]) { - if (((UIView *)curNode).hidden == YES || ((UIView *)curNode).alpha < 0.001) { - return NO; - } - } - curNode = curNode.nextResponder; - } - return YES; - } - - return NO; -} - // 关系 - (BOOL)growingNodeDonotTrack { if ([self isKindOfClass:NSClassFromString(@"_UINavigationItemButtonView")]) { @@ -283,33 +236,6 @@ - (void)setGrowingViewCustomContent:(NSString *)content { objc_setAssociatedObject(self, @selector(growingViewCustomContent), content, OBJC_ASSOCIATION_COPY_NONATOMIC); } -- (BOOL)growingIMPTracked { - return [objc_getAssociatedObject(self, @selector(growingIMPTracked)) boolValue]; -} - -- (void)setGrowingIMPTracked:(BOOL)flag { - objc_setAssociatedObject(self, - @selector(growingIMPTracked), - [NSNumber numberWithBool:flag], - OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (NSString *)growingIMPTrackEventName { - return objc_getAssociatedObject(self, @selector(growingIMPTrackEventName)); -} - -- (void)setGrowingIMPTrackEventName:(NSString *)eventId { - objc_setAssociatedObject(self, @selector(growingIMPTrackEventName), eventId, OBJC_ASSOCIATION_COPY_NONATOMIC); -} - -- (NSDictionary *)growingIMPTrackVariable { - return objc_getAssociatedObject(self, @selector(growingIMPTrackVariable)); -} - -- (void)setGrowingIMPTrackVariable:(NSDictionary *)variable { - objc_setAssociatedObject(self, @selector(growingIMPTrackVariable), variable, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - - (void)setGrowingViewIgnorePolicy:(GrowingIgnorePolicy)growingIgonrePolicy { objc_setAssociatedObject(self, @selector(growingViewIgnorePolicy), @@ -334,34 +260,3 @@ - (GrowingIgnorePolicy)growingViewIgnorePolicy { GrowingSafeStringPropertyImplementation(growingUniqueTag, setGrowingUniqueTag) @end - -@implementation UIView (GrowingImpression) - -- (void)growingTrackImpression:(NSString *)eventName { - [self growingTrackImpression:eventName attributes:nil]; -} - -- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *)attributes { - if (eventName.length == 0) { - return; - } - - if (self.growingIMPTrackEventName && [eventName isEqualToString:self.growingIMPTrackEventName]) { - if ((attributes && [attributes isEqualToDictionary:self.growingIMPTrackVariable]) || - attributes == self.growingIMPTrackVariable) { - return; - } - } - - [GrowingImpressionTrack sharedInstance].impTrackActive = YES; - - self.growingIMPTrackEventName = eventName; - self.growingIMPTrackVariable = attributes; - self.growingIMPTracked = NO; - [[GrowingImpressionTrack sharedInstance] addNode:self inSubView:NO]; -} - -- (void)growingStopTrackImpression { - [[GrowingImpressionTrack sharedInstance] clearNode:self]; -} -@end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m index c81a76c5d..b9de68bac 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m @@ -141,75 +141,4 @@ - (NSString *)growingNodeSubSimilarIndex { return [self growingNodeSubIndex]; } -- (NSArray> *)growingNodeChilds { - NSMutableArray *childs = [NSMutableArray array]; - - if (self.presentedViewController) { - [childs addObject:self.presentedViewController]; - return childs; - } - // ViewController中childViewController.view与self.view.subviews中重复,去除重复元素 - // 这里仅去除self.view上的重复,self.view.view的重复暂不考虑 - UIView *currentView = self.view; - if (currentView && self.isViewLoaded && currentView.growingImpNodeIsVisible) { - [childs addObjectsFromArray:self.view.subviews]; - if (self.childViewControllers.count > 0 && ![self isKindOfClass:UIAlertController.class]) { - // 是否包含全屏视图 - __block BOOL isContainFullScreen = NO; - - NSArray *childViewControllers = self.childViewControllers; - [childViewControllers - enumerateObjectsWithOptions:NSEnumerationReverse - usingBlock:^(__kindof UIViewController *_Nonnull obj, - NSUInteger idx, - BOOL *_Nonnull stop) { - if (obj.isViewLoaded) { - UIView *objSuperview = obj.view; - for (long i = (long)(childs.count - 1); i >= 0; i--) { - UIView *childview = childs[i]; - // 如果childview包含或者等于objsuperview - if ([objSuperview isDescendantOfView:childview]) { - // xib拖拽的viewController会被一个自定义的view包裹,判断其subviews数量是否为1 - if ([childview isEqual:objSuperview] || - (childview.subviews.count == 1 && - [childview.subviews.lastObject isEqual:objSuperview])) { - // NSInteger index = [childs - // indexOfObject:objSuperview]; - if ([objSuperview growingImpNodeIsVisible] && - !isContainFullScreen) { - [childs replaceObjectAtIndex:i withObject:obj]; - } else { - [childs removeObject:childview]; - } - } - } - } - - CGRect rect = [obj.view convertRect:obj.view.bounds toView:nil]; - // 是否全屏 - BOOL isFullScreenShow = - CGPointEqualToPoint(rect.origin, CGPointMake(0, 0)) && - CGSizeEqualToSize( - rect.size, - [UIApplication sharedApplication].growingMainWindow.bounds.size); - // 正在全屏显示 - if (isFullScreenShow && [obj.view growingImpNodeIsVisible]) { - isContainFullScreen = YES; - } - } - }]; - } - - [childs addObject:currentView]; - return childs; - } - - if ([self isKindOfClass:UIPageViewController.class]) { - UIPageViewController *pageViewController = (UIPageViewController *)self; - [childs addObject:pageViewController.viewControllers]; - } - - return childs; -} - @end diff --git a/GrowingAutotrackerCore/GrowingRealAutotracker.m b/GrowingAutotrackerCore/GrowingRealAutotracker.m index 8e5dba2c7..7c6a5e42f 100644 --- a/GrowingAutotrackerCore/GrowingRealAutotracker.m +++ b/GrowingAutotrackerCore/GrowingRealAutotracker.m @@ -25,14 +25,10 @@ #import "GrowingAutotrackerCore/Autotrack/UISegmentedControl+GrowingAutotracker.h" #import "GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.h" #import "GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.h" -#import "GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h" -#import "GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h" #import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingAutotrackConfiguration+Private.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h" -#import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" @@ -57,7 +53,6 @@ - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration [self addAutoTrackSwizzles]; [GrowingULViewControllerLifecycle setup]; [GrowingPageManager.sharedInstance start]; - [GrowingImpressionTrack.sharedInstance start]; } } @@ -123,15 +118,6 @@ - (void)addAutoTrackSwizzles { GIOLogError(@"Failed to swizzle UISegmentControl. Details: %@", segmentControlError); } - // UIView - NSError *viewError = NULL; - [UIView growingul_swizzleMethod:@selector(didMoveToSuperview) - withMethod:@selector(growing_didMoveToSuperview) - error:&viewError]; - if (viewError) { - GIOLogError(@"Failed to swizzle UIView. Details: %@", viewError); - } - // NSNotificationCenter NSError *notiError = NULL; [NSNotificationCenter growingul_swizzleMethod:@selector(postNotificationName:object:userInfo:) diff --git a/GrowingTrackerCore/Event/GrowingNodeProtocol.h b/GrowingTrackerCore/Event/GrowingNodeProtocol.h index 24821f66b..9af29a693 100644 --- a/GrowingTrackerCore/Event/GrowingNodeProtocol.h +++ b/GrowingTrackerCore/Event/GrowingNodeProtocol.h @@ -34,8 +34,6 @@ @property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubSimilarIndex; /// 原始父节点 - (id _Nullable)growingNodeParent; -/// 过滤后的子节点,例如UITableView子节点只需要是cell和footter -- (NSArray> *_Nullable)growingNodeChilds; /// 不进行track - (BOOL)growingNodeDonotTrack; /// 不进行圈选 @@ -48,7 +46,7 @@ - (CGRect)growingNodeFrame; @optional - -- (BOOL)growingImpNodeIsVisible; +/// 过滤后的子节点,例如UITableView子节点只需要是cell和footter +- (NSArray> *_Nullable)growingNodeChilds; @end diff --git a/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h b/Modules/ImpressionTrack/GrowingImpressionTrack.h similarity index 76% rename from GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h rename to Modules/ImpressionTrack/GrowingImpressionTrack.h index 6781b9903..4cf3d28d8 100644 --- a/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h +++ b/Modules/ImpressionTrack/GrowingImpressionTrack.h @@ -2,8 +2,8 @@ // GrowingImpressionTrack.h // GrowingAnalytics // -// Created by GrowingIO on 2019/5/9. -// Copyright (C) 2019 Beijing Yishu Technology Co., Ltd. +// Created by YoloMao on 2023/7/13. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,25 +19,15 @@ #import #import +#import "GrowingModuleProtocol.h" -@interface GrowingImpressionTrack : NSObject +@interface GrowingImpressionTrack : NSObject @property (nonatomic, assign) NSTimeInterval IMPInterval; - @property (nonatomic, assign) BOOL impTrackActive; + (instancetype)sharedInstance; - -- (void)start; - -- (void)markInvisibleNodes; - -- (void)markInvisibleNode:(UIView *)node inSubView:(BOOL)flag; - -- (void)addWindowNodes; - - (void)addNode:(UIView *)node inSubView:(BOOL)flag; - - (void)clearNode:(UIView *)node; @end diff --git a/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.m b/Modules/ImpressionTrack/GrowingImpressionTrack.m similarity index 90% rename from GrowingAutotrackerCore/Impression/GrowingImpressionTrack.m rename to Modules/ImpressionTrack/GrowingImpressionTrack.m index 820f311d4..1069d62be 100644 --- a/GrowingAutotrackerCore/Impression/GrowingImpressionTrack.m +++ b/Modules/ImpressionTrack/GrowingImpressionTrack.m @@ -2,8 +2,8 @@ // GrowingImpressionTrack.m // GrowingAnalytics // -// Created by GrowingIO on 2019/5/9. -// Copyright (C) 2019 Beijing Yishu Technology Co., Ltd. +// Created by YoloMao on 2023/7/13. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,14 +17,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "GrowingAutotrackerCore/Impression/GrowingImpressionTrack.h" +#import "Modules/ImpressionTrack/GrowingImpressionTrack.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" #import "GrowingTrackerCore/Event/GrowingEventGenerator.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingULAppLifecycle.h" +#import "GrowingULSwizzle.h" #import "GrowingULViewControllerLifecycle.h" +#import "Modules/ImpressionTrack/UIView+GrowingImpressionInternal.h" + +GrowingMod(GrowingImpressionTrack) @interface GrowingImpressionTrack () @@ -36,36 +40,47 @@ @interface GrowingImpressionTrack () + +NS_ASSUME_NONNULL_BEGIN + +@interface UIView (GrowingImpression) + +/** + 以下为元素展示打点事件 + 在元素展示前调用即可,GIO负责监听元素展示并触发事件 + 事件类型为自定义事件(cstm) + @param eventName 自定义事件名称 + */ +- (void)growingTrackImpression:(NSString *)eventName; + +/** + 以下为元素展示打点事件 + 在元素展示前调用即可,GIO负责监听元素展示并触发事件 + 事件类型为自定义事件(cstm) + @param eventName 自定义事件名称 + @param attributes 自定义属性 + */ +- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *)attributes; + +// 停止该元素展示追踪 +// 通常应用于列表中的重用元素 +// 例如您只想追踪列表中的第一行元素的展示,但当第四行出现时重用了第一行的元素,此时您可调用此函数避免事件触发 +- (void)growingStopTrackImpression; + +@end + +NS_ASSUME_NONNULL_END diff --git a/GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.h b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.h similarity index 62% rename from GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.h rename to Modules/ImpressionTrack/UIView+GrowingImpressionInternal.h index c58332cd7..c86d1252b 100644 --- a/GrowingAutotrackerCore/Autotrack/UIView+GrowingAutotracker.h +++ b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.h @@ -1,9 +1,9 @@ // -// UIView+GrowingAutoTrack.h +// UIView+GrowingImpressionInternal.h // GrowingAnalytics // -// Created by GrowingIO on 2020/7/23. -// Copyright (C) 2020 Beijing Yishu Technology Co., Ltd. +// Created by YoloMao on 2023/7/13. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,9 +21,14 @@ NS_ASSUME_NONNULL_BEGIN -@interface UIView (GrowingAutotracker) +@interface UIView (GrowingImpressionInternal) + +@property (nonatomic, assign) BOOL growingIMPTracked; +@property (nonatomic, copy, nullable) NSString *growingIMPTrackEventName; +@property (nonatomic, copy, nullable) NSDictionary *growingIMPTrackVariable; - (void)growing_didMoveToSuperview; +- (BOOL)growingImpNodeIsVisible; @end diff --git a/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m new file mode 100644 index 000000000..804cd5c67 --- /dev/null +++ b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m @@ -0,0 +1,138 @@ +// +// UIView+GrowingImpressionInternal.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/13. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import +#import "GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h" +#import "GrowingAutotrackerCore/Public/GrowingAutotrackConfiguration.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "Modules/ImpressionTrack/GrowingImpressionTrack.h" +#import "Modules/ImpressionTrack/UIView+GrowingImpressionInternal.h" + +@implementation UIView (GrowingImpressionInternal) + +- (void)growing_didMoveToSuperview { + [self growing_didMoveToSuperview]; + + if (self.superview && self.window) { + [[GrowingImpressionTrack sharedInstance] addNode:self inSubView:YES]; + } +} + +- (BOOL)growingIMPTracked { + return [objc_getAssociatedObject(self, @selector(growingIMPTracked)) boolValue]; +} + +- (void)setGrowingIMPTracked:(BOOL)flag { + objc_setAssociatedObject(self, + @selector(growingIMPTracked), + [NSNumber numberWithBool:flag], + OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (NSString *)growingIMPTrackEventName { + return objc_getAssociatedObject(self, @selector(growingIMPTrackEventName)); +} + +- (void)setGrowingIMPTrackEventName:(NSString *)eventId { + objc_setAssociatedObject(self, @selector(growingIMPTrackEventName), eventId, OBJC_ASSOCIATION_COPY_NONATOMIC); +} + +- (NSDictionary *)growingIMPTrackVariable { + return objc_getAssociatedObject(self, @selector(growingIMPTrackVariable)); +} + +- (void)setGrowingIMPTrackVariable:(NSDictionary *)variable { + objc_setAssociatedObject(self, @selector(growingIMPTrackVariable), variable, OBJC_ASSOCIATION_COPY_NONATOMIC); +} + +- (BOOL)growingImpNodeIsVisible { + if (!self.window || self.hidden || self.alpha < 0.001 || !self.superview) { + return NO; + } + + CGRect rect = [self growingNodeFrame]; + CGRect intersectionRect = CGRectIntersection([UIScreen mainScreen].bounds, rect); + + if (CGRectIsEmpty(intersectionRect) || CGRectIsNull(intersectionRect)) { + return NO; + } + + BOOL isInScreen; + double impScale = 0.0; + GrowingTrackConfiguration *configuration = GrowingConfigurationManager.sharedInstance.trackConfiguration; + if ([configuration isKindOfClass:[GrowingAutotrackConfiguration class]]) { + impScale = ((GrowingAutotrackConfiguration *)configuration).impressionScale; + } + + if (impScale == 0.0) { + isInScreen = YES; + } else { + if (intersectionRect.size.width * intersectionRect.size.height >= + self.bounds.size.width * self.bounds.size.height * impScale) { + isInScreen = YES; + } else { + isInScreen = NO; + } + } + + if (isInScreen) { + UIResponder *curNode = self.nextResponder; + while (curNode) { + if (!curNode.isProxy && [curNode isKindOfClass:[UIView class]]) { + if (((UIView *)curNode).hidden == YES || ((UIView *)curNode).alpha < 0.001) { + return NO; + } + } + curNode = curNode.nextResponder; + } + return YES; + } + + return NO; +} + +- (void)growingTrackImpression:(NSString *)eventName { + [self growingTrackImpression:eventName attributes:nil]; +} + +- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *)attributes { + if (eventName.length == 0) { + return; + } + + if (self.growingIMPTrackEventName && [eventName isEqualToString:self.growingIMPTrackEventName]) { + if ((attributes && [attributes isEqualToDictionary:self.growingIMPTrackVariable]) || + attributes == self.growingIMPTrackVariable) { + return; + } + } + + [GrowingImpressionTrack sharedInstance].impTrackActive = YES; + + self.growingIMPTrackEventName = eventName; + self.growingIMPTrackVariable = attributes; + self.growingIMPTracked = NO; + [[GrowingImpressionTrack sharedInstance] addNode:self inSubView:NO]; +} + +- (void)growingStopTrackImpression { + [[GrowingImpressionTrack sharedInstance] clearNode:self]; +} + +@end diff --git a/Package.swift b/Package.swift index 18e530f7d..c6b02101f 100644 --- a/Package.swift +++ b/Package.swift @@ -42,6 +42,10 @@ let package = Package( name: "GrowingTracker_NoIDFA", targets: ["GrowingTracker_NoIDFA_Wrapper"] ), + .library( + name: "GrowingModule_ImpressionTrack", + targets: ["GrowingModule_ImpressionTrack"] + ), .library( name: "GrowingModule_Hybrid", targets: ["GrowingModule_Hybrid"] @@ -278,6 +282,15 @@ let package = Package( .headerSearchPath("../.."), ] ), + .target( + name: "GrowingModule_ImpressionTrack", + dependencies: ["GrowingAutotrackerCore"], + path: "Modules/ImpressionTrack", + publicHeadersPath: "Public", + cSettings: [ + .headerSearchPath("../..") + ] + ), .target( name: "GrowingModule_Hybrid", dependencies: ["GrowingTrackerCore"], diff --git a/Podfile.lock b/Podfile.lock index 51ee40855..8b54ab8f2 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -27,6 +27,8 @@ PODS: - GrowingAnalytics/TrackerCore (= 3.5.0) - GrowingAnalytics/Hybrid (3.5.0): - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/ImpressionTrack (3.5.0): + - GrowingAnalytics/AutotrackerCore (= 3.5.0) - GrowingAnalytics/MobileDebugger (3.5.0): - GrowingAnalytics/Screenshot (= 3.5.0) - GrowingAnalytics/TrackerCore (= 3.5.0) @@ -122,6 +124,7 @@ DEPENDENCIES: - GrowingAnalytics/Advert (from `./`) - GrowingAnalytics/APM (from `./`) - GrowingAnalytics/Autotracker (from `./`) + - GrowingAnalytics/ImpressionTrack (from `./`) - GrowingAnalytics/Protobuf (from `./`) - GrowingAnalytics/Tracker (from `./`) - GrowingAPM @@ -147,7 +150,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: 80b480f3c662876f701eea99caf3164661f1aee4 + GrowingAnalytics: a01857dc934fa4b0b0b4a04b46d888d2472d5fa2 GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 88b144e858f8895f1d84c518642ce34ce0f5aa07 GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 @@ -157,6 +160,6 @@ SPEC CHECKSUMS: SDCycleScrollView: a0d74c3384caa72bdfc81470bdbc8c14b3e1fbcf SDWebImage: 2aea163b50bfcb569a2726b6a754c54a4506fcf6 -PODFILE CHECKSUM: 35caa7945daf79d82b68a3ed0e3fe6f47130bac1 +PODFILE CHECKSUM: d18ae04aaea2c73be8383f04c6feea89caed3e99 COCOAPODS: 1.12.1 From f89b6cc6f11dad72b0197630d29fb27583bbd3bb Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 13 Jul 2023 16:56:30 +0800 Subject: [PATCH 031/126] fix: sonar quality bugs --- .../GrowingNode/Category/UIView+GrowingNode.m | 9 ------ .../GrowingNode/GrowingNodeHelper.m | 2 +- .../GrowingNode/GrowingViewNode.h | 30 ++++++++++--------- .../GrowingNode/GrowingViewNode.m | 6 ++-- .../Event/GrowingNodeProtocol.h | 6 ++-- .../Public/UIView+GrowingImpression.h | 2 +- .../UIView+GrowingImpressionInternal.m | 2 +- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index 60db21f1f..2ca33e50d 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -54,10 +54,6 @@ - (NSInteger)growingNodeKeyIndex { } - (NSString *)growingNodeSubPath { - // UITableViewWrapperView 为 iOS11 以下 UITableView 与 cell 之间的 view - if ([NSStringFromClass(self.class) isEqualToString:@"UITableViewWrapperView"]) { - return nil; - } // 如果手动标识了该view,返回标识 if (self.growingUniqueTag.length > 0) { return self.growingUniqueTag; @@ -67,11 +63,6 @@ - (NSString *)growingNodeSubPath { } - (NSString *)growingNodeSubIndex { - // UITableViewWrapperView 为 iOS11 以下 UITableView 与 cell 之间的 view - if ([NSStringFromClass(self.class) isEqualToString:@"UITableViewWrapperView"]) { - return nil; - } - NSInteger index = [self growingNodeKeyIndex]; return index < 0 ? @"0" : [NSString stringWithFormat:@"%ld", (long)index]; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 46ede4ead..5d6eecd31 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -36,7 +36,7 @@ + (void)recalculateXpath:(UIView *)view NSMutableArray *originxindexArray = [NSMutableArray array]; BOOL isSimilar = YES; while (node && [node isKindOfClass:[UIView class]]) { - if (node.growingNodeSubPath == nil || [self isIgnoredPrivateView:node]) { + if ([self isIgnoredPrivateView:node]) { node = node.growingNodeParent; continue; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h index 1553b6e70..8301851ad 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h @@ -22,18 +22,20 @@ #import "GrowingTrackerCore/Event/GrowingNodeProtocol.h" NS_ASSUME_NONNULL_BEGIN + @class GrowingViewNodeBuilder; + @interface GrowingViewNode : NSObject -@property (nonatomic, weak, readonly) UIView *_Nullable view; +@property (nonatomic, weak, readonly) UIView *view; @property (nonatomic, copy, readonly) NSString *_Nullable viewContent; -@property (nonatomic, copy, readonly) NSString *_Nonnull xpath; -@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; +@property (nonatomic, copy, readonly) NSString *xpath; +@property (nonatomic, copy, readonly) NSString *xindex; // 原始的位置组 -@property (nonatomic, copy, readonly) NSString *_Nonnull originxindex; +@property (nonatomic, copy, readonly) NSString *originxindex; // 可点击的父节点xpath -@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXpath; -@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXindex; +@property (nonatomic, copy, readonly) NSString *clickableParentXpath; +@property (nonatomic, copy, readonly) NSString *clickableParentXindex; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; @@ -43,8 +45,8 @@ NS_ASSUME_NONNULL_BEGIN // 当圈选时,从上至下的路径不一定和正常事件(从下至上)的路径一致,我们需要从新计算xpath @property (nonatomic, assign, readonly) BOOL needRecalculate; -- (instancetype _Nonnull)init NS_UNAVAILABLE; -+ (instancetype _Nonnull)new NS_UNAVAILABLE; +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)new NS_UNAVAILABLE; - (instancetype)initWithBuilder:(GrowingViewNodeBuilder *)builder; + (GrowingViewNodeBuilder *)builder; @@ -56,15 +58,15 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingViewNodeBuilder : NSObject -@property (nonatomic, strong, readonly) UIView *_Nullable view; +@property (nonatomic, strong, readonly) UIView *view; @property (nonatomic, copy, readonly) NSString *_Nullable viewContent; -@property (nonatomic, copy, readonly) NSString *_Nonnull xpath; -@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; +@property (nonatomic, copy, readonly) NSString *xpath; +@property (nonatomic, copy, readonly) NSString *xindex; // 原始的位置组 -@property (nonatomic, copy, readonly) NSString *_Nonnull originxindex; +@property (nonatomic, copy, readonly) NSString *originxindex; // 可点击的父节点xpath -@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXpath; -@property (nonatomic, copy, readonly) NSString *_Nonnull clickableParentXindex; +@property (nonatomic, copy, readonly) NSString *clickableParentXpath; +@property (nonatomic, copy, readonly) NSString *clickableParentXindex; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m index 43efaad8b..c6dfa7f1a 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m @@ -27,9 +27,9 @@ @interface GrowingViewNode () -@property (nonatomic, copy, readwrite) NSString *_Nonnull xpath; -@property (nonatomic, copy, readwrite) NSString *_Nonnull xindex; -@property (nonatomic, copy, readwrite) NSString *_Nonnull originxindex; +@property (nonatomic, copy, readwrite) NSString *xpath; +@property (nonatomic, copy, readwrite) NSString *xindex; +@property (nonatomic, copy, readwrite) NSString *originxindex; @end diff --git a/GrowingTrackerCore/Event/GrowingNodeProtocol.h b/GrowingTrackerCore/Event/GrowingNodeProtocol.h index 9af29a693..b77527d67 100644 --- a/GrowingTrackerCore/Event/GrowingNodeProtocol.h +++ b/GrowingTrackerCore/Event/GrowingNodeProtocol.h @@ -26,12 +26,12 @@ /// UILabel[0] UILabel[1] @property (nonatomic, assign, readonly) NSInteger growingNodeKeyIndex; /// 完整的xpath由各个node的subPath拼接而成 -@property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubPath; +@property (nonatomic, copy, readonly) NSString *growingNodeSubPath; /// 完整的xindex由各个node的subIndex拼接而成 -@property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubIndex; +@property (nonatomic, copy, readonly) NSString *growingNodeSubIndex; /// 当同一视图下相同class的两个node点击行为相似 /// 当不需要区分点击哪一个node,仅需要区分点击那种类型时,使用该属性 -@property (nonatomic, copy, readonly) NSString *_Nullable growingNodeSubSimilarIndex; +@property (nonatomic, copy, readonly) NSString *growingNodeSubSimilarIndex; /// 原始父节点 - (id _Nullable)growingNodeParent; /// 不进行track diff --git a/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h b/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h index 928c84e01..b41b945af 100644 --- a/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h +++ b/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h @@ -38,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN @param eventName 自定义事件名称 @param attributes 自定义属性 */ -- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *)attributes; +- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *_Nullable)attributes; // 停止该元素展示追踪 // 通常应用于列表中的重用元素 diff --git a/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m index 804cd5c67..daf7412b8 100644 --- a/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m +++ b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m @@ -111,7 +111,7 @@ - (void)growingTrackImpression:(NSString *)eventName { [self growingTrackImpression:eventName attributes:nil]; } -- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *)attributes { +- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *_Nullable)attributes { if (eventName.length == 0) { return; } From 17c10ac0752cf2717324d665c2bce75b74beef75 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 13 Jul 2023 08:57:26 +0000 Subject: [PATCH 032/126] style: code format --- Modules/ImpressionTrack/Public/UIView+GrowingImpression.h | 3 ++- Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h b/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h index b41b945af..8cf75c741 100644 --- a/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h +++ b/Modules/ImpressionTrack/Public/UIView+GrowingImpression.h @@ -38,7 +38,8 @@ NS_ASSUME_NONNULL_BEGIN @param eventName 自定义事件名称 @param attributes 自定义属性 */ -- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *_Nullable)attributes; +- (void)growingTrackImpression:(NSString *)eventName + attributes:(NSDictionary *_Nullable)attributes; // 停止该元素展示追踪 // 通常应用于列表中的重用元素 diff --git a/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m index daf7412b8..ddb23f687 100644 --- a/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m +++ b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m @@ -111,7 +111,8 @@ - (void)growingTrackImpression:(NSString *)eventName { [self growingTrackImpression:eventName attributes:nil]; } -- (void)growingTrackImpression:(NSString *)eventName attributes:(NSDictionary *_Nullable)attributes { +- (void)growingTrackImpression:(NSString *)eventName + attributes:(NSDictionary *_Nullable)attributes { if (eventName.length == 0) { return; } From 101770cdb11526f4cc28bdaf09944727393cd765 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 13 Jul 2023 19:22:53 +0800 Subject: [PATCH 033/126] fix: sonar quality bugs --- .../Core/GrowingModuleManager.m | 4 +- .../Core/GrowingServiceManager.m | 6 +- .../Event/GrowingEventChannel.h | 2 +- .../Event/GrowingEventChannel.m | 13 +-- .../Event/GrowingNodeProtocol.h | 4 + .../Tools/GrowingPersistenceDataProvider.m | 2 +- .../Helpers/Foundation/NSURL+GrowingHelper.m | 2 +- GrowingTrackerCore/Public/GrowingBaseEvent.h | 87 ++++++++++--------- .../Public/GrowingServiceManager.h | 2 +- .../Thirdparty/Logger/GrowingWSLogger.m | 2 - .../UIView+GrowingImpressionInternal.m | 5 +- Services/Database/FMDB/GrowingFMResultSet.m | 2 +- 12 files changed, 63 insertions(+), 68 deletions(-) diff --git a/GrowingTrackerCore/Core/GrowingModuleManager.m b/GrowingTrackerCore/Core/GrowingModuleManager.m index 73000d360..7e4320053 100644 --- a/GrowingTrackerCore/Core/GrowingModuleManager.m +++ b/GrowingTrackerCore/Core/GrowingModuleManager.m @@ -136,7 +136,7 @@ - (void)handleModuleEvent:(NSInteger)eventType withCustomParam:(NSDictionary *)c - (void)handleModulesInitEvent:(NSDictionary *)customParam { GrowingContext *context = [GrowingContext sharedInstance].copy; context.customEvent = GrowingMInitEvent; - context.customParam = customParam; + context.customParam = customParam ?: @{}; NSArray *moduleInstances = [self.modulesByEvent objectForKey:@(GrowingMInitEvent)]; for (id module in moduleInstances) { @@ -159,7 +159,7 @@ - (void)handleModuleEvent:(NSInteger)eventType customParam:(NSDictionary *)custo GrowingContext *context = [GrowingContext sharedInstance].copy; context.customEvent = eventType; - context.customParam = customParam; + context.customParam = customParam ?: @{}; NSArray *moduleInstances = [self.modulesByEvent objectForKey:@(eventType)]; for (id module in moduleInstances) { diff --git a/GrowingTrackerCore/Core/GrowingServiceManager.m b/GrowingTrackerCore/Core/GrowingServiceManager.m index 31c9728a4..222d8c0d1 100644 --- a/GrowingTrackerCore/Core/GrowingServiceManager.m +++ b/GrowingTrackerCore/Core/GrowingServiceManager.m @@ -25,8 +25,8 @@ @interface GrowingServiceManager () -@property (nonatomic, copy) NSMutableDictionary *allServiceDict; -@property (nonatomic, copy) NSMutableDictionary *allServiceInstanceDict; +@property (nonatomic, strong) NSMutableDictionary *allServiceDict; +@property (nonatomic, strong) NSMutableDictionary *allServiceInstanceDict; @end @@ -77,7 +77,7 @@ - (void)registerService:(Protocol *)service implClass:(Class)serviceClass { [self.allServiceDict setValue:NSStringFromClass(serviceClass) forKey:NSStringFromProtocol(service)]; } -- (id)createService:(Protocol *)service { +- (nullable id)createService:(Protocol *)service { NSString *serviceString = NSStringFromProtocol(service); id instance = [self.allServiceInstanceDict objectForKey:serviceString]; if (instance) { diff --git a/GrowingTrackerCore/Event/GrowingEventChannel.h b/GrowingTrackerCore/Event/GrowingEventChannel.h index 317f197e8..319d40aa8 100644 --- a/GrowingTrackerCore/Event/GrowingEventChannel.h +++ b/GrowingTrackerCore/Event/GrowingEventChannel.h @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN /// 根据channels数组,返回 eventType 为key,channel对象为object的字典 + (NSDictionary *)eventChannelMapFromAllChannels:(NSArray *)channels; -+ (GrowingEventChannel *)otherEventChannelFromAllChannels:(NSArray *)allEventChannels; ++ (GrowingEventChannel *)otherEventChannelFromAllChannels:(NSArray *)channels; @end diff --git a/GrowingTrackerCore/Event/GrowingEventChannel.m b/GrowingTrackerCore/Event/GrowingEventChannel.m index f7b1c6b67..35c234428 100644 --- a/GrowingTrackerCore/Event/GrowingEventChannel.m +++ b/GrowingTrackerCore/Event/GrowingEventChannel.m @@ -79,11 +79,6 @@ + (instancetype)eventChannelWithEventTypes:(NSArray *)eventTypes } + (NSDictionary *)eventChannelMapFromAllChannels:(NSArray *)channels { - NSArray *allEventChannels = channels; - if (!allEventChannels.count) { - allEventChannels = [self buildAllEventChannels]; - } - // TODO: 添加page以及pageAttributes类型 NSMutableDictionary *dictM = [NSMutableDictionary dictionary]; for (GrowingEventChannel *obj in channels) { for (NSString *key in obj.eventTypes) { @@ -93,12 +88,8 @@ + (NSDictionary *)eventChannelMapFromAllChannels:(NSArray return dictM; } -+ (GrowingEventChannel *)otherEventChannelFromAllChannels:(NSArray *)allEventChannels { - if (!allEventChannels.count) { - return [self buildAllEventChannels].lastObject; - } - - return allEventChannels.lastObject; ++ (GrowingEventChannel *)otherEventChannelFromAllChannels:(NSArray *)channels { + return channels.lastObject; } @end diff --git a/GrowingTrackerCore/Event/GrowingNodeProtocol.h b/GrowingTrackerCore/Event/GrowingNodeProtocol.h index b77527d67..a5917d70c 100644 --- a/GrowingTrackerCore/Event/GrowingNodeProtocol.h +++ b/GrowingTrackerCore/Event/GrowingNodeProtocol.h @@ -19,6 +19,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + @protocol GrowingNode @required @@ -50,3 +52,5 @@ - (NSArray> *_Nullable)growingNodeChilds; @end + +NS_ASSUME_NONNULL_END diff --git a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m index 63daa633b..ea7f99a6d 100644 --- a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m +++ b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m @@ -108,7 +108,7 @@ - (GrowingEventSequenceObject *)getAndIncrement:(NSString *)eventType { - (long long)increaseFor:(NSString *)key spanValue:(int)span { NSNumber *value = [_growingUserdefault valueForKey:key]; - if (!value) { + if (value == nil) { value = [NSNumber numberWithLongLong:0]; } diff --git a/GrowingTrackerCore/Helpers/Foundation/NSURL+GrowingHelper.m b/GrowingTrackerCore/Helpers/Foundation/NSURL+GrowingHelper.m index 6476e4550..f23422deb 100644 --- a/GrowingTrackerCore/Helpers/Foundation/NSURL+GrowingHelper.m +++ b/GrowingTrackerCore/Helpers/Foundation/NSURL+GrowingHelper.m @@ -29,7 +29,7 @@ - (NSDictionary *)growingHelper_queryDict { NSArray *kv = [pair componentsSeparatedByString:@"="]; if (kv.count == 2) { NSString *key = [kv objectAtIndex:0]; - NSString *val = [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *val = [[kv objectAtIndex:1] stringByRemovingPercentEncoding]; if (val) { [params setObject:val forKey:key]; } diff --git a/GrowingTrackerCore/Public/GrowingBaseEvent.h b/GrowingTrackerCore/Public/GrowingBaseEvent.h index 89d440a33..40f39d356 100644 --- a/GrowingTrackerCore/Public/GrowingBaseEvent.h +++ b/GrowingTrackerCore/Public/GrowingBaseEvent.h @@ -19,6 +19,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + @class GrowingBaseBuilder; typedef NS_ENUM(NSUInteger, GrowingAppState) { GrowingAppStateForeground, GrowingAppStateBackground }; @@ -31,33 +33,33 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) { @interface GrowingBaseEvent : NSObject -@property (nonatomic, copy, readonly) NSString *_Nullable dataSourceId; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceId; -@property (nonatomic, copy, readonly) NSString *_Nullable userId; -@property (nonatomic, copy, readonly) NSString *_Nullable sessionId; -@property (nonatomic, copy, readonly) NSString *_Nonnull eventType; +@property (nonatomic, copy, readonly, nullable) NSString *dataSourceId; +@property (nonatomic, copy, readonly) NSString *deviceId; +@property (nonatomic, copy, readonly, nullable) NSString *userId; +@property (nonatomic, copy, readonly, nullable) NSString *sessionId; +@property (nonatomic, copy, readonly) NSString *eventType; @property (nonatomic, assign, readonly) long long timestamp; -@property (nonatomic, copy, readonly) NSString *_Nonnull domain; -@property (nonatomic, copy, readonly) NSString *_Nonnull urlScheme; +@property (nonatomic, copy, readonly) NSString *domain; +@property (nonatomic, copy, readonly) NSString *urlScheme; @property (nonatomic, assign, readonly) int appState; @property (nonatomic, assign, readonly) long long eventSequenceId; -@property (nonatomic, copy, readonly) NSString *_Nonnull platform; -@property (nonatomic, copy, readonly) NSString *_Nonnull platformVersion; -@property (nonatomic, strong, readonly) NSDictionary *_Nonnull extraParams; -@property (nonatomic, copy, readonly) NSString *_Nullable networkState; -@property (nonatomic, copy, readonly) NSString *_Nullable appChannel; +@property (nonatomic, copy, readonly) NSString *platform; +@property (nonatomic, copy, readonly) NSString *platformVersion; +@property (nonatomic, strong, readonly) NSDictionary *extraParams; +@property (nonatomic, copy, readonly, nullable) NSString *networkState; +@property (nonatomic, copy, readonly, nullable) NSString *appChannel; @property (nonatomic, assign, readonly) NSInteger screenHeight; @property (nonatomic, assign, readonly) NSInteger screenWidth; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceBrand; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceModel; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceType; -@property (nonatomic, copy, readonly) NSString *_Nonnull appName; -@property (nonatomic, copy, readonly) NSString *_Nonnull appVersion; -@property (nonatomic, copy, readonly) NSString *_Nonnull language; +@property (nonatomic, copy, readonly, nullable) NSString *deviceBrand; +@property (nonatomic, copy, readonly, nullable) NSString *deviceModel; +@property (nonatomic, copy, readonly, nullable) NSString *deviceType; +@property (nonatomic, copy, readonly) NSString *appName; +@property (nonatomic, copy, readonly) NSString *appVersion; +@property (nonatomic, copy, readonly) NSString *language; @property (nonatomic, assign, readonly) double latitude; @property (nonatomic, assign, readonly) double longitude; -@property (nonatomic, copy, readonly) NSString *_Nonnull sdkVersion; -@property (nonatomic, copy, readonly) NSString *_Nullable userKey; +@property (nonatomic, copy, readonly) NSString *sdkVersion; +@property (nonatomic, copy, readonly, nullable) NSString *userKey; @property (nonatomic, assign) GrowingEventSendPolicy sendPolicy; - (NSDictionary *_Nonnull)toDictionary; @@ -73,35 +75,33 @@ typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) { /// builder @interface GrowingBaseBuilder : NSObject -@property (nonatomic, copy, readonly) NSString *_Nullable dataSourceId; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceId; -@property (nonatomic, copy, readonly) NSString *_Nullable userId; -@property (nonatomic, copy, readonly) NSString *_Nullable sessionId; -@property (nonatomic, copy, readonly) NSString *_Nonnull eventType; +@property (nonatomic, copy, readonly, nullable) NSString *dataSourceId; +@property (nonatomic, copy, readonly) NSString *deviceId; +@property (nonatomic, copy, readonly, nullable) NSString *userId; +@property (nonatomic, copy, readonly, nullable) NSString *sessionId; +@property (nonatomic, copy, readonly) NSString *eventType; @property (nonatomic, assign, readonly) long long timestamp; -@property (nonatomic, copy, readonly) NSString *_Nonnull domain; -@property (nonatomic, copy, readonly) NSString *_Nonnull urlScheme; +@property (nonatomic, copy, readonly) NSString *domain; +@property (nonatomic, copy, readonly) NSString *urlScheme; @property (nonatomic, assign, readonly) int appState; @property (nonatomic, assign, readonly) long long eventSequenceId; -@property (nonatomic, copy, readonly) NSString *_Nonnull platform; -@property (nonatomic, copy, readonly) NSString *_Nonnull platformVersion; -@property (nonatomic, strong, readonly) NSDictionary *_Nonnull extraParams; -@property (nonatomic, copy, readonly) NSString *_Nullable networkState; -@property (nonatomic, copy, readonly) NSString *_Nullable appChannel; +@property (nonatomic, copy, readonly) NSString *platform; +@property (nonatomic, copy, readonly) NSString *platformVersion; +@property (nonatomic, strong, readonly) NSDictionary *extraParams; +@property (nonatomic, copy, readonly, nullable) NSString *networkState; +@property (nonatomic, copy, readonly, nullable) NSString *appChannel; @property (nonatomic, assign, readonly) NSInteger screenHeight; @property (nonatomic, assign, readonly) NSInteger screenWidth; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceBrand; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceModel; -@property (nonatomic, copy, readonly) NSString *_Nonnull deviceType; -@property (nonatomic, copy, readonly) NSString *_Nonnull appName; -@property (nonatomic, copy, readonly) NSString *_Nonnull appVersion; -@property (nonatomic, copy, readonly) NSString *_Nonnull language; +@property (nonatomic, copy, readonly, nullable) NSString *deviceBrand; +@property (nonatomic, copy, readonly, nullable) NSString *deviceModel; +@property (nonatomic, copy, readonly, nullable) NSString *deviceType; +@property (nonatomic, copy, readonly) NSString *appName; +@property (nonatomic, copy, readonly) NSString *appVersion; +@property (nonatomic, copy, readonly) NSString *language; @property (nonatomic, assign, readonly) double latitude; @property (nonatomic, assign, readonly) double longitude; -@property (nonatomic, copy, readonly) NSString *_Nonnull sdkVersion; -@property (nonatomic, copy, readonly) NSString *_Nullable userKey; - -NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, copy, readonly) NSString *sdkVersion; +@property (nonatomic, copy, readonly, nullable) NSString *userKey; // 赋值属性,eg:deviceId,userId,sessionId,eventSequenceId - (void)readPropertyInTrackThread; @@ -134,5 +134,6 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingBaseBuilder * (^)(NSString *value))setEventType; - (GrowingBaseEvent *)build; -NS_ASSUME_NONNULL_END @end + +NS_ASSUME_NONNULL_END diff --git a/GrowingTrackerCore/Public/GrowingServiceManager.h b/GrowingTrackerCore/Public/GrowingServiceManager.h index 4b67190a2..f61fc424f 100644 --- a/GrowingTrackerCore/Public/GrowingServiceManager.h +++ b/GrowingTrackerCore/Public/GrowingServiceManager.h @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)registerService:(Protocol *)service implClass:(Class)serviceClass; -- (id)createService:(Protocol *)service; +- (nullable id)createService:(Protocol *)service; - (id)serviceImplClass:(Protocol *)service; diff --git a/GrowingTrackerCore/Thirdparty/Logger/GrowingWSLogger.m b/GrowingTrackerCore/Thirdparty/Logger/GrowingWSLogger.m index edd5efe23..4bc3e550f 100644 --- a/GrowingTrackerCore/Thirdparty/Logger/GrowingWSLogger.m +++ b/GrowingTrackerCore/Thirdparty/Logger/GrowingWSLogger.m @@ -49,10 +49,8 @@ - (GrowingLoggerName)loggerName { - (void)logMessage:(GrowingLogMessage *)logMessage { NSString *logMsg = logMessage->_message; - BOOL isFormatted = NO; if (_logFormatter) { logMsg = [_logFormatter formatLogMessage:logMessage]; - isFormatted = logMsg != logMessage->_message; } if (logMsg) { diff --git a/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m index ddb23f687..817abb703 100644 --- a/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m +++ b/Modules/ImpressionTrack/UIView+GrowingImpressionInternal.m @@ -118,8 +118,9 @@ - (void)growingTrackImpression:(NSString *)eventName } if (self.growingIMPTrackEventName && [eventName isEqualToString:self.growingIMPTrackEventName]) { - if ((attributes && [attributes isEqualToDictionary:self.growingIMPTrackVariable]) || - attributes == self.growingIMPTrackVariable) { + if ((attributes && self.growingIMPTrackVariable && + [attributes isEqualToDictionary:self.growingIMPTrackVariable]) || + (attributes == nil && self.growingIMPTrackVariable == nil)) { return; } } diff --git a/Services/Database/FMDB/GrowingFMResultSet.m b/Services/Database/FMDB/GrowingFMResultSet.m index 107612e23..498b29eb9 100755 --- a/Services/Database/FMDB/GrowingFMResultSet.m +++ b/Services/Database/FMDB/GrowingFMResultSet.m @@ -251,7 +251,7 @@ - (int)columnIndexForName:(NSString*)columnName { NSNumber *n = [[self columnNameToIndexMap] objectForKey:columnName]; - if (n) { + if (n != nil) { return [n intValue]; } From 923c771604ceab58f85107cfec1b99a7337f293c Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 14 Jul 2023 11:25:22 +0800 Subject: [PATCH 034/126] docs: update Readme, use .spi.yml --- .spi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.spi.yml b/.spi.yml index 2fcd019af..0f982bac8 100644 --- a/.spi.yml +++ b/.spi.yml @@ -6,4 +6,4 @@ builder: - platform: macos-xcodebuild scheme: GrowingTracker - platform: macos-spm - target: GrowingTracker \ No newline at end of file + target: GrowingTracker From 1cec5786ce4c3d906c4f29638c0948cb3fb1c55b Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 14 Jul 2023 14:38:11 +0800 Subject: [PATCH 035/126] test: update ci --- Example/Example.xcodeproj/project.pbxproj | 52 ++++++ .../Storyboard/UICatalogTests.storyboard | 165 +++++++++++++++++- .../GIOActionSheetViewController.m | 36 +--- .../GrowingIgnoreViewClsViewController.h | 28 +++ .../GrowingIgnoreViewClsViewController.m | 40 +++++ .../GrowingIgnoreViewViewController.h | 35 ++++ .../GrowingIgnoreViewViewController.m | 58 ++++++ .../View/GrowingIgnoreButton1.h | 28 +++ .../View/GrowingIgnoreButton1.m | 32 ++++ .../View/GrowingIgnoreButton2.h | 28 +++ .../View/GrowingIgnoreButton2.m | 32 ++++ .../View/GrowingIgnoreButton3.h | 28 +++ .../View/GrowingIgnoreButton3.m | 32 ++++ .../View/GrowingNotIgnoreButton4.h | 28 +++ .../View/GrowingNotIgnoreButton4.m | 32 ++++ .../Event/A1ViewClickEventsTest.m | 58 ++++++ 16 files changed, 678 insertions(+), 34 deletions(-) create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.h create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.m create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.h create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.m create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.h create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.m create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.h create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.m create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.h create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.m create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.h create mode 100644 Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 0e7cce2fd..f3919ec38 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -87,6 +87,12 @@ 347B8F432A0A46DD00B8A114 /* ScreenshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 347B8F422A0A46DD00B8A114 /* ScreenshotTest.m */; }; 34821C6727B247DB006C8B8E /* UISegmentedControlAutotrackTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34821C6627B247DB006C8B8E /* UISegmentedControlAutotrackTest.m */; }; 34821C6C27B25AE7006C8B8E /* HybridTest_HostApp.m in Sources */ = {isa = PBXBuildFile; fileRef = 34821C6B27B25AE7006C8B8E /* HybridTest_HostApp.m */; }; + 348C86A52A60FC1100310C22 /* GrowingIgnoreViewClsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 348C86A42A60FC1100310C22 /* GrowingIgnoreViewClsViewController.m */; }; + 348C86A92A60FC7900310C22 /* GrowingIgnoreButton1.m in Sources */ = {isa = PBXBuildFile; fileRef = 348C86A82A60FC7900310C22 /* GrowingIgnoreButton1.m */; }; + 348C86AC2A60FC8300310C22 /* GrowingIgnoreButton2.m in Sources */ = {isa = PBXBuildFile; fileRef = 348C86AB2A60FC8300310C22 /* GrowingIgnoreButton2.m */; }; + 348C86AF2A60FC9000310C22 /* GrowingIgnoreButton3.m in Sources */ = {isa = PBXBuildFile; fileRef = 348C86AE2A60FC9000310C22 /* GrowingIgnoreButton3.m */; }; + 348C86B22A60FCA200310C22 /* GrowingNotIgnoreButton4.m in Sources */ = {isa = PBXBuildFile; fileRef = 348C86B12A60FCA200310C22 /* GrowingNotIgnoreButton4.m */; }; + 348C86B52A60FCE400310C22 /* GrowingIgnoreViewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 348C86B42A60FCE400310C22 /* GrowingIgnoreViewViewController.m */; }; 3494DD0328597E2E00A6CE46 /* DeepLinkTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34BA7B41277D8EC30030AC21 /* DeepLinkTest.m */; }; 3494DD092859CCF300A6CE46 /* GrowingDeepLinkHandler+XCTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3494DD072859CCF300A6CE46 /* GrowingDeepLinkHandler+XCTest.m */; }; 3494DD122859E07500A6CE46 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3494DD112859E07500A6CE46 /* AppDelegate.m */; }; @@ -306,6 +312,18 @@ 347B8F422A0A46DD00B8A114 /* ScreenshotTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScreenshotTest.m; sourceTree = ""; }; 34821C6627B247DB006C8B8E /* UISegmentedControlAutotrackTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UISegmentedControlAutotrackTest.m; sourceTree = ""; }; 34821C6B27B25AE7006C8B8E /* HybridTest_HostApp.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HybridTest_HostApp.m; sourceTree = ""; }; + 348C86A32A60FC1100310C22 /* GrowingIgnoreViewClsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingIgnoreViewClsViewController.h; sourceTree = ""; }; + 348C86A42A60FC1100310C22 /* GrowingIgnoreViewClsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingIgnoreViewClsViewController.m; sourceTree = ""; }; + 348C86A72A60FC7900310C22 /* GrowingIgnoreButton1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingIgnoreButton1.h; sourceTree = ""; }; + 348C86A82A60FC7900310C22 /* GrowingIgnoreButton1.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingIgnoreButton1.m; sourceTree = ""; }; + 348C86AA2A60FC8300310C22 /* GrowingIgnoreButton2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingIgnoreButton2.h; sourceTree = ""; }; + 348C86AB2A60FC8300310C22 /* GrowingIgnoreButton2.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingIgnoreButton2.m; sourceTree = ""; }; + 348C86AD2A60FC9000310C22 /* GrowingIgnoreButton3.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingIgnoreButton3.h; sourceTree = ""; }; + 348C86AE2A60FC9000310C22 /* GrowingIgnoreButton3.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingIgnoreButton3.m; sourceTree = ""; }; + 348C86B02A60FCA200310C22 /* GrowingNotIgnoreButton4.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingNotIgnoreButton4.h; sourceTree = ""; }; + 348C86B12A60FCA200310C22 /* GrowingNotIgnoreButton4.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingNotIgnoreButton4.m; sourceTree = ""; }; + 348C86B32A60FCE400310C22 /* GrowingIgnoreViewViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingIgnoreViewViewController.h; sourceTree = ""; }; + 348C86B42A60FCE400310C22 /* GrowingIgnoreViewViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingIgnoreViewViewController.m; sourceTree = ""; }; 3494DCF828597E1A00A6CE46 /* GrowingAnalyticsUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GrowingAnalyticsUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 3494DD072859CCF300A6CE46 /* GrowingDeepLinkHandler+XCTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GrowingDeepLinkHandler+XCTest.m"; sourceTree = ""; }; 3494DD082859CCF300A6CE46 /* GrowingDeepLinkHandler+XCTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GrowingDeepLinkHandler+XCTest.h"; sourceTree = ""; }; @@ -591,6 +609,7 @@ 34BDC35127707BA40030B3CE /* SimpleUIElements */, 34BDC35227707BB20030B3CE /* AttributeLabel */, 34BDC35327707BBE0030B3CE /* CollectionView */, + 348C86A22A60FBEC00310C22 /* IgnoreViewClass */, 34BDC35427707BC80030B3CE /* Banner&TableView */, 0465310F24DD4271002D254C /* PageStructure */, 34BDC35527707BD00030B3CE /* ActionSheets */, @@ -797,6 +816,33 @@ path = HybridTests; sourceTree = ""; }; + 348C86A22A60FBEC00310C22 /* IgnoreViewClass */ = { + isa = PBXGroup; + children = ( + 348C86A62A60FC6100310C22 /* View */, + 348C86A32A60FC1100310C22 /* GrowingIgnoreViewClsViewController.h */, + 348C86A42A60FC1100310C22 /* GrowingIgnoreViewClsViewController.m */, + 348C86B32A60FCE400310C22 /* GrowingIgnoreViewViewController.h */, + 348C86B42A60FCE400310C22 /* GrowingIgnoreViewViewController.m */, + ); + path = IgnoreViewClass; + sourceTree = ""; + }; + 348C86A62A60FC6100310C22 /* View */ = { + isa = PBXGroup; + children = ( + 348C86A72A60FC7900310C22 /* GrowingIgnoreButton1.h */, + 348C86A82A60FC7900310C22 /* GrowingIgnoreButton1.m */, + 348C86AA2A60FC8300310C22 /* GrowingIgnoreButton2.h */, + 348C86AB2A60FC8300310C22 /* GrowingIgnoreButton2.m */, + 348C86AD2A60FC9000310C22 /* GrowingIgnoreButton3.h */, + 348C86AE2A60FC9000310C22 /* GrowingIgnoreButton3.m */, + 348C86B02A60FCA200310C22 /* GrowingNotIgnoreButton4.h */, + 348C86B12A60FCA200310C22 /* GrowingNotIgnoreButton4.m */, + ); + path = View; + sourceTree = ""; + }; 3494DCF928597E1A00A6CE46 /* GrowingAnalyticsUITests */ = { isa = PBXGroup; children = ( @@ -2214,9 +2260,12 @@ buildActionMask = 2147483647; files = ( 04A6FAF224E662E9006C72F0 /* GIOChildsAddViewController.m in Sources */, + 348C86AF2A60FC9000310C22 /* GrowingIgnoreButton3.m in Sources */, 349F1492285B560200437F53 /* UIColor+Hex.m in Sources */, + 348C86A52A60FC1100310C22 /* GrowingIgnoreViewClsViewController.m in Sources */, 349F1489285B503B00437F53 /* GIOH5BrowserViewController.m in Sources */, 0465314424DD4272002D254C /* GIOMeasurementProtocolTableViewController.m in Sources */, + 348C86B52A60FCE400310C22 /* GrowingIgnoreViewViewController.m in Sources */, 0465314024DD4272002D254C /* GIOKeyValueCell.m in Sources */, 34ECFDBF2A5C082A0059F87C /* GrowingAutotrackPageViewController.m in Sources */, 0465314D24DD4272002D254C /* AppDelegate.m in Sources */, @@ -2239,6 +2288,9 @@ 0465315B24DD4272002D254C /* GIOCollectionViewCell.m in Sources */, 0465314F24DD4272002D254C /* GIOTextFieldViewController.m in Sources */, 4916271224E157CF00444AF2 /* GIOPagingViewController.m in Sources */, + 348C86A92A60FC7900310C22 /* GrowingIgnoreButton1.m in Sources */, + 348C86AC2A60FC8300310C22 /* GrowingIgnoreButton2.m in Sources */, + 348C86B22A60FCA200310C22 /* GrowingNotIgnoreButton4.m in Sources */, 0465313F24DD4272002D254C /* GIOInputChangeEventViewController.m in Sources */, 04A6FAF524E67215006C72F0 /* GIOBaseViewController.m in Sources */, 0465315A24DD4272002D254C /* GIOFoodTableViewCell.m in Sources */, diff --git a/Example/Example/Storyboard/UICatalogTests.storyboard b/Example/Example/Storyboard/UICatalogTests.storyboard index a569fcce2..33820acc6 100644 --- a/Example/Example/Storyboard/UICatalogTests.storyboard +++ b/Example/Example/Storyboard/UICatalogTests.storyboard @@ -1,9 +1,9 @@ - + - + @@ -119,12 +119,32 @@ + + + + + + + + + + + + + + - + @@ -144,7 +164,7 @@ - + @@ -161,7 +181,7 @@ - + @@ -181,7 +201,7 @@ - + @@ -201,7 +221,7 @@ - + @@ -420,6 +440,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1312,6 +1460,9 @@ + + + diff --git a/Example/Example/UICategoryTests/ActionSheets/GIOActionSheetViewController.m b/Example/Example/UICategoryTests/ActionSheets/GIOActionSheetViewController.m index 13227f52d..f1c957406 100644 --- a/Example/Example/UICategoryTests/ActionSheets/GIOActionSheetViewController.m +++ b/Example/Example/UICategoryTests/ActionSheets/GIOActionSheetViewController.m @@ -18,7 +18,7 @@ typedef NS_ENUM(NSInteger, GIOActionSheetsViewControllerTableRow) { GrwingAlertTwoTextMenuRow, }; -@interface GIOActionSheetViewController () +@interface GIOActionSheetViewController () @end @@ -40,14 +40,10 @@ - (void)showOkayCancelActionSheet { NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil); NSString *destructiveButtonTitle = NSLocalizedString(@"OK", nil); - UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil - delegate:self - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:nil]; - - actionSheet.actionSheetStyle = UIActionSheetStyleDefault; - - [actionSheet showInView:self.view]; + UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + [controller addAction:[UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:nil]]; + [controller addAction:[UIAlertAction actionWithTitle:destructiveButtonTitle style:UIAlertActionStyleDestructive handler:nil]]; + [self presentViewController:controller animated:YES completion:nil]; } // Show a dialog with two custom buttons. @@ -55,11 +51,10 @@ - (void)showOtherActionSheet { NSString *destructiveButtonTitle = NSLocalizedString(@"Destructive Choice", nil); NSString *otherButtonTitle = NSLocalizedString(@"Safe Choice", nil); - UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:otherButtonTitle, nil]; - - actionSheet.actionSheetStyle = UIActionSheetStyleDefault; - - [actionSheet showInView:self.view]; + UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + [controller addAction:[UIAlertAction actionWithTitle:destructiveButtonTitle style:UIAlertActionStyleDestructive handler:nil]]; + [controller addAction:[UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:nil]]; + [self presentViewController:controller animated:YES completion:nil]; } - (void)showGrowingAlertMenuOne { @@ -124,19 +119,6 @@ - (void)showGrowingAlertMenuTwoText { } -#pragma mark - UIActionSheetDelegate -- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { - if (actionSheet.destructiveButtonIndex == buttonIndex) { - NSLog(@"Action sheet clicked with the destructive button index."); - } - else if (actionSheet.cancelButtonIndex == buttonIndex) { - NSLog(@"Action sheet clicked with the cancel button index."); - } - else { - NSLog(@"Action sheet clicked with button at index %ld.", (long)buttonIndex); - } -} - #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { GIOActionSheetsViewControllerTableRow row = indexPath.row; diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.h b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.h new file mode 100644 index 000000000..14026408d --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.h @@ -0,0 +1,28 @@ +// +// GrowingIgnoreViewClsViewController.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingIgnoreViewClsViewController : UITableViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.m b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.m new file mode 100644 index 000000000..ffb393f30 --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewClsViewController.m @@ -0,0 +1,40 @@ +// +// GrowingIgnoreViewClsViewController.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingIgnoreViewClsViewController.h" +#import "GrowingIgnoreViewViewController.h" + +@interface GrowingIgnoreViewClsViewController () + +@end + +@implementation GrowingIgnoreViewClsViewController + +- (void)viewDidLoad { + [super viewDidLoad]; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + if ([segue.destinationViewController isKindOfClass:GrowingIgnoreViewViewController.class]) { + GrowingIgnoreViewViewController *vc = (GrowingIgnoreViewViewController *)segue.destinationViewController; + vc.type = segue.identifier.intValue; + } +} + +@end diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.h b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.h new file mode 100644 index 000000000..286e600ce --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.h @@ -0,0 +1,35 @@ +// +// GrowingIgnoreViewViewController.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, GrowingDemoIgnoreViewType) { + GrowingDemoIgnoreViewTypeSingle, + GrowingDemoIgnoreViewTypeMutiple, +}; + +@interface GrowingIgnoreViewViewController : UIViewController + +@property (nonatomic, assign) GrowingDemoIgnoreViewType type; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.m b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.m new file mode 100644 index 000000000..cbf1d42ef --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/GrowingIgnoreViewViewController.m @@ -0,0 +1,58 @@ +// +// GrowingIgnoreViewViewController.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingIgnoreViewViewController.h" +#import "GrowingIgnoreButton1.h" +#import "GrowingIgnoreButton2.h" +#import "GrowingIgnoreButton3.h" +#import "GrowingNotIgnoreButton4.h" + +@interface GrowingIgnoreViewViewController () + +@end + +@implementation GrowingIgnoreViewViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wundeclared-selector" + id autotracker = [GrowingAutotracker sharedInstance]; + if ([autotracker respondsToSelector:@selector(ignoreViewClasses)]) { + NSMutableSet *ignoreViewClasses = [autotracker performSelector:@selector(ignoreViewClasses)]; + [ignoreViewClasses removeAllObjects]; + } +#pragma clang diagnostic pop + +#if defined(AUTOTRACKER) +#if defined(SDK3rd) + if (self.type == GrowingDemoIgnoreViewTypeSingle) { + [[GrowingAutotracker sharedInstance] ignoreViewClass:GrowingIgnoreButton1.class]; + } else if (self.type == GrowingDemoIgnoreViewTypeMutiple) { + [[GrowingAutotracker sharedInstance] ignoreViewClasses:@[GrowingIgnoreButton1.class, GrowingIgnoreButton2.class, GrowingIgnoreButton3.class]]; + } +#endif +#endif +} + +- (IBAction)buttonAction:(id)sender { +} + +@end diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.h b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.h new file mode 100644 index 000000000..6b8bf1ca9 --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.h @@ -0,0 +1,28 @@ +// +// GrowingIgnoreButton1.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingIgnoreButton1 : UIButton + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.m b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.m new file mode 100644 index 000000000..79c5eafd7 --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton1.m @@ -0,0 +1,32 @@ +// +// GrowingIgnoreButton1.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingIgnoreButton1.h" + +@implementation GrowingIgnoreButton1 + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect { + // Drawing code +} +*/ + +@end diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.h b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.h new file mode 100644 index 000000000..3448ac5df --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.h @@ -0,0 +1,28 @@ +// +// GrowingIgnoreButton2.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingIgnoreButton2 : UIButton + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.m b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.m new file mode 100644 index 000000000..ebecf1991 --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton2.m @@ -0,0 +1,32 @@ +// +// GrowingIgnoreButton2.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingIgnoreButton2.h" + +@implementation GrowingIgnoreButton2 + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect { + // Drawing code +} +*/ + +@end diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.h b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.h new file mode 100644 index 000000000..1644cf3f8 --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.h @@ -0,0 +1,28 @@ +// +// GrowingIgnoreButton3.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingIgnoreButton3 : UIButton + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.m b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.m new file mode 100644 index 000000000..02a5b451f --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingIgnoreButton3.m @@ -0,0 +1,32 @@ +// +// GrowingIgnoreButton3.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingIgnoreButton3.h" + +@implementation GrowingIgnoreButton3 + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect { + // Drawing code +} +*/ + +@end diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.h b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.h new file mode 100644 index 000000000..e3218573c --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.h @@ -0,0 +1,28 @@ +// +// GrowingNotIgnoreButton4.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingNotIgnoreButton4 : UIButton + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.m b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.m new file mode 100644 index 000000000..94f69f58e --- /dev/null +++ b/Example/Example/UICategoryTests/IgnoreViewClass/View/GrowingNotIgnoreButton4.m @@ -0,0 +1,32 @@ +// +// GrowingNotIgnoreButton4.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/14. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GrowingNotIgnoreButton4.h" + +@implementation GrowingNotIgnoreButton4 + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect { + // Drawing code +} +*/ + +@end diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 6ceb1389a..60ba16194 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -216,4 +216,62 @@ - (void)test06ClickCustomContent { [[viewTester usingLabel:@"好的"] tap]; } +- (void)test07IgnoreViewClass { + [[viewTester usingLabel:@"IgnoreViewClass"] tap]; + [viewTester waitForAnimationsToFinish]; + + [[viewTester usingLabel:@"ignoreViewClass"] tap]; + [viewTester waitForAnimationsToFinish]; + + [MockEventQueue.sharedQueue cleanQueue]; + + [[viewTester usingLabel:@"IgnoreButton1"] tap]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertEqual(events.count, 0); + + [[viewTester usingLabel:@"IgnoreButton2"] tap]; + [[viewTester usingLabel:@"IgnoreButton3"] tap]; + [[viewTester usingLabel:@"NotIgnoreButton4"] tap]; + events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertEqual(events.count, 3); + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"textValue"], @"IgnoreButton2"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingIgnoreButton2"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0"); +} + +- (void)test08IgnoreViewClasses { + [[viewTester usingLabel:@"IgnoreViewClass"] tap]; + [viewTester waitForAnimationsToFinish]; + + [[viewTester usingLabel:@"ignoreViewClasses"] tap]; + [viewTester waitForAnimationsToFinish]; + + [MockEventQueue.sharedQueue cleanQueue]; + + [[viewTester usingLabel:@"IgnoreButton1"] tap]; + [[viewTester usingLabel:@"IgnoreButton2"] tap]; + [[viewTester usingLabel:@"IgnoreButton3"] tap]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertEqual(events.count, 0); + + [[viewTester usingLabel:@"NotIgnoreButton4"] tap]; + events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertEqual(events.count, 1); + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"textValue"], @"NotIgnoreButton4"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingNotIgnoreButton4"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0"); +} + @end From 006bb26b296a3cc786ef05e19baa50f68d025915 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 14 Jul 2023 14:50:58 +0800 Subject: [PATCH 036/126] build: delete ci about cdp --- .github/workflows/cocoapods.yml | 1 - scripts/cocoapods-beta.sh | 7 ++--- scripts/generate_xcframework.sh | 54 +------------------------------- scripts/modifyPodfileYAML.ruby | 21 ------------- scripts/modifyPodsXcodeproj.ruby | 1 - scripts/update_version.sh | 6 ++-- 6 files changed, 5 insertions(+), 85 deletions(-) delete mode 100644 scripts/modifyPodfileYAML.ruby diff --git a/.github/workflows/cocoapods.yml b/.github/workflows/cocoapods.yml index bef8c2d49..3bb2dfa0a 100644 --- a/.github/workflows/cocoapods.yml +++ b/.github/workflows/cocoapods.yml @@ -19,6 +19,5 @@ jobs: run: | set -eo pipefail pod trunk push GrowingAnalytics.podspec --verbose --allow-warnings --use-libraries - pod trunk push GrowingAnalytics-cdp.podspec --verbose --allow-warnings --use-libraries --synchronous env: COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} diff --git a/scripts/cocoapods-beta.sh b/scripts/cocoapods-beta.sh index d9e367421..db26bbfd7 100755 --- a/scripts/cocoapods-beta.sh +++ b/scripts/cocoapods-beta.sh @@ -2,10 +2,9 @@ set -x POD_BETA_VERSOIN=`cat GrowingAnalytics.podspec | grep 's.version\s*=' | grep -Eo '[0-9]+.[0-9]+.[0-9]+'-beta` -POD_BETA_VERSOIN_CDP=`cat GrowingAnalytics-cdp.podspec | grep 's.version\s*=' | grep -Eo '[0-9]+.[0-9]+.[0-9]+'-beta` BETA='beta' -if [[ $POD_BETA_VERSOIN == *$BETA* && $POD_BETA_VERSOIN_CDP == *$BETA* && $POD_BETA_VERSOIN == $POD_BETA_VERSOIN_CDP ]] +if [[ $POD_BETA_VERSOIN == *$BETA* ]] then echo "spec文件中,版本号包含beta,且配置正确,继续" else @@ -26,10 +25,8 @@ fi echo "删除trunk上的cocoapods库" echo y | pod trunk delete GrowingAnalytics $POD_BETA_VERSOIN -echo y | pod trunk delete GrowingAnalytics-cdp $POD_BETA_VERSOIN git tag $POD_BETA_VERSOIN git push --tags -pod trunk push GrowingAnalytics.podspec --allow-warnings --use-libraries -pod trunk push GrowingAnalytics-cdp.podspec --allow-warnings --use-libraries --synchronous +pod trunk push GrowingAnalytics.podspec --allow-warnings --use-libraries \ No newline at end of file diff --git a/scripts/generate_xcframework.sh b/scripts/generate_xcframework.sh index 52107c984..3d9ba93b1 100644 --- a/scripts/generate_xcframework.sh +++ b/scripts/generate_xcframework.sh @@ -13,30 +13,6 @@ logger() { fi } -IS_SAAS=false -chooseSaasOrCdp() { - PS3='Please choose SaaS or CDP:' - options=("SaaS" "CDP" "Quit") - select opt in "${options[@]}"; do - case $opt in - "SaaS") - IS_SAAS=true - break - ;; - "CDP") - break - ;; - "Quit") - exit 0 - break - ;; - *) - logger -e invalid option - ;; - esac - done -} - MAIN_BUNDLE="" chooseMainBundle() { PS3='Please choose which bundle you wanna build:' @@ -125,9 +101,6 @@ chooseModulesWith() { MAIN_FRAMEWORK_NAME='GrowingAnalytics' copyAndModifyPodspec() { logger -v "step: backup podspec" - if [ $IS_SAAS == false ]; then - MAIN_FRAMEWORK_NAME='GrowingAnalytics-cdp' - fi cp "${MAIN_FRAMEWORK_NAME}.podspec" "${MAIN_FRAMEWORK_NAME}-backup.podspec" modifyPodspec "${MAIN_FRAMEWORK_NAME}.podspec" } @@ -181,28 +154,7 @@ generateProject() { args+=" --verbose" fi - if [ $IS_SAAS == false ]; then - # 会出现找不到GrowingAnalytics对应版本的报错,处理方法在下面 - logger -i "tip: please ignore error message under, this script handled it perfectly" - bundle exec pod gen ${MAIN_FRAMEWORK_NAME}.podspec $args - logger -i "tip: please ignore error message above, this script handled it perfectly" - else - bundle exec pod gen ${MAIN_FRAMEWORK_NAME}.podspec $args || exit 1 - fi - - if [ $IS_SAAS == false ]; then - logger -v "step: modify CocoaPods.podfile.yaml" - # 这里用了比较绕的办法,让生成的GrowingAnalytics-cdp xcodeproj使用本地环境的GrowingAnalytics代码而不是Cocoapods Spec Repo上的对应的 - # 另外一种办法是使用[.gen_config.yml](https://github.com/square/cocoapods-generate#gen_configyml),添加external_source_pods: - # external_source_pods: - # - "GrowingAnalytics": - # - git: "https://github.com/growingio/growingio-sdk-ios-autotracker.git" - # 这样在生成xcodeproj时将使用git url对应最新的GrowingAnalytics.podspec,无需先执行pod repo push REPO_NAME PODSPEC_NAME更新podspec - ruby ./scripts/modifyPodfileYAML.ruby "${PROJECT_FOR_IOS_PATH}/${MAIN_FRAMEWORK_NAME}/CocoaPods.podfile.yaml" - pushd ${PROJECT_FOR_IOS_PATH}/${MAIN_FRAMEWORK_NAME} - bundle exec pod update --no-repo-update - popd - fi + bundle exec pod gen ${MAIN_FRAMEWORK_NAME}.podspec $args || exit 1 logger -v "step: modify build settings using CocoaPods/Xcodeproj" targets=$(ruby ./scripts/modifyPodsXcodeproj.ruby "./${PROJECT_FOR_IOS_PATH}/${MAIN_FRAMEWORK_NAME}/Pods/Pods.xcodeproj") @@ -211,9 +163,6 @@ generateProject() { if [ $target == "GrowingAnalytics" ]; then schemes+=("GrowingAnalytics") fi - if [ $target == "GrowingAnalytics-cdp" ]; then - schemes+=("GrowingAnalytics-cdp") - fi if [ $target == "GrowingUtils" ]; then schemes+=("GrowingUtils") fi @@ -327,7 +276,6 @@ beginGenerate() { } main() { - chooseSaasOrCdp chooseMainBundle chooseModules beginGenerate diff --git a/scripts/modifyPodfileYAML.ruby b/scripts/modifyPodfileYAML.ruby deleted file mode 100644 index 7c0d1ec13..000000000 --- a/scripts/modifyPodfileYAML.ruby +++ /dev/null @@ -1,21 +0,0 @@ -require 'yaml' - -file_path = ARGV[0] -data = YAML.load_file(file_path) - -new_dependency = { - 'GrowingAnalytics/TrackerCore' => [ - { - :path => '../../../../GrowingAnalytics.podspec' - } - ] -} - -data['target_definitions'].each do |target_def| - if target_def['name'] == 'Pods' - target_def['dependencies'] << new_dependency - break - end -end - -File.write(file_path, data.to_yaml) diff --git a/scripts/modifyPodsXcodeproj.ruby b/scripts/modifyPodsXcodeproj.ruby index e7f359b83..c17a9986e 100644 --- a/scripts/modifyPodsXcodeproj.ruby +++ b/scripts/modifyPodsXcodeproj.ruby @@ -8,7 +8,6 @@ end project.targets.each do |target| if target.name == "GrowingAnalytics" || - target.name == "GrowingAnalytics-cdp" || target.name == "GrowingUtils" || target.name == "GrowingAPM" || target.name == "Protobuf" diff --git a/scripts/update_version.sh b/scripts/update_version.sh index bfc4677f8..b80552f32 100644 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -3,8 +3,7 @@ NEW_VERSION=$@ REGEX1="[0-9]+\\.[0-9]+\\.[0-9]+((-hotfix.[0-9]+)|-beta)*" REGEX2="[0-9]+" SDK_VERSION_FILE1=./GrowingTrackerCore/GrowingRealTracker.m -SDK_VERSION_FILE2=./GrowingAnalytics-cdp.podspec -SDK_VERSION_FILE3=./GrowingAnalytics.podspec +SDK_VERSION_FILE2=./GrowingAnalytics.podspec version_to_number() { local version=$1 @@ -22,5 +21,4 @@ version_to_number() { sed -i '' -E "s/NSString \*const GrowingTrackerVersionName = @\"$REGEX1\";/NSString *const GrowingTrackerVersionName = @\"$NEW_VERSION\";/" $SDK_VERSION_FILE1 sed -i '' -E "s/const int GrowingTrackerVersionCode = $REGEX2;/const int GrowingTrackerVersionCode = $(version_to_number "$NEW_VERSION");/" $SDK_VERSION_FILE1 -sed -i '' -E "s/s.version = \'$REGEX1\'/s.version = \'$NEW_VERSION\'/" $SDK_VERSION_FILE2 -sed -i '' -E "s/s.version = \'$REGEX1\'/s.version = \'$NEW_VERSION\'/" $SDK_VERSION_FILE3 \ No newline at end of file +sed -i '' -E "s/s.version = \'$REGEX1\'/s.version = \'$NEW_VERSION\'/" $SDK_VERSION_FILE2 \ No newline at end of file From a9fb3f94c452f72501b51b40cb73d24b77764bf1 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 17 Jul 2023 10:04:27 +0800 Subject: [PATCH 037/126] docs: update Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08ee31682..aed71a4af 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ GrowingIO 专注于零售、电商、保险、酒旅航司、教育、内容社 **GrowingIO Autotracker** 具备自动采集基本的用户行为事件,比如访问和行为数据等。目前支持代码埋点、无埋点、可视化圈选、热图等功能。 ## 集成文档 -[如何集成](https://growingio.github.io/growingio-sdk-docs/docs/ios/base/Getting_Started) +[如何集成](https://growingio.github.io/growingio-sdk-docs/docs/ios/Introduce) ## License ``` From 404ce71d507798e1f3c7a3251f012f704bf3ac13 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 17 Jul 2023 16:53:48 +0800 Subject: [PATCH 038/126] fix: sequenceId for event type --- GrowingTrackerCore/Event/Base/GrowingBaseEvent.m | 8 +++++--- .../Event/Tools/GrowingPersistenceDataProvider.h | 10 +--------- .../Event/Tools/GrowingPersistenceDataProvider.m | 14 +++----------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m b/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m index 18d724ee1..4b731cecb 100644 --- a/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m +++ b/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m @@ -124,9 +124,11 @@ - (void)readPropertyInTrackThread { _platform = deviceInfo.platform; _platformVersion = deviceInfo.platformVersion; - GrowingEventSequenceObject *sequence = - [[GrowingPersistenceDataProvider sharedInstance] getAndIncrement:self.eventType]; - _eventSequenceId = sequence.sequenceId; + long long sequenceId = + [[GrowingPersistenceDataProvider sharedInstance] sequenceIdForEventType:self.eventType]; + if (sequenceId > 0) { + _eventSequenceId = sequenceId; + } GrowingSession *session = [GrowingSession currentSession]; _userId = session.loginUserId; _sessionId = session.sessionId; diff --git a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h index 363483bc6..75cbaeaed 100644 --- a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h +++ b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h @@ -21,8 +21,6 @@ NS_ASSUME_NONNULL_BEGIN -@class GrowingEventSequenceObject; - @interface GrowingPersistenceDataProvider : NSObject + (instancetype)sharedInstance; @@ -38,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)getStringforKey:(NSString *)key; -- (GrowingEventSequenceObject *)getAndIncrement:(NSString *)eventType; +- (long long)sequenceIdForEventType:(NSString *)eventType; // 防止xcode编码提示使用KVC来获取值 - (void)setValue:(id _Nullable)value forKey:(NSString *_Nonnull)key UNAVAILABLE_ATTRIBUTE; @@ -46,10 +44,4 @@ NS_ASSUME_NONNULL_BEGIN @end -@interface GrowingEventSequenceObject : NSObject - -@property (nonatomic, assign) long long sequenceId; - -@end - NS_ASSUME_NONNULL_END diff --git a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m index ea7f99a6d..a2285c4ee 100644 --- a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m +++ b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.m @@ -93,17 +93,13 @@ - (void)setString:(NSString *)value forKey:(NSString *)key { - (NSString *)getStringforKey:(NSString *)key; { return [_growingUserdefault valueForKey:key]; } -- (GrowingEventSequenceObject *)getAndIncrement:(NSString *)eventType { - int increase = 0; +- (long long)sequenceIdForEventType:(NSString *)eventType { if ([eventType isEqualToString:@"VISIT"] || [eventType isEqualToString:@"PAGE"] || [eventType isEqualToString:@"VIEW_CLICK"] || [eventType isEqualToString:@"VIEW_CHANGE"] || [eventType isEqualToString:@"CUSTOM"]) { - increase = 1; + return [self increaseFor:kGrowingUserdefault_sequenceId spanValue:1]; } - long long sequenceId = [self increaseFor:kGrowingUserdefault_sequenceId spanValue:increase]; - GrowingEventSequenceObject *obj = [[GrowingEventSequenceObject alloc] init]; - obj.sequenceId = sequenceId; - return obj; + return 0; } - (long long)increaseFor:(NSString *)key spanValue:(int)span { @@ -120,7 +116,3 @@ - (long long)increaseFor:(NSString *)key spanValue:(int)span { } @end - -@implementation GrowingEventSequenceObject - -@end From 0f60212c52a52ea08ff04d2674c4a67199d99209 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 17 Jul 2023 08:54:45 +0000 Subject: [PATCH 039/126] style: code format --- GrowingTrackerCore/Event/Base/GrowingBaseEvent.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m b/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m index 4b731cecb..ef3e5d86c 100644 --- a/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m +++ b/GrowingTrackerCore/Event/Base/GrowingBaseEvent.m @@ -124,8 +124,7 @@ - (void)readPropertyInTrackThread { _platform = deviceInfo.platform; _platformVersion = deviceInfo.platformVersion; - long long sequenceId = - [[GrowingPersistenceDataProvider sharedInstance] sequenceIdForEventType:self.eventType]; + long long sequenceId = [[GrowingPersistenceDataProvider sharedInstance] sequenceIdForEventType:self.eventType]; if (sequenceId > 0) { _eventSequenceId = sequenceId; } From 33361cdd8be8bb936b50cbcf7c1ab90e7b33beab Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 18 Jul 2023 18:04:15 +0800 Subject: [PATCH 040/126] test: update ci --- Example/Example.xcodeproj/project.pbxproj | 4 + .../AutotrackerTests/Event/A3PageEventsTest.m | 263 ++++++++++++++++++ 2 files changed, 267 insertions(+) create mode 100644 Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index f3919ec38..64ebf8fe4 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -74,6 +74,7 @@ 04A6FAF524E67215006C72F0 /* GIOBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A6FAF424E67215006C72F0 /* GIOBaseViewController.m */; }; 04F675662628293800077374 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04F675652628293800077374 /* AdSupport.framework */; }; 33A0F692F1D1738D6854E19A /* Pods_HostApplicationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42F5EA0EFE2552358C35A0F5 /* Pods_HostApplicationTests.framework */; }; + 3406842B2A668EB700E25216 /* A3PageEventsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3406842A2A668EB700E25216 /* A3PageEventsTest.m */; }; 34486D3D27B1049000FA8223 /* UITapGestureRecognizerAutotrackTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34486D3B27B102B000FA8223 /* UITapGestureRecognizerAutotrackTest.m */; }; 34664587278EEEA6009C351C /* A0GrowingAnalyticsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 047BF3A224F638BB0028FE94 /* A0GrowingAnalyticsTest.m */; }; 346E0B3B29F2724400A12E4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346E0B3A29F2724400A12E4E /* AppDelegate.swift */; }; @@ -297,6 +298,7 @@ 04F675652628293800077374 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 0B3751A8D7A8C11CD50B544E /* Pods-GrowingAnalyticsStartTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GrowingAnalyticsStartTests.debug.xcconfig"; path = "../Example/Pods/Target Support Files/Pods-GrowingAnalyticsStartTests/Pods-GrowingAnalyticsStartTests.debug.xcconfig"; sourceTree = ""; }; 1769255A062869A5D219F683 /* Pods_GrowingAnalyticsStartTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GrowingAnalyticsStartTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 3406842A2A668EB700E25216 /* A3PageEventsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = A3PageEventsTest.m; sourceTree = ""; }; 34106BB228FECB0D00E7DB01 /* Crasher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Crasher.h; sourceTree = ""; }; 34106BB328FECB0E00E7DB01 /* Crasher.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Crasher.mm; sourceTree = ""; }; 34486D3B27B102B000FA8223 /* UITapGestureRecognizerAutotrackTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UITapGestureRecognizerAutotrackTest.m; sourceTree = ""; }; @@ -804,6 +806,7 @@ children = ( 34BF77C22795568B00CA18BA /* A1ViewClickEventsTest.m */, 34BF77C32795568B00CA18BA /* A2ViewChangeEventsTest.m */, + 3406842A2A668EB700E25216 /* A3PageEventsTest.m */, ); path = Event; sourceTree = ""; @@ -2247,6 +2250,7 @@ 34BF77CB279562AC00CA18BA /* ManualTrackHelper.m in Sources */, 34821C6C27B25AE7006C8B8E /* HybridTest_HostApp.m in Sources */, 34BF77C92795571000CA18BA /* MockEventQueue.m in Sources */, + 3406842B2A668EB700E25216 /* A3PageEventsTest.m in Sources */, 34486D3D27B1049000FA8223 /* UITapGestureRecognizerAutotrackTest.m in Sources */, 34BF77C62795568C00CA18BA /* A1ViewClickEventsTest.m in Sources */, 34BF77C72795568C00CA18BA /* A2ViewChangeEventsTest.m in Sources */, diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m new file mode 100644 index 000000000..73daa717f --- /dev/null +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m @@ -0,0 +1,263 @@ +// +// A2PageEventsTest.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/18. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +#import "GrowingAutotracker.h" +#import "MockEventQueue.h" +#import "ManualTrackHelper.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" + +@interface A2PageEventsTest : KIFTestCase + +@end + +@implementation A2PageEventsTest + ++ (void)setUp { + // userId userKey + [GrowingAutotracker.sharedInstance setLoginUserId:@"xctest_userId" userKey:@"xctest_userKey"]; + // latitude longitude + [GrowingAutotracker.sharedInstance setLocation:30.12345 longitude:31.123456]; +} + +- (void)setUp { + [[viewTester usingLabel:@"协议/接口"] tap]; + [MockEventQueue.sharedQueue cleanQueue]; +} + +- (void)tearDown { + [[viewTester usingLabel:@"协议/接口"] tap]; +} + +- (void)test01AutotrackPage { + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [[viewTester usingLabel:@"Button"] tap]; + + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertGreaterThanOrEqual(events.count, 1); + + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; + XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); + XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.attributes[@"key"], @"value"); + + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); + XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } + + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 3); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.lastObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"textValue"], @"Button"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } +} + +- (void)test02AutotrackPageDelay { + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [[viewTester usingLabel:@"Button"] tap]; + + // 立即点击按钮,由于尚未调用autotrackPage,path字段无值 + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 3); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.lastObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"path"], @""); + XCTAssertEqualObjects(dic[@"textValue"], @"Button"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); + } + + // demo中在3.0秒后调用autotrackPage,发送PAGE事件,再次点击按钮,path有值 + XCTestExpectation *expectation = [self expectationWithDescription:@"test02AutotrackPageDelay failed : timeout"]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertGreaterThanOrEqual(events.count, 1); + + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; + XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); + XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.attributes[@"key"], @"value"); + + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); + XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } + + [[viewTester usingLabel:@"Button"] tap]; + + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 3); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.lastObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"textValue"], @"Button"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } + + [expectation fulfill]; + }); + [self waitForExpectationsWithTimeout:10.0f handler:nil]; +} + +- (void)test03AutotrackPageWithoutCallSuperViewDidAppear { + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [[viewTester usingLabel:@"Button"] tap]; + + // 不兼容在viewDidLoad调用autotrackPage,却未调用super viewDidAppear的情况 + // 此时不会发送PAGE事件,但会将alias与attributes赋值 + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 0); + } + + // path、attributes有值 + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 3); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.lastObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"textValue"], @"Button"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } +} + +- (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [[viewTester usingLabel:@"Button"] tap]; + + // 立即点击按钮,由于尚未调用autotrackPage,path字段无值 + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 3); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.lastObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"path"], @""); + XCTAssertEqualObjects(dic[@"textValue"], @"Button"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); + } + + // demo中在3.0秒后调用autotrackPage,由于实际上已经过了viewDidAppear生命周期,所以sdk内部可判断发送PAGE事件,再次点击按钮,path有值 + XCTestExpectation *expectation = [self expectationWithDescription:@"test02AutotrackPageDelay failed : timeout"]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertGreaterThanOrEqual(events.count, 1); + + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; + XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); + XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.attributes[@"key"], @"value"); + + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); + XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } + + [[viewTester usingLabel:@"Button"] tap]; + + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 3); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.lastObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"textValue"], @"Button"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } + + [expectation fulfill]; + }); + [self waitForExpectationsWithTimeout:10.0f handler:nil]; +} + +@end From b1cff8a667028a967b65e4b07d1073a3c9b8dfe8 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 18 Jul 2023 19:17:26 +0800 Subject: [PATCH 041/126] test: update ci --- .../AutotrackerTests/Event/A3PageEventsTest.m | 55 ++++++++++++++++++- .../Page/GrowingPageManager.m | 37 +++++-------- 2 files changed, 67 insertions(+), 25 deletions(-) diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m index 73daa717f..be8b324af 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m @@ -198,7 +198,7 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; - // 立即点击按钮,由于尚未调用autotrackPage,path字段无值 + // 立即点击按钮,走findPageByView内部的补page逻辑,由于尚未调用autotrackPage,path字段无值 { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 3); @@ -260,4 +260,57 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { [self waitForExpectationsWithTimeout:10.0f handler:nil]; } +- (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]]; + [viewTester waitForAnimationsToFinish]; + [[viewTester usingLabel:@"Button"] tap]; + + // 不点击按钮,走autotrackPage内部的补page逻辑 + + // demo中在3.0秒后调用autotrackPage,由于实际上已经过了viewDidAppear生命周期,所以sdk内部可判断发送PAGE事件,再次点击按钮,path有值 + XCTestExpectation *expectation = [self expectationWithDescription:@"test02AutotrackPageDelay failed : timeout"]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; + XCTAssertGreaterThanOrEqual(events.count, 1); + + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; + XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); + XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.attributes[@"key"], @"value"); + + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); + XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } + + [[viewTester usingLabel:@"Button"] tap]; + + { + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertGreaterThanOrEqual(events.count, 3); + + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.lastObject; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"textValue"], @"Button"); + XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); + } + + [expectation fulfill]; + }); + [self waitForExpectationsWithTimeout:10.0f handler:nil]; +} + @end diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.m b/GrowingAutotrackerCore/Page/GrowingPageManager.m index 778c3d7e0..4b5819802 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.m +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.m @@ -148,33 +148,10 @@ - (BOOL)isDidAppearController:(UIViewController *)vc { } - (BOOL)isPrivateViewController:(UIViewController *)viewController { - if (!viewController) { - return NO; - } NSString *vcName = NSStringFromClass([viewController class]); return [self.ignoredPrivateControllers containsObject:vcName]; } -- (GrowingPage *)findPageByViewController:(UIViewController *)controller { - while ([self isPrivateViewController:controller]) { - controller = (UIViewController *)controller.growingNodeParent; - } - - if (!controller) { - return self.currentPage; - } - - GrowingPage *page = controller.growingPageObject; - if (!page) { - // 执行到此,执行流程大概是view -> findPageByView -> findPageByViewController - // view所在viewcontroller必定到了viewDidAppear生命周期 - // 一般来说,page对象在viewDidAppear时就已创建,此处兼容page对象未生成的特殊情况,比如: - // 用户未在自定义的ViewController viewDidAppear中调用super viewDidAppear - page = [self createdPage:controller]; - } - return page; -} - - (void)autotrackPage:(UIViewController *)controller alias:(NSString *)alias attributes:(NSDictionary *_Nullable)attributes { @@ -205,10 +182,22 @@ - (void)autotrackPage:(UIViewController *)controller - (GrowingPage *)findPageByView:(UIView *)view { UIViewController *current = [view growingHelper_viewController]; + while (current && [self isPrivateViewController:current]) { + current = (UIViewController *)current.growingNodeParent; + } if (!current) { return self.currentPage; } - return [self findPageByViewController:current]; + + GrowingPage *page = current.growingPageObject; + if (!page) { + // 执行到此,执行流程大概是view -> findPageByView + // view所在viewcontroller必定到了viewDidAppear生命周期 + // 一般来说,page对象在viewDidAppear时就已创建,此处兼容page对象未生成的特殊情况,比如: + // 用户未在自定义的ViewController viewDidAppear中调用super viewDidAppear + page = [self createdPage:current]; + } + return page; } - (GrowingPage *)findAutotrackPageByPage:(GrowingPage *)page { From b50ed5c6e12f79e24d653284526898caee706b55 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 19 Jul 2023 16:20:26 +0800 Subject: [PATCH 042/126] fix: delete unused codes --- ...IOMeasurementProtocolTableViewController.m | 2 +- .../GrowingNodeTests/NodeTest.m | 5 - .../Event/A1ViewClickEventsTest.m | 102 +++++++++++++++--- GrowingAutotracker/GrowingAutotracker.m | 1 - .../UISegmentedControl+GrowingAutotracker.m | 6 +- .../UIViewController+GrowingAutotracker.h | 1 - .../UIViewController+GrowingAutotracker.m | 6 -- .../Category/UIAlertController+GrowingNode.m | 8 +- .../Category/UIApplication+GrowingNode.m | 6 +- .../Category/UICollectionView+GrowingNode.m | 20 ---- .../Category/UILabel+GrowingNode.m | 5 +- .../Category/UISegmentedControl+GrowingNode.m | 6 +- .../Category/UITableView+GrowingNode.m | 6 +- .../GrowingNode/Category/UIView+GrowingNode.h | 1 - .../Category/UIViewController+GrowingNode.m | 28 ----- .../Category/UIWindow+GrowingNode.m | 6 +- .../GrowingRealAutotracker.m | 1 - GrowingAutotrackerCore/Page/GrowingPage.m | 8 +- .../Page/GrowingPageManager.h | 2 - .../Page/GrowingPageManager.m | 9 -- .../Event/GrowingNodeProtocol.h | 16 +-- 21 files changed, 110 insertions(+), 135 deletions(-) diff --git a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m index 50ab8e418..94fd8da2d 100644 --- a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m +++ b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m @@ -78,7 +78,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.translatesAutoresizingMaskIntoConstraints = NO; - [button setTitle:@"button" forState:UIControlStateNormal]; + [button setTitle:[NSString stringWithFormat:@"header%ld", (long)section] forState:UIControlStateNormal]; [button setBackgroundColor:UIColor.grayColor]; [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; [vHeader addSubview:button]; diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m index 3c8162114..d09ab9915 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m @@ -38,11 +38,6 @@ -(void)testGrowingUIViewController { #pragma clang diagnostic ignored "-Wundeclared-selector" UIViewController *vc1 = [[UIViewController alloc]init]; [vc1 performSelector:@selector(growingNodeParent)]; - [vc1 performSelector:@selector(growingAppearStateCanTrack)]; - [vc1 performSelector:@selector(growingNodeDonotTrack)]; - [vc1 performSelector:@selector(growingNodeDonotCircle)]; - [vc1 performSelector:@selector(growingNodeUserInteraction)]; - [vc1 performSelector:@selector(growingNodeContent)]; [vc1 performSelector:@selector(growingNodeKeyIndex)]; [vc1 performSelector:@selector(growingNodeSubPath)]; [vc1 performSelector:@selector(growingNodeSubIndex)]; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 60ba16194..e97e19537 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -12,6 +12,8 @@ #import "MockEventQueue.h" #import "ManualTrackHelper.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" +#import "GrowingAutotrackerCore/Page/GrowingPageManager.h" @interface A1ViewClickEventsTest : KIFTestCase @@ -35,14 +37,38 @@ - (void)tearDown { [[viewTester usingLabel:@"UI界面"] tap]; } +- (void)checkWebCirclePathWithView:(UIView *)view xpath:(NSString *)xpathForView xindex:(NSString *)xindexForView originxindex:(NSString *)originxindexForView { + // 检查圈选的计算逻辑得出的xpath、xindex是否正确 + GrowingPage *page = [[GrowingPageManager sharedInstance] findPageByView:view]; + NSDictionary *pathInfo = page.pathInfo; + NSString *pagexpath = pathInfo[@"xpath"]; + NSString *pagexindex = pathInfo[@"xindex"]; + [GrowingNodeHelper recalculateXpath:view block:^(NSString * _Nonnull xpath, NSString * _Nonnull xindex, NSString * _Nonnull originxindex) { + xpath = [NSString stringWithFormat:@"%@/%@", pagexpath, xpath]; + xindex = [NSString stringWithFormat:@"%@/%@", pagexindex, xindex]; + originxindex = [NSString stringWithFormat:@"%@/%@", pagexindex, originxindex]; + XCTAssertEqualObjects(xpathForView, xpath); + XCTAssertEqualObjects(xindexForView, xindex); + XCTAssertEqualObjects(originxindexForView, originxindex); + }]; +} + - (void)test01AlertButtonClick { // 对话框按钮点击,检测click事件 [[viewTester usingLabel:@"AttributeLabel"] tap]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"ShowAlert"] tap]; [viewTester waitForAnimationsToFinish]; - [[viewTester usingLabel:@"取消"] tap]; + KIFUIViewTestActor *actor = [viewTester usingLabel:@"取消"]; + NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/" + @"_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfac" + @"eActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"; + NSString *xindexForView = @"/0/1/0/0/0/0/0/0/0/1/0"; + NSString *originxindexForView = @"/0/1/0/0/0/0/0/0/0/1/0"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + [actor tap]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 2); @@ -55,9 +81,8 @@ - (void)test01AlertButtonClick { XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"取消"); - XCTAssertEqualObjects(dic[@"xpath"], - @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfaceActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/0/0/0/0/1/0"); + XCTAssertEqualObjects(dic[@"xpath"], xpathForView); + XCTAssertEqualObjects(dic[@"xindex"], xindexForView); } { @@ -121,7 +146,13 @@ - (void)test03ButtonWithImageViewClick { // 单击ButtonWithImageView,检测click事件 [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; - [[viewTester usingLabel:@"Food"] tap]; + + KIFUIViewTestActor *actor = [viewTester usingLabel:@"Food"]; + NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; + NSString *xindexForView = @"/0/1/0/0/0/0"; + NSString *originxindexForView = @"/0/1/0/0/0/0"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + [actor tap]; [[viewTester usingLabel:@"好的"] tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -135,8 +166,8 @@ - (void)test03ButtonWithImageViewClick { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"Food"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xpath"], xpathForView); + XCTAssertEqualObjects(dic[@"xindex"], xindexForView); } } @@ -144,8 +175,15 @@ - (void)test04UIViewButtonClick { // 单击UIViewButton,检测click事件 [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; - [[viewTester usingLabel:@"Fire"] tap]; + + KIFUIViewTestActor *actor = [viewTester usingLabel:@"Fire"]; + NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; + NSString *xindexForView = @"/0/1/0/0/0/1"; + NSString *originxindexForView = @"/0/1/0/0/0/1"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + [actor tap]; [[viewTester usingLabel:@"好的"] tap]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 3); @@ -157,8 +195,8 @@ - (void)test04UIViewButtonClick { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"Fire"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/1"); + XCTAssertEqualObjects(dic[@"xpath"], xpathForView); + XCTAssertEqualObjects(dic[@"xindex"], xindexForView); } } @@ -167,7 +205,13 @@ - (void)test05UISegmentedControlClick { [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"SecondSegment"] tap]; - [[viewTester usingLabel:@"ThirdSegment"] tap]; + + KIFUIViewTestActor *actor = [viewTester usingLabel:@"ThirdSegment"]; + NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UISegmentedControl/UISegment"; + NSString *xindexForView = @"/0/1/0/0/0/-"; + NSString *originxindexForView = @"/0/1/0/0/0/2"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + [actor tap]; [viewTester waitForAnimationsToFinish]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 3); @@ -180,9 +224,9 @@ - (void)test05UISegmentedControlClick { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"Third"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UISegmentedControl/UISegment"); + XCTAssertEqualObjects(dic[@"xpath"], xpathForView); XCTAssertEqualObjects(dic[@"index"], @(2)); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/-"); + XCTAssertEqualObjects(dic[@"xindex"], xindexForView); } } @@ -216,7 +260,35 @@ - (void)test06ClickCustomContent { [[viewTester usingLabel:@"好的"] tap]; } -- (void)test07IgnoreViewClass { +- (void)test07UITableViewHeaderFooterViewButtonClick { + // 单击UITableViewHeaderFooterView上的Button,检测click事件 + [[viewTester usingLabel:@"协议/接口"] tap]; + [viewTester waitForAnimationsToFinish]; + + KIFUIViewTestActor *actor = [viewTester usingLabel:@"header1"]; + NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOMeasurementProtocolTableViewController/UITableView/UITableViewHeaderFooterView/UIButton"; + NSString *xindexForView = @"/0/0/0/0/1/0"; + NSString *originxindexForView = @"/0/0/0/0/1/0"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + [actor tap]; + + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertEqual(events.count, 2); + + { + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events[events.count - 1]; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"textValue"], @"header1"); + XCTAssertEqualObjects(dic[@"xpath"], xpathForView); + XCTAssertEqualObjects(dic[@"xindex"], xindexForView); + } +} + +- (void)test08IgnoreViewClass { [[viewTester usingLabel:@"IgnoreViewClass"] tap]; [viewTester waitForAnimationsToFinish]; @@ -245,7 +317,7 @@ - (void)test07IgnoreViewClass { XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0"); } -- (void)test08IgnoreViewClasses { +- (void)test09IgnoreViewClasses { [[viewTester usingLabel:@"IgnoreViewClass"] tap]; [viewTester waitForAnimationsToFinish]; diff --git a/GrowingAutotracker/GrowingAutotracker.m b/GrowingAutotracker/GrowingAutotracker.m index 5a8686d21..296e79ad8 100644 --- a/GrowingAutotracker/GrowingAutotracker.m +++ b/GrowingAutotracker/GrowingAutotracker.m @@ -20,7 +20,6 @@ #import "GrowingAutotracker/GrowingAutotracker.h" #import "GrowingAutotrackerCore/GrowingRealAutotracker.h" #import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" static GrowingAutotracker *sharedInstance = nil; diff --git a/GrowingAutotrackerCore/Autotrack/UISegmentedControl+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UISegmentedControl+GrowingAutotracker.m index 41a5b79c1..f361fdb4c 100644 --- a/GrowingAutotrackerCore/Autotrack/UISegmentedControl+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UISegmentedControl+GrowingAutotracker.m @@ -48,10 +48,8 @@ + (NSString *)growing_titleForSegment:(UIView *)segment { - (nullable NSArray *)growing_segmentViews { NSArray *array = nil; - if ([self growingHelper_getIvar:"_segments" outObj:&array]) { - return array; - } - return nil; + [self growingHelper_getIvar:"_segments" outObj:&array]; + return array; } static void growingUISegmentedControlSetUp(UISegmentedControl *self) { diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h index e7a03eb97..3a470a398 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h @@ -29,7 +29,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy) NSString *growingPageAlias; @property (nonatomic, copy) NSDictionary *growingPageAttributes; -- (BOOL)growingHookIsCustomAddVC; // 用来判断是否是没有使用addChildViewController方法的childVC - (nullable NSString *)growingPageTitle; @end diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m index 63d8ceb7d..0e4c1d666 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m @@ -20,7 +20,6 @@ #import #import "GrowingAutotrackerCore/Autotrack/GrowingPropertyDefine.h" #import "GrowingAutotrackerCore/Page/GrowingPage.h" -#import "GrowingULViewControllerLifecycle.h" static char kGrowingPageObjectKey; static char kGrowingPageAttributesKey; @@ -38,11 +37,6 @@ - (nullable NSString *)growingPageTitle { return currentPageName; } -- (BOOL)growingHookIsCustomAddVC { - return !self.growingul_didAppear && self.parentViewController == nil && - [UIApplication sharedApplication].keyWindow.rootViewController != self; -} - - (void)setGrowingPageObject:(GrowingPage *)page { objc_setAssociatedObject(self, &kGrowingPageObjectKey, page, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m index bbb9ae059..e14649cbf 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.m @@ -83,16 +83,12 @@ - (NSString *)growingNodeSubIndex { return subIndex; } -- (BOOL)growingNodeUserInteraction { +- (BOOL)growingViewUserInteraction { return YES; } - (NSString *)growingNodeContent { - NSString *nodeContent = [[UIAlertController growing_actionForActionView:(id)self] title]; - if (nodeContent.length) { - return nodeContent; - } - return nil; + return [[UIAlertController growing_actionForActionView:(id)self] title]; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.m index 68a6626f6..fa830c4a5 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIApplication+GrowingNode.m @@ -22,13 +22,15 @@ @implementation UIApplication (GrowingNode) - (UIWindow *)growingMainWindow { + UIWindow *w = nil; for (NSUInteger i = 0; i < self.windows.count; i++) { UIWindow *window = self.windows[i]; if (window.windowLevel == UIWindowLevelNormal && window.hidden == NO) { - return window; + w = window; + break; } } - return nil; + return w; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m index 3b93d4b2d..12c000744 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m @@ -83,26 +83,6 @@ - (NSString *)growingNodeSubSimilarIndex { return [super growingNodeSubIndex]; } -- (BOOL)growingNodeUserInteraction { - return YES; -} - -- (BOOL)growingViewUserInteraction { - return YES; -} - -@end - -@interface UICollectionReusableView (GrowingNode) - -@end - -@implementation UICollectionReusableView (GrowingNode) - -- (BOOL)growingNodeUserInteraction { - return YES; -} - - (BOOL)growingViewUserInteraction { return YES; } diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m index fdb61fee4..cff6e6b8c 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UILabel+GrowingNode.m @@ -22,10 +22,7 @@ @implementation UILabel (GrowingNode) - (NSString *)growingViewContent { - if (self.text.length) { - return self.text; - } - return nil; + return self.text; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m index a460fec91..272c74ad0 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.m @@ -75,11 +75,7 @@ - (NSString *)growingNodeSubSimilarIndex { } - (NSString *)growingNodeContent { - NSString *nodeContent = [UISegmentedControl growing_titleForSegment:(id)self]; - if (nodeContent.length) { - return nodeContent; - } - return nil; + return [UISegmentedControl growing_titleForSegment:(id)self]; } @end diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m index 573fa2703..a34104ba8 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m @@ -96,14 +96,10 @@ - (NSString *)growingNodeSubSimilarIndex { return childs; } -- (BOOL)growingNodeUserInteraction { +- (BOOL)growingViewUserInteraction { return YES; } -- (BOOL)growingNodeDonotCircle { - return [super growingNodeDonotCircle]; -} - @end @implementation UITableViewHeaderFooterView (GrowingNode) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h index f911d89af..888a51a80 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.h @@ -24,7 +24,6 @@ @interface UIView (GrowingNode) @property (nonatomic, copy) NSString *growingUniqueTag; -- (BOOL)growingViewUserInteraction; - (NSString *)growingViewContent; - (BOOL)growingViewDontTrack; diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m index b9de68bac..1eb72c95f 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIViewController+GrowingNode.m @@ -78,34 +78,6 @@ - (CGRect)growingNodeFrame { } } -- (BOOL)growingAppearStateCanTrack { - if ([[GrowingPageManager sharedInstance] isDidAppearController:self]) { - return YES; - } - // 此处判断意义在于避免没有使用addChildViewController方法的childVC没有调用didappear - // 造成checknode失败 页面元素无法收集 - if ([self growingHookIsCustomAddVC]) { - return YES; - } - return NO; -} - -- (BOOL)growingNodeDonotTrack { - return (![self isViewLoaded] || !self.view.window || ![self growingAppearStateCanTrack]); -} - -- (BOOL)growingNodeDonotCircle { - return NO; -} - -- (BOOL)growingNodeUserInteraction { - return NO; -} - -- (NSString *)growingNodeContent { - return nil; -} - #pragma mark - xpath - (NSInteger)growingNodeKeyIndex { NSString *classString = NSStringFromClass(self.class); diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m index 626cdedcb..ddcb4ac60 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIWindow+GrowingNode.m @@ -22,11 +22,7 @@ @implementation UIWindow (GrowingNode) - (id)growingNodeParent { - if (self.superview) { - return self.superview; - } else { - return nil; - } + return self.superview; } - (CGRect)growingNodeFrame { diff --git a/GrowingAutotrackerCore/GrowingRealAutotracker.m b/GrowingAutotrackerCore/GrowingRealAutotracker.m index 7c6a5e42f..752602784 100644 --- a/GrowingAutotrackerCore/GrowingRealAutotracker.m +++ b/GrowingAutotrackerCore/GrowingRealAutotracker.m @@ -30,7 +30,6 @@ #import "GrowingAutotrackerCore/GrowingNode/Category/UIAlertController+GrowingNode.h" #import "GrowingAutotrackerCore/GrowingNode/Category/UISegmentedControl+GrowingNode.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" -#import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingTrackerCore/Utils/GrowingArgumentChecker.h" diff --git a/GrowingAutotrackerCore/Page/GrowingPage.m b/GrowingAutotrackerCore/Page/GrowingPage.m index 5edd932ec..d767bef74 100644 --- a/GrowingAutotrackerCore/Page/GrowingPage.m +++ b/GrowingAutotrackerCore/Page/GrowingPage.m @@ -91,9 +91,6 @@ - (NSString *)alias { } - (NSString *)tag { - if (self.carrier == nil) { - return nil; - } UIViewController *parentViewController = self.carrier.parentViewController; if (parentViewController == nil) { return nil; @@ -102,14 +99,13 @@ - (NSString *)tag { int index = 0; for (UIViewController *child in childs) { if (self.carrier == child) { - return [NSString stringWithFormat:@"%d", index]; + break; } - if (self.carrier.class == child.class) { index++; } } - return nil; + return [NSString stringWithFormat:@"%d", index]; } - (NSDictionary *)pathInfo { diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.h b/GrowingAutotrackerCore/Page/GrowingPageManager.h index 021796e01..cf43d63df 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.h +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.h @@ -31,8 +31,6 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingPage *)currentPage; - (NSArray *)allDidAppearPages; -- (BOOL)isDidAppearController:(UIViewController *)vc; - - (void)autotrackPage:(UIViewController *)controller alias:(NSString *)alias attributes:(NSDictionary *_Nullable)attributes; diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.m b/GrowingAutotrackerCore/Page/GrowingPageManager.m index 4b5819802..56590926a 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.m +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.m @@ -138,15 +138,6 @@ - (GrowingPage *)findParentPage:(UIViewController *)carrier { return self.visiablePages.allObjects; } -- (BOOL)isDidAppearController:(UIViewController *)vc { - for (GrowingPage *page in self.visiablePages) { - if (page.carrier == vc) { - return YES; - } - } - return NO; -} - - (BOOL)isPrivateViewController:(UIViewController *)viewController { NSString *vcName = NSStringFromClass([viewController class]); return [self.ignoredPrivateControllers containsObject:vcName]; diff --git a/GrowingTrackerCore/Event/GrowingNodeProtocol.h b/GrowingTrackerCore/Event/GrowingNodeProtocol.h index a5917d70c..ec4b50aed 100644 --- a/GrowingTrackerCore/Event/GrowingNodeProtocol.h +++ b/GrowingTrackerCore/Event/GrowingNodeProtocol.h @@ -36,20 +36,20 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *growingNodeSubSimilarIndex; /// 原始父节点 - (id _Nullable)growingNodeParent; -/// 不进行track -- (BOOL)growingNodeDonotTrack; -/// 不进行圈选 -- (BOOL)growingNodeDonotCircle; -/// 是否可交互 -- (BOOL)growingNodeUserInteraction; -/// 内容 -- (NSString *_Nullable)growingNodeContent; /// 在主window的frame - (CGRect)growingNodeFrame; @optional /// 过滤后的子节点,例如UITableView子节点只需要是cell和footter - (NSArray> *_Nullable)growingNodeChilds; +/// 是否可交互(仅UIView) +- (BOOL)growingNodeUserInteraction; +/// 不进行track(仅UIView) +- (BOOL)growingNodeDonotTrack; +/// 不进行圈选(仅UIView) +- (BOOL)growingNodeDonotCircle; +/// 内容(仅UIView) +- (NSString *_Nullable)growingNodeContent; @end From 43949fa9454785d3b3e7ebfec896530a20c8a79e Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 24 Jul 2023 11:28:00 +0800 Subject: [PATCH 043/126] test: update ci --- Example/Example.xcodeproj/project.pbxproj | 4 +- ...IOMeasurementProtocolTableViewController.m | 3 +- .../AutotrackerTests/Event/A3PageEventsTest.m | 82 +++--- .../WebCircleTests/WebCircleTest.m | 270 +++++++++++------- Modules/WebCircle/GrowingWebCircle.m | 16 +- 5 files changed, 224 insertions(+), 151 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 64ebf8fe4..613d114d4 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 346EABE5277EE1FD00A32B03 /* HybridTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 42ADE26B250B292900CA7268 /* HybridTest.m */; }; 346EABEB277EE53200A32B03 /* DeviceInfoTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 346EABEA277EE53200A32B03 /* DeviceInfoTest.m */; }; 346EABF2277EE63F00A32B03 /* NodeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 346EABF1277EE63F00A32B03 /* NodeTest.m */; }; + 34734EE52A69118E00BF54F4 /* WebCircleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34BA7B44277D91900030AC21 /* WebCircleTest.m */; }; 347B8F432A0A46DD00B8A114 /* ScreenshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 347B8F422A0A46DD00B8A114 /* ScreenshotTest.m */; }; 34821C6727B247DB006C8B8E /* UISegmentedControlAutotrackTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34821C6627B247DB006C8B8E /* UISegmentedControlAutotrackTest.m */; }; 34821C6C27B25AE7006C8B8E /* HybridTest_HostApp.m in Sources */ = {isa = PBXBuildFile; fileRef = 34821C6B27B25AE7006C8B8E /* HybridTest_HostApp.m */; }; @@ -154,7 +155,6 @@ 34BA7B37277C64070030AC21 /* ProtobufPersistenceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A4C02C276C3A7E0056C8C4 /* ProtobufPersistenceTest.m */; }; 34BA7B38277C640B0030AC21 /* ProtobufEventsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A4C02D276C3A7E0056C8C4 /* ProtobufEventsTest.m */; }; 34BA7B39277C640F0030AC21 /* ProtobufRequestHeaderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A4C02E276C3A7E0056C8C4 /* ProtobufRequestHeaderTest.m */; }; - 34BA7B45277D91900030AC21 /* WebCircleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34BA7B44277D91900030AC21 /* WebCircleTest.m */; }; 34BA7B48277D92840030AC21 /* FileStorageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34BA7B47277D92840030AC21 /* FileStorageTest.m */; }; 34BDC35A277088D40030B3CE /* UICatalogTests.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 34BDC359277088D40030B3CE /* UICatalogTests.storyboard */; }; 34BF77AE2795095100CA18BA /* GrowingSessionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34BF77AD2795095100CA18BA /* GrowingSessionTest.m */; }; @@ -2196,7 +2196,6 @@ 34AC7AC92798270500C0DFA5 /* GrowingUIKitHelpersTest.m in Sources */, 34BA7B24277C62E70030AC21 /* HybridEventTest.m in Sources */, 34B2147C27966142004E2CE3 /* DatabaseTest.m in Sources */, - 34BA7B45277D91900030AC21 /* WebCircleTest.m in Sources */, 34BA7B2A277C63660030AC21 /* MockEventQueue.m in Sources */, 34AC7ACB2798271E00C0DFA5 /* GrowingFoundationHelpersTest.m in Sources */, 34B2148727969562004E2CE3 /* DynamicProxyTest.m in Sources */, @@ -2247,6 +2246,7 @@ files = ( 34AC7ACE279829FC00C0DFA5 /* GrowingUIKitHelpersTest.m in Sources */, 34AC7ACD2798289C00C0DFA5 /* InvocationHelper.m in Sources */, + 34734EE52A69118E00BF54F4 /* WebCircleTest.m in Sources */, 34BF77CB279562AC00CA18BA /* ManualTrackHelper.m in Sources */, 34821C6C27B25AE7006C8B8E /* HybridTest_HostApp.m in Sources */, 34BF77C92795571000CA18BA /* MockEventQueue.m in Sources */, diff --git a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m index 94fd8da2d..bbbfcc878 100644 --- a/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m +++ b/Example/Example/MeasurementProtocol/GIOMeasurementProtocolTableViewController.m @@ -79,14 +79,13 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.translatesAutoresizingMaskIntoConstraints = NO; [button setTitle:[NSString stringWithFormat:@"header%ld", (long)section] forState:UIControlStateNormal]; - [button setBackgroundColor:UIColor.grayColor]; [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; [vHeader addSubview:button]; [NSLayoutConstraint activateConstraints:@[ [button.centerYAnchor constraintEqualToAnchor:vHeader.centerYAnchor], [button.trailingAnchor constraintEqualToAnchor:vHeader.trailingAnchor constant:-15.0f], - [button.widthAnchor constraintEqualToConstant:60.0f], + [button.widthAnchor constraintEqualToConstant:80.0f], [button.heightAnchor constraintEqualToConstant:35.0f] ]]; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m index be8b324af..8fc98241c 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m @@ -20,16 +20,16 @@ #import #import "GrowingAutotracker.h" -#import "MockEventQueue.h" -#import "ManualTrackHelper.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "ManualTrackHelper.h" +#import "MockEventQueue.h" -@interface A2PageEventsTest : KIFTestCase +@interface A3PageEventsTest : KIFTestCase @end -@implementation A2PageEventsTest +@implementation A3PageEventsTest + (void)setUp { // userId userKey @@ -53,11 +53,11 @@ - (void)test01AutotrackPage { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; - + { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertGreaterThanOrEqual(events.count, 1); - + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); XCTAssertEqualObjects(event.pageName, @"页面测试"); @@ -70,7 +70,7 @@ - (void)test01AutotrackPage { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } - + { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 3); @@ -83,7 +83,9 @@ - (void)test01AutotrackPage { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -95,7 +97,7 @@ - (void)test02AutotrackPageDelay { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; - + // 立即点击按钮,由于尚未调用autotrackPage,path字段无值 { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -109,23 +111,25 @@ - (void)test02AutotrackPageDelay { XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); } - + // demo中在3.0秒后调用autotrackPage,发送PAGE事件,再次点击按钮,path有值 XCTestExpectation *expectation = [self expectationWithDescription:@"test02AutotrackPageDelay failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertGreaterThanOrEqual(events.count, 1); - + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); XCTAssertEqualObjects(event.pageName, @"页面测试"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); @@ -133,9 +137,9 @@ - (void)test02AutotrackPageDelay { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } - + [[viewTester usingLabel:@"Button"] tap]; - + { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 3); @@ -148,7 +152,9 @@ - (void)test02AutotrackPageDelay { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -164,14 +170,14 @@ - (void)test03AutotrackPageWithoutCallSuperViewDidAppear { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; - + // 不兼容在viewDidLoad调用autotrackPage,却未调用super viewDidAppear的情况 // 此时不会发送PAGE事件,但会将alias与attributes赋值 { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 0); } - + // path、attributes有值 { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -185,7 +191,9 @@ - (void)test03AutotrackPageWithoutCallSuperViewDidAppear { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -197,7 +205,7 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; - + // 立即点击按钮,走findPageByView内部的补page逻辑,由于尚未调用autotrackPage,path字段无值 { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -211,23 +219,25 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); } - + // demo中在3.0秒后调用autotrackPage,由于实际上已经过了viewDidAppear生命周期,所以sdk内部可判断发送PAGE事件,再次点击按钮,path有值 XCTestExpectation *expectation = [self expectationWithDescription:@"test02AutotrackPageDelay failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertGreaterThanOrEqual(events.count, 1); - + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); XCTAssertEqualObjects(event.pageName, @"页面测试"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); @@ -235,9 +245,9 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } - + [[viewTester usingLabel:@"Button"] tap]; - + { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 3); @@ -250,7 +260,9 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -266,21 +278,21 @@ - (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; - + // 不点击按钮,走autotrackPage内部的补page逻辑 - + // demo中在3.0秒后调用autotrackPage,由于实际上已经过了viewDidAppear生命周期,所以sdk内部可判断发送PAGE事件,再次点击按钮,path有值 XCTestExpectation *expectation = [self expectationWithDescription:@"test02AutotrackPageDelay failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertGreaterThanOrEqual(events.count, 1); - + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); XCTAssertEqualObjects(event.pageName, @"页面测试"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); @@ -288,9 +300,9 @@ - (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } - + [[viewTester usingLabel:@"Button"] tap]; - + { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 3); @@ -303,7 +315,9 @@ - (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects(dic[@"path"], @"页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index 5ec335940..e1e64096b 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -17,150 +17,224 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import -#import - -#import "GrowingAutotracker.h" -#import "GrowingAutotrackConfiguration.h" -#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" +#import "GrowingModuleManager.h" #import "GrowingTrackerCore/DeepLink/GrowingDeepLinkHandler.h" -#import "GrowingTrackerCore/Event/GrowingNodeProtocol.h" +#import "GrowingTrackerCore/Helpers/GrowingHelpers.h" +#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "Modules/WebCircle/GrowingWebCircle.h" -#import "GrowingAutotrackerCore/Page/GrowingPageManager.h" -#import "GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.h" -#import "Modules/WebCircle/GrowingWebCircleElement.h" +#import "Services/WebSocket/GrowingSRWebSocket.h" -@interface GrowingWebCircle (XCTest) +@interface MockWebSocket : NSObject -- (NSMutableDictionary *)dictFromPage:(GrowingPage *)page; +@property (nonatomic, strong) NSMutableArray *messages; -- (unsigned long)getSnapshotKey; ++ (instancetype)sharedInstance; -- (void)resetSnapshotKey; +@end -- (NSMutableArray *)elements; +@implementation MockWebSocket -- (void)sendScreenShot; ++ (instancetype)sharedInstance { + static id _sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _sharedInstance = [[self alloc] init]; + }); + return _sharedInstance; +} -- (void)remoteReady; +- (instancetype)init { + if (self = [super init]) { + self.messages = [NSMutableArray arrayWithCapacity:5]; + } + return self; +} -- (void)runWithCircle:(NSURL *)url readyBlock:(void (^)(void))readyBlock finishBlock:(void (^)(void))finishBlock; +- (void)cleanMessages { + [GrowingDispatchManager dispatchInGrowingThread:^{ + [self.messages removeAllObjects]; + }]; +} -- (void)start; +- (NSString *)lastMessage { + __block NSString *message = nil; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + message = self.messages.lastObject.copy; + } + waitUntilDone:YES]; + return message; +} -- (void)stop; +- (void)addMessage:(NSString *)message { + [GrowingDispatchManager dispatchInGrowingThread:^{ + [self.messages addObject:message]; + }]; +} -- (void)sendScreenShotWithCallback:(void (^)(NSString *))callback; +@end +@interface GrowingModuleManager (XCTest) -#pragma mark - GrowingDeepLinkHandlerProtocol +@property (nonatomic, strong) NSMutableArray *modules; -- (BOOL)growingHandlerUrl:(NSURL *)url; +@end + +@interface GrowingWebCircle (XCTest) + +- (void)stop; #pragma mark - Websocket Delegate -- (void)webSocketDidOpen:(id )webSocket; +- (void)webSocketDidOpen:(id)webSocket; + +- (void)webSocket:(id)webSocket didReceiveMessage:(id)message; + +- (void)webSocket:(id)webSocket + didCloseWithCode:(NSInteger)code + reason:(NSString *)reason + wasClean:(BOOL)wasClean; -- (void)webSocket:(id )webSocket didReceiveMessage:(id)message; +- (void)webSocket:(id)webSocket didFailWithError:(NSError *)error; @end -@interface GrowingPageManager (XCTest) +@implementation GrowingSRWebSocket (XCTest) -- (GrowingPage *)createdViewControllerPage:(UIViewController *)controller; +- (void)send:(id)data { + [MockWebSocket.sharedInstance addMessage:data]; +} + +- (void)setDelegate:(id)delegate { + // 在单测中,使用测试逻辑进行socket +} + +- (NSInteger)readyState { + return Growing_WS_OPEN; +} @end -@interface WebCircleTest : XCTestCase +@interface WebCircleTest : KIFTestCase @end +static __weak GrowingWebCircle *webCircle; + @implementation WebCircleTest + (void)setUp { - GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; - GrowingConfigurationManager.sharedInstance.trackConfiguration = config; + NSArray *modules = [GrowingModuleManager sharedInstance].modules.copy; + for (id module in modules) { + if ([module isKindOfClass:[GrowingWebCircle class]]) { + webCircle = (GrowingWebCircle *)module; + break; + } + } } - (void)setUp { - // Put setup code here. This method is called before the invocation of each test method in the class. + [[viewTester usingLabel:@"协议/接口"] tap]; + + // mock + NSURL *url = [NSURL URLWithString: + @"growing.bf30ad277eaae1aa://growingio/webservice?serviceType=circle&wsUrl" + @"=wss://portal.growingio.com/app/r85jV5gv/circle/faeb773a1d004663a86c227a159cc687"]; + [GrowingDeepLinkHandler handlerUrl:url]; + [webCircle webSocketDidOpen:nil]; + + [MockWebSocket.sharedInstance cleanMessages]; } - (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. + [webCircle stop]; + [[viewTester usingLabel:@"协议/接口"] tap]; } -- (void)testGrowingDeepLinkHandler { - NSURL *url1 = [NSURL URLWithString: @"http://test.growingio.com/oauth2/" - @"qrcode.html?URLScheme=growing.test&productId=test&circleRoomNumber=test0f4cfa51ff3f&serviceType=" - @"circle&appName=GrowingIO&wsUrl=ws://cdp.growingio.com/app/test/circle/test0f4cfa51ff3f"]; +- (void)test01SocketSend { + [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; + + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"testWebCircle Test failed : timeout"]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + NSString *message = MockWebSocket.sharedInstance.lastMessage; + NSMutableDictionary *dict = [[message growingHelper_jsonObject] mutableCopy]; - [GrowingDeepLinkHandler handlerUrl:url1]; + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:5.0f handler:nil]; } -- (void)testWebCircle { - GrowingWebCircle *circle = [[GrowingWebCircle alloc] init]; - - XCTAssertGreaterThan([circle getSnapshotKey], 0); - [circle resetSnapshotKey]; - XCTAssertEqual([circle getSnapshotKey], 1); +- (void)test02IncompatibleVersion { + [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"incompatible_version\"}"]; + [[viewTester usingLabel:@"知道了"] tap]; +} - UIViewController *current = [[UIViewController alloc] init]; - // 避免自动发 PAGE 报错 - GrowingPage *page = [current growingPageObject]; - if (!page) { - [[GrowingPageManager sharedInstance] createdViewControllerPage:current]; - page = [current growingPageObject]; - } - XCTAssertNotNil([circle dictFromPage:page]); - XCTAssertNotNil([circle elements]); - - [circle sendScreenShot]; - [circle remoteReady]; - [circle runWithCircle:[NSURL URLWithString:@"ws://testws"] readyBlock:nil finishBlock:nil]; - [circle start]; - [circle stop]; - [circle sendScreenShotWithCallback:nil]; - NSURL *urltest = [[NSURL alloc] initWithString:@"http://testxxx.growingio.com/" - @"qrcode.html?URLScheme=growing.XXX&productId=XXX&circleRoomNumber=" - @"8ebd86b3fac64b64ae09a9ce1450e015&serviceType=circle&appName=XXX"]; - [circle growingHandlerUrl:urltest]; - [circle webSocketDidOpen:nil]; - [circle webSocket:nil didReceiveMessage:@"{@\"msgType\":@\"ready\"}"]; - [circle webSocket:nil didReceiveMessage:@"{@\"msgType\":@\"incompatible_version\"}"]; -} - -- (void)testWebCircleElement { - GrowingWebCircleElementBuilder *builder = GrowingWebCircleElement.builder; - GrowingWebCircleElement *element = builder.setRect(CGRectMake(0, 0, 100, 100)) - .setZLevel(10) - .setContent(@"test") - .setXpath(@"Xpath") - .setXindex(@"xindex") - .setNodeType(@"Button") - .setParentXpath(@"parentXpath") - .setIsContainer(YES) - .setIndex(10) - .setPage(@"page") - .build; - NSDictionary *dic = [element toDictionary]; - CGFloat scale = MIN([UIScreen mainScreen].scale, 2); - XCTAssertNotNil(dic); - XCTAssertEqualObjects(dic[@"left"], @0); - XCTAssertEqualObjects(dic[@"top"], @0); - XCTAssertEqualObjects(dic[@"width"], @(100 * scale)); - XCTAssertEqualObjects(dic[@"height"], @(100 * scale)); - XCTAssertEqualObjects(dic[@"zLevel"], @10); - XCTAssertEqualObjects(dic[@"content"], @"test"); - XCTAssertEqualObjects(dic[@"xpath"], @"Xpath"); - XCTAssertEqualObjects(dic[@"xindex"], @"xindex"); - XCTAssertEqualObjects(dic[@"nodeType"], @"Button"); - XCTAssertEqualObjects(dic[@"isContainer"], @1); - XCTAssertEqualObjects(dic[@"index"], @10); - XCTAssertEqualObjects(dic[@"parentXPath"], @"parentXpath"); - XCTAssertEqualObjects(dic[@"page"], @"page"); - XCTAssertEqualObjects(dic[@"domain"], [GrowingDeviceInfo currentDeviceInfo].bundleID); +- (void)test03Quit { + [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; + [[viewTester usingLabel:@"协议/接口"] tap]; + [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"quit\"}"]; + [[viewTester usingLabel:@"知道了"] tap]; +} + +- (void)test04SocketReopen { + NSURL *url = [NSURL URLWithString: + @"growing.bf30ad277eaae1aa://growingio/webservice?serviceType=circle&wsUrl=wss://" + @"portal.growingio.com/app/r85jV5gv/circle/faeb773a1d004663a86c227a159cc687"]; + [GrowingDeepLinkHandler handlerUrl:url]; + [webCircle webSocketDidOpen:nil]; + [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; +} +// +//- (void)test05SocketOpenTimeOut { +// XCTestExpectation *expectation = [self expectationWithDescription:@""]; +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(11.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ +// [[viewTester usingLabel:@"知道了"] tap]; +// [viewTester waitForAnimationsToFinish]; +// [expectation fulfill]; +// }); +// +// [self waitForExpectationsWithTimeout:15.0f handler:nil]; +//} + +- (void)test06StatusTap { + [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; + [[viewTester usingLabel:@"正在进行GrowingIO移动端圈选"] tap]; + [[viewTester usingLabel:@"继续圈选"] tap]; + [[viewTester usingLabel:@"正在进行GrowingIO移动端圈选"] tap]; + [[viewTester usingLabel:@"退出圈选"] tap]; +} + +- (void)test07Hybrid { + // 由于hybrid中getDomTree是个同步方法,KIF + // tap方法内部也有一个同步的runLoop逻辑,这2者同时进行会卡死,所以在这里先tap, + // 再执行webSocket:didReceiveMessage:以触发getDomTree + [[viewTester usingLabel:@"UI界面"] tap]; + [[viewTester usingLabel:@"Hybrid"] tap]; + + [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; + // 尝试通过tapPoint点击到html中的button + [viewTester tapScreenAtPoint:CGPointMake(100, 200)]; + [[viewTester usingLabel:@"UI界面"] tap]; +} + +- (void)test08SocketDidCloseWithCode { + [webCircle webSocket:nil didCloseWithCode:GrowingWebSocketStatusCodeGoingAway reason:nil wasClean:YES]; + [[viewTester usingLabel:@"知道了"] tap]; +} + +- (void)test09SocketDidFail { + [webCircle webSocket:nil didFailWithError:nil]; + [[viewTester usingLabel:@"知道了"] tap]; +} + +- (BOOL)webCircleSocketParamsCheck:(NSDictionary *)dic { + return YES; } @end diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 7d33b1b0c..d1b398000 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -69,8 +69,6 @@ @interface GrowingWebCircle () )webSocket didReceiveMessage:(id)message { - if ([message isKindOfClass:[NSString class]] || ((NSString *)message).length > 0) { + if ([message isKindOfClass:[NSString class]] && ((NSString *)message).length > 0) { GIOLogDebug(@"[GrowingWebCircle] didReceiveMessage: %@", message); NSMutableDictionary *dict = [[message growingHelper_jsonObject] mutableCopy]; From 191528d83b6ee70cc53d86057b5990e8b60cf843 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 24 Jul 2023 16:51:20 +0800 Subject: [PATCH 044/126] test: update ci --- .../WebCircleTests/WebCircleTest.m | 83 +++++++++++++--- Modules/WebCircle/GrowingWebCircle.m | 99 ++++--------------- .../WebCircle/GrowingWebCircleStatusView.h | 37 +++++++ .../WebCircle/GrowingWebCircleStatusView.m | 95 ++++++++++++++++++ 4 files changed, 216 insertions(+), 98 deletions(-) create mode 100644 Modules/WebCircle/GrowingWebCircleStatusView.h create mode 100644 Modules/WebCircle/GrowingWebCircleStatusView.m diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index e1e64096b..0db1c3afe 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -159,11 +159,11 @@ - (void)test01SocketSend { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; - XCTestExpectation *expectation = [self expectationWithDescription:@"testWebCircle Test failed : timeout"]; + XCTestExpectation *expectation = [self expectationWithDescription:@"WebCircle Test failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSString *message = MockWebSocket.sharedInstance.lastMessage; - NSMutableDictionary *dict = [[message growingHelper_jsonObject] mutableCopy]; - + NSMutableDictionary *dic = [[message growingHelper_jsonObject] mutableCopy]; + [self webCircleSocketParamsCheck:dic]; [expectation fulfill]; }); @@ -190,17 +190,16 @@ - (void)test04SocketReopen { [webCircle webSocketDidOpen:nil]; [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; } -// -//- (void)test05SocketOpenTimeOut { -// XCTestExpectation *expectation = [self expectationWithDescription:@""]; -// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(11.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ -// [[viewTester usingLabel:@"知道了"] tap]; -// [viewTester waitForAnimationsToFinish]; -// [expectation fulfill]; -// }); -// -// [self waitForExpectationsWithTimeout:15.0f handler:nil]; -//} + +- (void)test05SocketOpenTimeOut { + XCTestExpectation *expectation = [self expectationWithDescription:@""]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(11.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[viewTester usingLabel:@"知道了"] tap]; + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:15.0f handler:nil]; +} - (void)test06StatusTap { [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; @@ -220,6 +219,27 @@ - (void)test07Hybrid { [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; // 尝试通过tapPoint点击到html中的button [viewTester tapScreenAtPoint:CGPointMake(100, 200)]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"WebCircle Test failed : timeout"]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + NSString *message = MockWebSocket.sharedInstance.lastMessage; + NSMutableDictionary *dic = [[message growingHelper_jsonObject] mutableCopy]; + [self webCircleSocketParamsCheck:dic]; + + // webView圈选数据 + NSArray *elements = dic[@"elements"]; + XCTAssertNotNil(elements); + for (NSDictionary *element in elements) { + if ([element[@"nodeType"] isEqualToString:@"WEB_VIEW"]) { + XCTAssertNotNil(element[@"webView"]); + } + } + + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:5.0f handler:nil]; + [[viewTester usingLabel:@"UI界面"] tap]; } @@ -233,8 +253,39 @@ - (void)test09SocketDidFail { [[viewTester usingLabel:@"知道了"] tap]; } -- (BOOL)webCircleSocketParamsCheck:(NSDictionary *)dic { - return YES; +- (void)webCircleSocketParamsCheck:(NSDictionary *)dic { + XCTAssertEqualObjects(dic[@"msgType"], @"refreshScreenshot"); + XCTAssertNotNil(dic[@"screenWidth"]); + XCTAssertNotNil(dic[@"screenHeight"]); + XCTAssertNotNil(dic[@"snapshotKey"]); + XCTAssertNotNil(dic[@"scale"]); + XCTAssertNotNil(dic[@"screenshot"]); + + NSArray *elements = dic[@"elements"]; + XCTAssertNotNil(elements); + for (NSDictionary *element in elements) { + XCTAssertNotNil(element[@"left"]); + XCTAssertNotNil(element[@"top"]); + XCTAssertNotNil(element[@"width"]); + XCTAssertNotNil(element[@"height"]); + XCTAssertNotNil(element[@"nodeType"]); + XCTAssertNotNil(element[@"domain"]); + XCTAssertNotNil(element[@"zLevel"]); + XCTAssertNotNil(element[@"xpath"]); + XCTAssertNotNil(element[@"xindex"]); + XCTAssertNotNil(element[@"page"]); + XCTAssertNotNil(element[@"isContainer"]); + } + + NSArray *pages = dic[@"pages"]; + XCTAssertNotNil(pages); + for (NSDictionary *page in pages) { + XCTAssertNotNil(page[@"path"]); + XCTAssertNotNil(page[@"top"]); + XCTAssertNotNil(page[@"width"]); + XCTAssertNotNil(page[@"left"]); + XCTAssertNotNil(page[@"height"]); + } } @end diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index d1b398000..80fc74c03 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -33,7 +33,6 @@ #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" #import "GrowingTrackerCore/Menu/GrowingAlert.h" -#import "GrowingTrackerCore/Menu/GrowingStatusBar.h" #import "GrowingTrackerCore/Network/Request/GrowingNetworkConfig.h" #import "GrowingTrackerCore/Public/GrowingFlutterService.h" #import "GrowingTrackerCore/Public/GrowingScreenshotService.h" @@ -43,6 +42,7 @@ #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" #import "Modules/WebCircle/GrowingWebCircleElement.h" +#import "Modules/WebCircle/GrowingWebCircleStatusView.h" #import #import "Modules/Hybrid/GrowingHybridBridgeProvider.h" @@ -59,10 +59,7 @@ @interface GrowingWebCircle () *cachedEvents; @@ -101,7 +98,7 @@ - (BOOL)growingHandlerUrl:(NSURL *)url { NSString *serviceType = params[@"serviceType"]; NSString *wsurl = params[@"wsUrl"]; if (serviceType.length > 0 && [serviceType isEqualToString:@"circle"] && wsurl.length > 0) { - [self runWithCircle:[NSURL URLWithString:wsurl] readyBlock:nil finishBlock:nil]; + [self runWithCircle:[NSURL URLWithString:wsurl]]; return YES; } return NO; @@ -110,7 +107,9 @@ - (BOOL)growingHandlerUrl:(NSURL *)url { #pragma mark - actions - (void)_setNeedUpdateScreen { - [self sendScreenShot]; + if (self.isReady) { + [self sendScreenShot]; + } } #pragma mark - screenShot @@ -176,13 +175,6 @@ - (void)resetSnapshotKey { _snapNumber = 0; } -- (NSMutableArray *)elements { - if (!_elements) { - _elements = [NSMutableArray array]; - } - return _elements; -} - - (void)traverseViewNode:(GrowingViewNode *)viewNode { UIView *node = viewNode.view; if ([node growingNodeDonotCircle]) { @@ -292,10 +284,6 @@ - (void)fillAllViewsForWebCircle:(NSDictionary *)dataDict completion:(void (^)(N } - (NSDictionary *)dictForUserAction:(NSString *)action { - if (action.length == 0) { - return nil; - } - UIImage *image = [self.screenshotProvider screenShot]; NSData *data = [image growingHelper_JPEG:0.8]; @@ -327,22 +315,11 @@ - (NSDictionary *)dictForUserAction:(NSString *)action { } - (void)sendScreenShot { - if (self.isReady) { - [self sendScreenShotWithCallback:nil]; - } -} - -- (void)sendScreenShotWithCallback:(void (^)(NSString *))callback // in case of error, the - // callback parameter is nil -{ // eventType已经忽略 NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSString *userAction = @"refreshScreenshot"; [dict addEntriesFromDictionary:[self dictForUserAction:userAction]]; if (dict.count == 0) { - if (callback != nil) { - callback(nil); - } return; } @@ -353,18 +330,10 @@ - (void)sendScreenShotWithCallback:(void (^)(NSString *))callback // in case of if (sself != nil && dict) { [sself sendJson:dict]; } - if (callback != nil) { - NSString *dictString = [dict growingHelper_jsonString]; - callback(dictString); // dictString == nil for error - } }]; } -- (void)remoteReady { - [self sendScreenShot]; -} - -- (void)runWithCircle:(NSURL *)url readyBlock:(void (^)(void))readyBlock finishBlock:(void (^)(void))finishBlock { +- (void)runWithCircle:(NSURL *)url { if (self.webSocket) { [self.webSocket close]; self.webSocket.delegate = nil; @@ -375,9 +344,7 @@ - (void)runWithCircle:(NSURL *)url readyBlock:(void (^)(void))readyBlock finishB Class serviceClass = [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingWebSocketService)]; if (!serviceClass) { - GIOLogError( - @"[GrowingWebCircle] -runWithCircle:readyBlock:finishBlock: web circle error : no websocket service " - @"support"); + GIOLogError(@"[GrowingWebCircle] -runWithCircle: web circle error : no websocket service support"); return; } @@ -402,25 +369,12 @@ - (void)runWithCircle:(NSURL *)url readyBlock:(void (^)(void))readyBlock finishB [self.webSocket open]; } - if (!self.statusWindow) { - self.statusWindow = [[GrowingStatusBar alloc] initWithFrame:[UIScreen mainScreen].bounds]; - self.statusWindow.hidden = NO; - self.statusWindow.statusLable.text = @"正在等待web链接"; - self.statusWindow.statusLable.textAlignment = NSTextAlignmentCenter; + if (!self.statusView) { + self.statusView = [[GrowingWebCircleStatusView alloc] initWithFrame:[UIScreen mainScreen].bounds]; + self.statusView.status = GrowingWebCircleStatusWaitConnect; __weak typeof(self) wself = self; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - if (wself && [wself.statusWindow.statusLable.text isEqualToString:@"正在等待web链接"]) { - GrowingAlert *alert = [GrowingAlert createAlertWithStyle:UIAlertControllerStyleAlert - title:@"提示" - message: - @"电脑端连接超时,请刷新电脑页面," - @"再次尝试扫码圈选。"]; - [alert addOkWithTitle:@"知道了" handler:nil]; - [alert showAlertAnimated:NO]; - } - }); - self.statusWindow.onButtonClick = ^{ + self.statusView.onButtonClick = ^{ NSString *content = [NSString stringWithFormat:@"APP版本: %@\nSDK版本: %@", [GrowingDeviceInfo currentDeviceInfo].appFullVersion, GrowingTrackerVersionName]; @@ -436,9 +390,6 @@ - (void)runWithCircle:(NSURL *)url readyBlock:(void (^)(void))readyBlock finishB [alert showAlertAnimated:NO]; }; } - - self.onReadyBlock = readyBlock; - self.onFinishBlock = finishBlock; } } @@ -457,15 +408,10 @@ - (void)handleWindowDidResignKey:(NSNotification *)notification { } - (void)start { - self.statusWindow.statusLable.text = @"正在进行GrowingIO移动端圈选"; - self.statusWindow.statusLable.textAlignment = NSTextAlignmentCenter; - if (self.onReadyBlock) { - self.onReadyBlock(); - self.onReadyBlock = nil; - } + self.statusView.status = GrowingWebCircleStatusOpening; [self resetSnapshotKey]; self.isReady = YES; - [self remoteReady]; + [self sendScreenShot]; // Hybrid的布局改变回调代理设置 [GrowingHybridBridgeProvider sharedInstance].domChangedDelegate = self; // 监听原生事件,变动时发送 @@ -477,8 +423,7 @@ - (void)stop { GIOLogDebug(@"[GrowingWebCircle] 开始断开连接"); NSDictionary *dict = @{@"msgType": @"quit"}; [self sendJson:dict]; - self.statusWindow.statusLable.text = @"正在关闭web圈选..."; - self.statusWindow.statusLable.textAlignment = NSTextAlignmentCenter; + self.statusView.status = GrowingWebCircleStatusClosing; self.isReady = NO; [self _stopWithError:nil]; } @@ -499,17 +444,7 @@ - (void)_stopWithError:(NSString *)error { [self.webSocket close]; self.webSocket = nil; } - if (self.onFinishBlock) { - self.onFinishBlock(); - self.onFinishBlock = nil; - } - if (self.onReadyBlock) { - self.onReadyBlock = nil; - } - if (self.statusWindow) { - self.statusWindow.hidden = YES; - self.statusWindow = nil; - } + self.statusView = nil; if (error.length) { GrowingAlert *alert = [GrowingAlert createAlertWithStyle:UIAlertControllerStyleAlert title:@"设备已断开连接" @@ -636,7 +571,7 @@ - (void)sendWebcircleWithType:(NSString *)eventType { usingBlock:^(__kindof NSString *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) { if ([obj isEqualToString:GrowingEventTypeViewClick] || [obj isEqualToString:GrowingEventTypePage]) { - [self sendScreenShotWithCallback:nil]; + [self sendScreenShot]; *stop = YES; } }]; diff --git a/Modules/WebCircle/GrowingWebCircleStatusView.h b/Modules/WebCircle/GrowingWebCircleStatusView.h new file mode 100644 index 000000000..a8ab4e56b --- /dev/null +++ b/Modules/WebCircle/GrowingWebCircleStatusView.h @@ -0,0 +1,37 @@ +// +// GrowingWebCircleStatusView.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/24. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import +#import "GrowingTrackerCore/Menu/GrowingStatusBar.h" + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, GrowingWebCircleStatus) { + GrowingWebCircleStatusWaitConnect, + GrowingWebCircleStatusOpening, + GrowingWebCircleStatusClosing +}; + +@interface GrowingWebCircleStatusView : GrowingStatusBar + +@property (nonatomic, assign) GrowingWebCircleStatus status; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Modules/WebCircle/GrowingWebCircleStatusView.m b/Modules/WebCircle/GrowingWebCircleStatusView.m new file mode 100644 index 000000000..eae38aa98 --- /dev/null +++ b/Modules/WebCircle/GrowingWebCircleStatusView.m @@ -0,0 +1,95 @@ +// +// GrowingWebCircleStatusView.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/7/24. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "Modules/WebCircle/GrowingWebCircleStatusView.h" +#import "GrowingTrackerCore/Menu/GrowingAlert.h" + +@interface GrowingWebCircleStatusView () + +@property (nonatomic, strong) NSTimer *timer; + +@end + +@implementation GrowingWebCircleStatusView + +- (instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + self.statusLable.textAlignment = NSTextAlignmentCenter; + } + return self; +} + +- (void)dealloc { + [self stopTimer]; +} + +- (void)setStatus:(GrowingWebCircleStatus)status { + _status = status; + switch (status) { + case GrowingWebCircleStatusWaitConnect: { + self.statusLable.text = @"正在等待web链接"; + self.hidden = NO; + [self startTimer]; + } break; + case GrowingWebCircleStatusOpening: { + self.statusLable.text = @"正在进行GrowingIO移动端圈选"; + } break; + case GrowingWebCircleStatusClosing: { + self.statusLable.text = @"正在关闭web圈选..."; + self.hidden = YES; + [self stopTimer]; + } break; + default: + break; + } +} + +- (void)startTimer { + if (!self.timer) { + self.timer = [NSTimer timerWithTimeInterval:10.0f + target:self + selector:@selector(checkStatusIfOpen) + userInfo:nil + repeats:NO]; + [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; + } +} + +- (void)stopTimer { + if (self.timer) { + [self.timer invalidate]; + self.timer = nil; + } +} + +- (void)checkStatusIfOpen { + if (self.status != GrowingWebCircleStatusWaitConnect) { + return; + } + + GrowingAlert *alert = [GrowingAlert createAlertWithStyle:UIAlertControllerStyleAlert + title:@"提示" + message: + @"电脑端连接超时,请刷新电脑页面," + @"再次尝试扫码圈选。"]; + [alert addOkWithTitle:@"知道了" handler:nil]; + [alert showAlertAnimated:NO]; +} + +@end From 43c42e93987004630cff08f5716771b948665af3 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 28 Jul 2023 17:47:50 +0800 Subject: [PATCH 045/126] fix: bug --- Podfile.lock | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 8b54ab8f2..fb92b35df 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -68,16 +68,16 @@ PODS: - GrowingAPM/Core - GrowingAPM/UIMonitor (0.0.14): - GrowingAPM/Core - - GrowingToolsKit (1.1.3): - - GrowingToolsKit/Default (= 1.1.3) - - GrowingToolsKit/APMCore (1.1.3): + - GrowingToolsKit (1.2.0): + - GrowingToolsKit/Default (= 1.2.0) + - GrowingToolsKit/APMCore (1.2.0): - GrowingAPM/Core - GrowingToolsKit/Core - - GrowingToolsKit/Core (1.1.3) - - GrowingToolsKit/CrashMonitor (1.1.3): + - GrowingToolsKit/Core (1.2.0) + - GrowingToolsKit/CrashMonitor (1.2.0): - GrowingAPM/CrashMonitor - GrowingToolsKit/APMCore - - GrowingToolsKit/Default (1.1.3): + - GrowingToolsKit/Default (1.2.0): - GrowingToolsKit/Core - GrowingToolsKit/CrashMonitor - GrowingToolsKit/EventsList @@ -87,20 +87,20 @@ PODS: - GrowingToolsKit/SDKInfo - GrowingToolsKit/Settings - GrowingToolsKit/XPathTrack - - GrowingToolsKit/EventsList (1.1.3): + - GrowingToolsKit/EventsList (1.2.0): - GrowingToolsKit/Core - - GrowingToolsKit/LaunchTime (1.1.3): + - GrowingToolsKit/LaunchTime (1.2.0): - GrowingAPM/UIMonitor - GrowingToolsKit/APMCore - - GrowingToolsKit/NetFlow (1.1.3): + - GrowingToolsKit/NetFlow (1.2.0): - GrowingToolsKit/Core - - GrowingToolsKit/Realtime (1.1.3): + - GrowingToolsKit/Realtime (1.2.0): - GrowingToolsKit/Core - - GrowingToolsKit/SDKInfo (1.1.3): + - GrowingToolsKit/SDKInfo (1.2.0): - GrowingToolsKit/Core - - GrowingToolsKit/Settings (1.1.3): + - GrowingToolsKit/Settings (1.2.0): - GrowingToolsKit/Core - - GrowingToolsKit/XPathTrack (1.1.3): + - GrowingToolsKit/XPathTrack (1.2.0): - GrowingToolsKit/Core - GrowingUtils/AutotrackerCore (0.0.5): - GrowingUtils/TrackerCore @@ -113,12 +113,12 @@ PODS: - LBXScan/Types (2.3) - LBXScan/UI (2.3): - LBXScan/Types (~> 2.2) - - Protobuf (3.23.3) + - Protobuf (3.23.4) - SDCycleScrollView (1.82): - SDWebImage (>= 5.0.0) - - SDWebImage (5.16.0): - - SDWebImage/Core (= 5.16.0) - - SDWebImage/Core (5.16.0) + - SDWebImage (5.17.0): + - SDWebImage/Core (= 5.17.0) + - SDWebImage/Core (5.17.0) DEPENDENCIES: - GrowingAnalytics/Advert (from `./`) @@ -152,13 +152,13 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: GrowingAnalytics: a01857dc934fa4b0b0b4a04b46d888d2472d5fa2 GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a - GrowingToolsKit: 88b144e858f8895f1d84c518642ce34ce0f5aa07 + GrowingToolsKit: 9c0d6e41c9678397dbaa3304b1738a2867b023ae GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 KIF: 7660c626b0f2d4562533590960db70a36d640558 LBXScan: e51449f0832d1fe17da632af0d22adeb3cfa3543 - Protobuf: d9c3d7e5a3574aa6a5d521f2d9f733c76d294be8 + Protobuf: c6bc59bbab3d38a71c67f62d7cb7ca8f8ea4eca1 SDCycleScrollView: a0d74c3384caa72bdfc81470bdbc8c14b3e1fbcf - SDWebImage: 2aea163b50bfcb569a2726b6a754c54a4506fcf6 + SDWebImage: 750adf017a315a280c60fde706ab1e552a3ae4e9 PODFILE CHECKSUM: d18ae04aaea2c73be8383f04c6feea89caed3e99 From 822afce089e304925e231577f2dc1f06b30d9793 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 31 Jul 2023 15:40:47 +0800 Subject: [PATCH 046/126] =?UTF-8?q?feat:=20protobuf=20=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=20xcontent=E3=80=81xindex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GrowingAnalytics.podspec | 2 +- .../Catagory/GrowingBaseEvent+Protobuf.m | 2 + .../GrowingPBEventV3Dto+GrowingHelper.m | 6 + Modules/Protobuf/Proto/GrowingEvent.pbobjc.h | 160 ++++++++-------- Modules/Protobuf/Proto/GrowingEvent.pbobjc.m | 179 ++++++++++-------- Modules/Protobuf/Proto/event_v3.proto | 57 +++--- Modules/SwiftProtobuf/SwiftProtobuf.swift | 42 +++- Modules/SwiftProtobuf/event_v3.pb.swift | 141 ++++++-------- Podfile.lock | 4 +- 9 files changed, 306 insertions(+), 287 deletions(-) diff --git a/GrowingAnalytics.podspec b/GrowingAnalytics.podspec index 3222f9757..faed2fc77 100644 --- a/GrowingAnalytics.podspec +++ b/GrowingAnalytics.podspec @@ -157,7 +157,7 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 proto.source_files = 'Modules/Protobuf/Proto/**/*{.h,.m,.c,.cpp,.mm}' proto.public_header_files = 'Modules/Protobuf/Proto/include/*.h' proto.requires_arc = false - proto.dependency 'Protobuf' + proto.dependency 'Protobuf', '>= 3.22.0' end end diff --git a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index a2237b1d7..355d404d6 100644 --- a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -87,6 +87,8 @@ - (GrowingPBEventV3Dto *)toProtobuf { dto.path = stringBlock(@"pageName").length > 0 ? stringBlock(@"pageName") : stringBlock(@"path"); dto.textValue = stringBlock(@"textValue"); dto.xpath = stringBlock(@"xpath"); + dto.xcontent = stringBlock(@"xcontent"); + dto.xindex = stringBlock(@"xindex"); dto.index = int32Block(@"index"); dto.query = stringBlock(@"query"); dto.hyperlink = stringBlock(@"hyperlink"); diff --git a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index aa88ca9ca..279f1f191 100644 --- a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -129,6 +129,12 @@ - (id)growingHelper_jsonObject { if (self.xpath.length > 0) { [dic setObject:self.xpath forKey:@"xpath"]; } + if (self.xcontent.length > 0) { + [dic setObject:self.xcontent forKey:@"xcontent"]; + } + if (self.xindex.length > 0) { + [dic setObject:self.xindex forKey:@"xindex"]; + } if (self.index > 0) { [dic setObject:@(self.index) forKey:@"index"]; } diff --git a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h index 99d92b42a..7f61a44da 100644 --- a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h +++ b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// clang-format off // source: event_v3.proto // This CPP symbol can be defined to use imports that match up to the framework @@ -13,10 +14,10 @@ #import "GPBProtocolBuffers.h" #endif -#if GOOGLE_PROTOBUF_OBJC_VERSION < 30004 +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. #endif -#if 30004 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION #error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. #endif @@ -131,137 +132,122 @@ typedef GPB_ENUM(GrowingPBEventV3Dto_FieldNumber) { GrowingPBEventV3Dto_FieldNumber_ProjectKey = 53, GrowingPBEventV3Dto_FieldNumber_SendTime = 54, GrowingPBEventV3Dto_FieldNumber_UserKey = 55, + GrowingPBEventV3Dto_FieldNumber_Xcontent = 56, + GrowingPBEventV3Dto_FieldNumber_Xindex = 57, }; GPB_FINAL @interface GrowingPBEventV3Dto : GPBMessage -@property (nonatomic, readwrite, copy, null_resettable) NSString *deviceId; +@property(nonatomic, readwrite, copy, null_resettable) NSString *deviceId; -@property (nonatomic, readwrite, copy, null_resettable) NSString *userId; +@property(nonatomic, readwrite, copy, null_resettable) NSString *userId; -@property (nonatomic, readwrite, copy, null_resettable) NSString *sessionId; +@property(nonatomic, readwrite, copy, null_resettable) NSString *sessionId; -@property (nonatomic, readwrite, copy, null_resettable) NSString *dataSourceId; +@property(nonatomic, readwrite, copy, null_resettable) NSString *dataSourceId; -@property (nonatomic, readwrite) GrowingPBEventType eventType; +@property(nonatomic, readwrite) GrowingPBEventType eventType; -@property (nonatomic, readwrite, copy, null_resettable) NSString *platform; +@property(nonatomic, readwrite, copy, null_resettable) NSString *platform; -@property (nonatomic, readwrite) int64_t timestamp; +@property(nonatomic, readwrite) int64_t timestamp; -@property (nonatomic, readwrite, copy, null_resettable) NSString *domain; +@property(nonatomic, readwrite, copy, null_resettable) NSString *domain; -/** PageEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *path; +@property(nonatomic, readwrite, copy, null_resettable) NSString *path; -/** HybridCustomEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *query; +@property(nonatomic, readwrite, copy, null_resettable) NSString *query; -/** PageEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *title; +@property(nonatomic, readwrite, copy, null_resettable) NSString *title; -/** PageEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *referralPage; +@property(nonatomic, readwrite, copy, null_resettable) NSString *referralPage; -@property (nonatomic, readwrite) int32_t eventSequenceId; +@property(nonatomic, readwrite) int32_t eventSequenceId; -@property (nonatomic, readwrite) int32_t screenHeight; +@property(nonatomic, readwrite) int32_t screenHeight; -@property (nonatomic, readwrite) int32_t screenWidth; +@property(nonatomic, readwrite) int32_t screenWidth; -@property (nonatomic, readwrite, copy, null_resettable) NSString *language; +@property(nonatomic, readwrite, copy, null_resettable) NSString *language; -@property (nonatomic, readwrite, copy, null_resettable) NSString *sdkVersion; +@property(nonatomic, readwrite, copy, null_resettable) NSString *sdkVersion; -@property (nonatomic, readwrite, copy, null_resettable) NSString *appVersion; +@property(nonatomic, readwrite, copy, null_resettable) NSString *appVersion; -/** VisitEvent */ -@property (nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *extraSdk; -/** The number of items in @c extraSdk without causing the array to be created. */ -@property (nonatomic, readonly) NSUInteger extraSdk_Count; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *extraSdk; +/** The number of items in @c extraSdk without causing the container to be created. */ +@property(nonatomic, readonly) NSUInteger extraSdk_Count; -/** customEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *eventName; +@property(nonatomic, readwrite, copy, null_resettable) NSString *eventName; -/** BaseAttributesEvent */ -@property (nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *attributes; -/** The number of items in @c attributes without causing the array to be created. */ -@property (nonatomic, readonly) NSUInteger attributes_Count; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *attributes; +/** The number of items in @c attributes without causing the container to be created. */ +@property(nonatomic, readonly) NSUInteger attributes_Count; -/** ResourceItemCustomEvent */ -@property (nonatomic, readwrite, strong, null_resettable) GrowingPBResourceItem *resourceItem; +@property(nonatomic, readwrite, strong, null_resettable) GrowingPBResourceItem *resourceItem; /** Test to see if @c resourceItem has been set. */ -@property (nonatomic, readwrite) BOOL hasResourceItem; +@property(nonatomic, readwrite) BOOL hasResourceItem; -/** HybridPageEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *protocolType; +@property(nonatomic, readwrite, copy, null_resettable) NSString *protocolType; -/** ViewElementEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *textValue; +@property(nonatomic, readwrite, copy, null_resettable) NSString *textValue; -/** ViewElementEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *xpath; +@property(nonatomic, readwrite, copy, null_resettable) NSString *xpath; -/** ViewElementEvent */ -@property (nonatomic, readwrite) int32_t index; +@property(nonatomic, readwrite) int32_t index; -/** HybridViewElementEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *hyperlink; +@property(nonatomic, readwrite, copy, null_resettable) NSString *hyperlink; -@property (nonatomic, readwrite, copy, null_resettable) NSString *URLScheme; +@property(nonatomic, readwrite, copy, null_resettable) NSString *URLScheme; -@property (nonatomic, readwrite, copy, null_resettable) NSString *appState; +@property(nonatomic, readwrite, copy, null_resettable) NSString *appState; -@property (nonatomic, readwrite, copy, null_resettable) NSString *networkState; +@property(nonatomic, readwrite, copy, null_resettable) NSString *networkState; -@property (nonatomic, readwrite, copy, null_resettable) NSString *appChannel; +@property(nonatomic, readwrite, copy, null_resettable) NSString *appChannel; /** useless */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *pageName; +@property(nonatomic, readwrite, copy, null_resettable) NSString *pageName; -@property (nonatomic, readwrite, copy, null_resettable) NSString *platformVersion; +@property(nonatomic, readwrite, copy, null_resettable) NSString *platformVersion; -@property (nonatomic, readwrite, copy, null_resettable) NSString *deviceBrand; +@property(nonatomic, readwrite, copy, null_resettable) NSString *deviceBrand; -@property (nonatomic, readwrite, copy, null_resettable) NSString *deviceModel; +@property(nonatomic, readwrite, copy, null_resettable) NSString *deviceModel; -@property (nonatomic, readwrite, copy, null_resettable) NSString *deviceType; +@property(nonatomic, readwrite, copy, null_resettable) NSString *deviceType; -/** refer platformVersion */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *operatingSystem; +@property(nonatomic, readwrite, copy, null_resettable) NSString *operatingSystem; -@property (nonatomic, readwrite, copy, null_resettable) NSString *appName; +@property(nonatomic, readwrite, copy, null_resettable) NSString *appName; -@property (nonatomic, readwrite) double latitude; +@property(nonatomic, readwrite) double latitude; -@property (nonatomic, readwrite) double longitude; +@property(nonatomic, readwrite) double longitude; -/** VISITEVENT */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *imei; +@property(nonatomic, readwrite, copy, null_resettable) NSString *imei; -/** VISITEVENT */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *androidId; +@property(nonatomic, readwrite, copy, null_resettable) NSString *androidId; -/** VISITEVENT */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *oaid; +@property(nonatomic, readwrite, copy, null_resettable) NSString *oaid; -/** VISITEVENT */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *googleAdvertisingId; +@property(nonatomic, readwrite, copy, null_resettable) NSString *googleAdvertisingId; -/** for ios */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *idfa; +@property(nonatomic, readwrite, copy, null_resettable) NSString *idfa; -/** for ios */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *idfv; +@property(nonatomic, readwrite, copy, null_resettable) NSString *idfv; -/** PageEvent */ -@property (nonatomic, readwrite, copy, null_resettable) NSString *orientation; +@property(nonatomic, readwrite, copy, null_resettable) NSString *orientation; -@property (nonatomic, readwrite, copy, null_resettable) NSString *projectKey; +@property(nonatomic, readwrite, copy, null_resettable) NSString *projectKey; -@property (nonatomic, readwrite) int64_t sendTime; +@property(nonatomic, readwrite) int64_t sendTime; -@property (nonatomic, readwrite, copy, null_resettable) NSString *userKey; +@property(nonatomic, readwrite, copy, null_resettable) NSString *userKey; + +@property(nonatomic, readwrite, copy, null_resettable) NSString *xcontent; + +@property(nonatomic, readwrite, copy, null_resettable) NSString *xindex; @end @@ -287,13 +273,13 @@ typedef GPB_ENUM(GrowingPBResourceItem_FieldNumber) { GPB_FINAL @interface GrowingPBResourceItem : GPBMessage -@property (nonatomic, readwrite, copy, null_resettable) NSString *id_p; +@property(nonatomic, readwrite, copy, null_resettable) NSString *id_p; -@property (nonatomic, readwrite, copy, null_resettable) NSString *key; +@property(nonatomic, readwrite, copy, null_resettable) NSString *key; -@property (nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *attributes; -/** The number of items in @c attributes without causing the array to be created. */ -@property (nonatomic, readonly) NSUInteger attributes_Count; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *attributes; +/** The number of items in @c attributes without causing the container to be created. */ +@property(nonatomic, readonly) NSUInteger attributes_Count; @end @@ -305,9 +291,9 @@ typedef GPB_ENUM(GrowingPBEventV3List_FieldNumber) { GPB_FINAL @interface GrowingPBEventV3List : GPBMessage -@property (nonatomic, readwrite, strong, null_resettable) NSMutableArray *valuesArray; -/** The number of items in @c valuesArray without causing the array to be created. */ -@property (nonatomic, readonly) NSUInteger valuesArray_Count; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *valuesArray; +/** The number of items in @c valuesArray without causing the container to be created. */ +@property(nonatomic, readonly) NSUInteger valuesArray_Count; @end @@ -318,3 +304,5 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) + +// clang-format on diff --git a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m index adddca017..066e45bfb 100644 --- a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m +++ b/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// clang-format off // source: event_v3.proto // This CPP symbol can be defined to use imports that match up to the framework @@ -13,6 +14,13 @@ #import "GPBProtocolBuffers_RuntimeSupport.h" #endif +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30007 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30007 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + #import #import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" @@ -22,11 +30,12 @@ #pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdollar-in-identifier-extension" -#pragma mark - Objective C Class declarations -// Forward declarations of Objective C classes that we can use as +#pragma mark - Objective-C Class declarations +// Forward declarations of Objective-C classes that we can use as // static values in struct initializers. // We don't use [Foo class] because it is not a static value. GPBObjCClassDeclaration(GrowingPBEventV3Dto); +GPBObjCClassDeclaration(GrowingPBEventV3List); GPBObjCClassDeclaration(GrowingPBResourceItem); #pragma mark - GrowingPBEventV3Root @@ -38,26 +47,18 @@ @implementation GrowingPBEventV3Root @end -#pragma mark - GrowingPBEventV3Root_FileDescriptor - -static GPBFileDescriptor *GrowingPBEventV3Root_FileDescriptor(void) { - // This is called by +initialize so there is no need to worry - // about thread safety of the singleton. - static GPBFileDescriptor *descriptor = NULL; - if (!descriptor) { - GPB_DEBUG_CHECK_RUNTIME_VERSIONS(); - descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"com.growingio.database" - objcPrefix:@"GrowingPB" - syntax:GPBFileSyntaxProto3]; - } - return descriptor; -} +static GPBFileDescription GrowingPBEventV3Root_FileDescription = { + .package = "io.growing.tunnel.protocol", + .prefix = "GrowingPB", + .syntax = GPBFileSyntaxProto3 +}; #pragma mark - Enum GrowingPBEventType GPBEnumDescriptor *GrowingPBEventType_EnumDescriptor(void) { static _Atomic(GPBEnumDescriptor*) descriptor = nil; if (!descriptor) { + GPB_DEBUG_CHECK_RUNTIME_VERSIONS(); static const char *valueNames = "Visit\000Custom\000VisitorAttributes\000LoginUser" "Attributes\000ConversionVariables\000AppClosed" @@ -82,7 +83,8 @@ @implementation GrowingPBEventV3Root valueNames:valueNames values:values count:(uint32_t)(sizeof(values) / sizeof(int32_t)) - enumVerifier:GrowingPBEventType_IsValidValue]; + enumVerifier:GrowingPBEventType_IsValidValue + flags:GPBEnumDescriptorInitializationFlag_None]; GPBEnumDescriptor *expected = nil; if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) { [worker release]; @@ -165,6 +167,8 @@ @implementation GrowingPBEventV3Dto @dynamic projectKey; @dynamic sendTime; @dynamic userKey; +@dynamic xcontent; +@dynamic xindex; typedef struct GrowingPBEventV3Dto__storage_ { uint32_t _has_storage_[2]; @@ -214,6 +218,8 @@ @implementation GrowingPBEventV3Dto NSString *orientation; NSString *projectKey; NSString *userKey; + NSString *xcontent; + NSString *xindex; int64_t timestamp; double latitude; double longitude; @@ -225,6 +231,7 @@ @implementation GrowingPBEventV3Dto + (GPBDescriptor *)descriptor { static GPBDescriptor *descriptor = nil; if (!descriptor) { + GPB_DEBUG_CHECK_RUNTIME_VERSIONS(); static GPBMessageFieldDescription fields[] = { { .name = "deviceId", @@ -248,7 +255,7 @@ + (GPBDescriptor *)descriptor { .name = "sessionId", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_SessionId, - .hasIndex = 3, + .hasIndex = 2, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, sessionId), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -257,7 +264,7 @@ + (GPBDescriptor *)descriptor { .name = "dataSourceId", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_DataSourceId, - .hasIndex = 4, + .hasIndex = 3, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, dataSourceId), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -266,7 +273,7 @@ + (GPBDescriptor *)descriptor { .name = "eventType", .dataTypeSpecific.enumDescFunc = GrowingPBEventType_EnumDescriptor, .number = GrowingPBEventV3Dto_FieldNumber_EventType, - .hasIndex = 5, + .hasIndex = 4, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, eventType), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeEnum, @@ -275,7 +282,7 @@ + (GPBDescriptor *)descriptor { .name = "platform", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Platform, - .hasIndex = 6, + .hasIndex = 5, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, platform), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -284,7 +291,7 @@ + (GPBDescriptor *)descriptor { .name = "timestamp", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Timestamp, - .hasIndex = 7, + .hasIndex = 6, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, timestamp), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeInt64, @@ -293,7 +300,7 @@ + (GPBDescriptor *)descriptor { .name = "domain", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Domain, - .hasIndex = 8, + .hasIndex = 7, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, domain), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -302,7 +309,7 @@ + (GPBDescriptor *)descriptor { .name = "path", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Path, - .hasIndex = 9, + .hasIndex = 8, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, path), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -311,7 +318,7 @@ + (GPBDescriptor *)descriptor { .name = "query", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Query, - .hasIndex = 10, + .hasIndex = 9, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, query), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -320,7 +327,7 @@ + (GPBDescriptor *)descriptor { .name = "title", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Title, - .hasIndex = 11, + .hasIndex = 10, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, title), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -329,7 +336,7 @@ + (GPBDescriptor *)descriptor { .name = "referralPage", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_ReferralPage, - .hasIndex = 12, + .hasIndex = 11, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, referralPage), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -338,7 +345,7 @@ + (GPBDescriptor *)descriptor { .name = "eventSequenceId", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_EventSequenceId, - .hasIndex = 14, + .hasIndex = 12, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, eventSequenceId), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeInt32, @@ -347,7 +354,7 @@ + (GPBDescriptor *)descriptor { .name = "screenHeight", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_ScreenHeight, - .hasIndex = 15, + .hasIndex = 13, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, screenHeight), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeInt32, @@ -356,7 +363,7 @@ + (GPBDescriptor *)descriptor { .name = "screenWidth", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_ScreenWidth, - .hasIndex = 16, + .hasIndex = 14, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, screenWidth), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeInt32, @@ -365,7 +372,7 @@ + (GPBDescriptor *)descriptor { .name = "language", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Language, - .hasIndex = 17, + .hasIndex = 15, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, language), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -374,7 +381,7 @@ + (GPBDescriptor *)descriptor { .name = "sdkVersion", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_SdkVersion, - .hasIndex = 18, + .hasIndex = 16, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, sdkVersion), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -383,7 +390,7 @@ + (GPBDescriptor *)descriptor { .name = "appVersion", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_AppVersion, - .hasIndex = 19, + .hasIndex = 17, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, appVersion), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -401,7 +408,7 @@ + (GPBDescriptor *)descriptor { .name = "eventName", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_EventName, - .hasIndex = 20, + .hasIndex = 18, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, eventName), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -419,7 +426,7 @@ + (GPBDescriptor *)descriptor { .name = "resourceItem", .dataTypeSpecific.clazz = GPBObjCClass(GrowingPBResourceItem), .number = GrowingPBEventV3Dto_FieldNumber_ResourceItem, - .hasIndex = 22, + .hasIndex = 19, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, resourceItem), .flags = GPBFieldOptional, .dataType = GPBDataTypeMessage, @@ -428,7 +435,7 @@ + (GPBDescriptor *)descriptor { .name = "protocolType", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_ProtocolType, - .hasIndex = 23, + .hasIndex = 20, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, protocolType), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -437,7 +444,7 @@ + (GPBDescriptor *)descriptor { .name = "textValue", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_TextValue, - .hasIndex = 24, + .hasIndex = 21, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, textValue), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -446,7 +453,7 @@ + (GPBDescriptor *)descriptor { .name = "xpath", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Xpath, - .hasIndex = 25, + .hasIndex = 22, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, xpath), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -455,7 +462,7 @@ + (GPBDescriptor *)descriptor { .name = "index", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Index, - .hasIndex = 26, + .hasIndex = 23, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, index), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeInt32, @@ -464,7 +471,7 @@ + (GPBDescriptor *)descriptor { .name = "hyperlink", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Hyperlink, - .hasIndex = 27, + .hasIndex = 24, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, hyperlink), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -473,7 +480,7 @@ + (GPBDescriptor *)descriptor { .name = "URLScheme", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_URLScheme, - .hasIndex = 28, + .hasIndex = 25, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, URLScheme), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -482,7 +489,7 @@ + (GPBDescriptor *)descriptor { .name = "appState", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_AppState, - .hasIndex = 29, + .hasIndex = 26, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, appState), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -491,7 +498,7 @@ + (GPBDescriptor *)descriptor { .name = "networkState", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_NetworkState, - .hasIndex = 30, + .hasIndex = 27, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, networkState), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -500,7 +507,7 @@ + (GPBDescriptor *)descriptor { .name = "appChannel", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_AppChannel, - .hasIndex = 31, + .hasIndex = 28, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, appChannel), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -509,7 +516,7 @@ + (GPBDescriptor *)descriptor { .name = "pageName", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_PageName, - .hasIndex = 32, + .hasIndex = 29, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, pageName), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -518,7 +525,7 @@ + (GPBDescriptor *)descriptor { .name = "platformVersion", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_PlatformVersion, - .hasIndex = 33, + .hasIndex = 30, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, platformVersion), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -527,7 +534,7 @@ + (GPBDescriptor *)descriptor { .name = "deviceBrand", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_DeviceBrand, - .hasIndex = 34, + .hasIndex = 31, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, deviceBrand), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -536,7 +543,7 @@ + (GPBDescriptor *)descriptor { .name = "deviceModel", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_DeviceModel, - .hasIndex = 35, + .hasIndex = 32, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, deviceModel), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -545,7 +552,7 @@ + (GPBDescriptor *)descriptor { .name = "deviceType", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_DeviceType, - .hasIndex = 36, + .hasIndex = 33, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, deviceType), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -554,7 +561,7 @@ + (GPBDescriptor *)descriptor { .name = "operatingSystem", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_OperatingSystem, - .hasIndex = 37, + .hasIndex = 34, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, operatingSystem), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -563,7 +570,7 @@ + (GPBDescriptor *)descriptor { .name = "appName", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_AppName, - .hasIndex = 38, + .hasIndex = 35, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, appName), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -572,7 +579,7 @@ + (GPBDescriptor *)descriptor { .name = "latitude", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Latitude, - .hasIndex = 39, + .hasIndex = 36, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, latitude), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeDouble, @@ -581,7 +588,7 @@ + (GPBDescriptor *)descriptor { .name = "longitude", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Longitude, - .hasIndex = 40, + .hasIndex = 37, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, longitude), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeDouble, @@ -590,7 +597,7 @@ + (GPBDescriptor *)descriptor { .name = "imei", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Imei, - .hasIndex = 41, + .hasIndex = 38, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, imei), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -599,7 +606,7 @@ + (GPBDescriptor *)descriptor { .name = "androidId", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_AndroidId, - .hasIndex = 42, + .hasIndex = 39, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, androidId), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -608,7 +615,7 @@ + (GPBDescriptor *)descriptor { .name = "oaid", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Oaid, - .hasIndex = 43, + .hasIndex = 40, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, oaid), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -617,7 +624,7 @@ + (GPBDescriptor *)descriptor { .name = "googleAdvertisingId", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_GoogleAdvertisingId, - .hasIndex = 44, + .hasIndex = 41, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, googleAdvertisingId), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -626,7 +633,7 @@ + (GPBDescriptor *)descriptor { .name = "idfa", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Idfa, - .hasIndex = 45, + .hasIndex = 42, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, idfa), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -635,7 +642,7 @@ + (GPBDescriptor *)descriptor { .name = "idfv", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Idfv, - .hasIndex = 46, + .hasIndex = 43, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, idfv), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -644,7 +651,7 @@ + (GPBDescriptor *)descriptor { .name = "orientation", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_Orientation, - .hasIndex = 47, + .hasIndex = 44, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, orientation), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -653,7 +660,7 @@ + (GPBDescriptor *)descriptor { .name = "projectKey", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_ProjectKey, - .hasIndex = 48, + .hasIndex = 45, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, projectKey), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, @@ -662,7 +669,7 @@ + (GPBDescriptor *)descriptor { .name = "sendTime", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_SendTime, - .hasIndex = 49, + .hasIndex = 46, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, sendTime), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeInt64, @@ -671,20 +678,38 @@ + (GPBDescriptor *)descriptor { .name = "userKey", .dataTypeSpecific.clazz = Nil, .number = GrowingPBEventV3Dto_FieldNumber_UserKey, - .hasIndex = 50, + .hasIndex = 47, .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, userKey), .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, }, + { + .name = "xcontent", + .dataTypeSpecific.clazz = Nil, + .number = GrowingPBEventV3Dto_FieldNumber_Xcontent, + .hasIndex = 48, + .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, xcontent), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), + .dataType = GPBDataTypeString, + }, + { + .name = "xindex", + .dataTypeSpecific.clazz = Nil, + .number = GrowingPBEventV3Dto_FieldNumber_Xindex, + .hasIndex = 49, + .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, xindex), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), + .dataType = GPBDataTypeString, + }, }; GPBDescriptor *localDescriptor = - [GPBDescriptor allocDescriptorForClass:[GrowingPBEventV3Dto class] - rootClass:[GrowingPBEventV3Root class] - file:GrowingPBEventV3Root_FileDescriptor() + [GPBDescriptor allocDescriptorForClass:GPBObjCClass(GrowingPBEventV3Dto) + messageName:@"EventV3Dto" + fileDescription:&GrowingPBEventV3Root_FileDescription fields:fields fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GrowingPBEventV3Dto__storage_) - flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown)]; + flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; #if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS static const char *extraTextFormatInfo = "\001\037!!!\246\000"; @@ -732,6 +757,7 @@ @implementation GrowingPBResourceItem + (GPBDescriptor *)descriptor { static GPBDescriptor *descriptor = nil; if (!descriptor) { + GPB_DEBUG_CHECK_RUNTIME_VERSIONS(); static GPBMessageFieldDescription fields[] = { { .name = "id_p", @@ -762,13 +788,13 @@ + (GPBDescriptor *)descriptor { }, }; GPBDescriptor *localDescriptor = - [GPBDescriptor allocDescriptorForClass:[GrowingPBResourceItem class] - rootClass:[GrowingPBEventV3Root class] - file:GrowingPBEventV3Root_FileDescriptor() + [GPBDescriptor allocDescriptorForClass:GPBObjCClass(GrowingPBResourceItem) + messageName:@"ResourceItem" + fileDescription:&GrowingPBEventV3Root_FileDescription fields:fields fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GrowingPBResourceItem__storage_) - flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown)]; + flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; #if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); #endif // DEBUG @@ -795,6 +821,7 @@ @implementation GrowingPBEventV3List + (GPBDescriptor *)descriptor { static GPBDescriptor *descriptor = nil; if (!descriptor) { + GPB_DEBUG_CHECK_RUNTIME_VERSIONS(); static GPBMessageFieldDescription fields[] = { { .name = "valuesArray", @@ -807,13 +834,13 @@ + (GPBDescriptor *)descriptor { }, }; GPBDescriptor *localDescriptor = - [GPBDescriptor allocDescriptorForClass:[GrowingPBEventV3List class] - rootClass:[GrowingPBEventV3Root class] - file:GrowingPBEventV3Root_FileDescriptor() + [GPBDescriptor allocDescriptorForClass:GPBObjCClass(GrowingPBEventV3List) + messageName:@"EventV3List" + fileDescription:&GrowingPBEventV3Root_FileDescription fields:fields fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GrowingPBEventV3List__storage_) - flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown)]; + flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; #if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); #endif // DEBUG @@ -828,3 +855,5 @@ + (GPBDescriptor *)descriptor { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) + +// clang-format on diff --git a/Modules/Protobuf/Proto/event_v3.proto b/Modules/Protobuf/Proto/event_v3.proto index eee418be8..8bd54b64e 100644 --- a/Modules/Protobuf/Proto/event_v3.proto +++ b/Modules/Protobuf/Proto/event_v3.proto @@ -1,42 +1,43 @@ syntax = "proto3"; - -package com.growingio.database; -option java_package = "com.growingio.database"; +package io.growing.tunnel.protocol; +option java_package = "io.growing.collector.tunnel.protocol"; +option java_multiple_files = true; option java_outer_classname = "EventV3Protocol"; option objc_class_prefix = "GrowingPB"; message EventV3Dto { + + reserved 3, 14, 23, 41, 43; + reserved "gio_id", "global_sequence_id", "page_show_timestamp", "operating_system_version"; + string device_id = 1; string user_id = 2; - string gio_id = 3; string session_id = 4; string data_source_id = 5; EventType event_type = 6; string platform = 7; int64 timestamp = 8; string domain = 9; - string path = 10;//PageEvent - string query = 11;//HybridCustomEvent - string title = 12;//PageEvent - string referral_page = 13;//PageEvent - int64 global_sequence_id = 14; + string path = 10; + string query = 11; + string title = 12; + string referral_page = 13; int32 event_sequence_id = 15; int32 screen_height = 16; int32 screen_width = 17; string language = 18; string sdk_version = 19; string app_version = 20; - map extra_sdk = 21;//VisitEvent - string event_name = 22;//customEvent - int64 page_show_timestamp = 23;//PageAttributesEvent - map attributes = 24; //BaseAttributesEvent - ResourceItem resource_item = 25; //ResourceItemCustomEvent - string protocol_type = 26;//HybridPageEvent - string text_value = 27;//ViewElementEvent - string xpath = 28;//ViewElementEvent - int32 index = 29;//ViewElementEvent - string hyperlink = 30;//HybridViewElementEvent + map extra_sdk = 21; + string event_name = 22; + map attributes = 24; + ResourceItem resource_item = 25; + string protocol_type = 26; + string text_value = 27; + string xpath = 28; + int32 index = 29; + string hyperlink = 30; string url_scheme = 31; string app_state = 32; string network_state = 33; @@ -46,20 +47,22 @@ message EventV3Dto { string device_brand = 37; string device_model = 38; string device_type = 39; - string operating_system = 40;//refer platformVersion + string operating_system = 40; string app_name = 42; double latitude = 44; double longitude = 45; - string imei = 46; //VISITEVENT - string android_id = 47;//VISITEVENT - string oaid = 48;//VISITEVENT - string google_advertising_id = 49;//VISITEVENT - string idfa = 50;//for ios - string idfv = 51;//for ios - string orientation = 52;//PageEvent + string imei = 46; + string android_id = 47; + string oaid = 48; + string google_advertising_id = 49; + string idfa = 50; + string idfv = 51; + string orientation = 52; string project_key = 53; int64 send_time = 54; string user_key = 55; + string xcontent = 56; + string xindex = 57; } message ResourceItem { diff --git a/Modules/SwiftProtobuf/SwiftProtobuf.swift b/Modules/SwiftProtobuf/SwiftProtobuf.swift index 8a3f6ed6b..60f6c2962 100644 --- a/Modules/SwiftProtobuf/SwiftProtobuf.swift +++ b/Modules/SwiftProtobuf/SwiftProtobuf.swift @@ -20,11 +20,15 @@ import Foundation import GrowingTrackerCore +typealias EventDto = Io_Growing_Tunnel_Protocol_EventV3Dto +typealias EventList = Io_Growing_Tunnel_Protocol_EventV3List +typealias EventType = Io_Growing_Tunnel_Protocol_EventType + @objc(GrowingSwiftProtobuf) public class SwiftProtobufWrapper: NSObject { - var unbox: EventV3Dto + var unbox: EventDto @objc public let data: Data? - init(_ unbox: EventV3Dto) { + init(_ unbox: EventDto) { self.unbox = unbox self.data = try? unbox.serializedData() } @@ -32,7 +36,7 @@ public class SwiftProtobufWrapper: NSObject { @objc(parseFromData:) public static func parse(from data: Data) -> SwiftProtobufWrapper? { do { - let dto = try EventV3Dto(serializedData: data) + let dto = try EventDto(serializedData: data) return SwiftProtobufWrapper(dto) } catch { return nil @@ -59,7 +63,7 @@ public class SwiftProtobufWrapper: NSObject { @objc(serializedDatasFromList:) public static func serializedDatas(from boxes: [SwiftProtobufWrapper]) -> Data? { do { - var list = EventV3List() + var list = EventList() for box in boxes { list.values.append(box.unbox) } @@ -75,7 +79,7 @@ extension SwiftProtobufWrapper { @objc(convertProtobufDataToJsonArray:) public static func convertProtobufDataToJsonArray(from data: Data) -> [[String: AnyObject]]? { do { - let list = try EventV3List(serializedData: data) + let list = try EventList(serializedData: data) var array = [[String: AnyObject]]() for dto in list.values { let jsonData = try dto.jsonUTF8Data() @@ -93,7 +97,7 @@ extension SwiftProtobufWrapper { extension GrowingBaseEvent { @objc public func toProtobuf() -> SwiftProtobufWrapper { - var dto = EventV3Dto() + var dto = EventDto() dto.dataSourceID = self.dataSourceId ?? "" dto.sessionID = self.sessionId ?? "" @@ -109,9 +113,9 @@ extension GrowingBaseEvent { dto.networkState = self.networkState ?? "" dto.screenWidth = Int32(self.screenWidth) dto.screenHeight = Int32(self.screenHeight) - dto.deviceBrand = self.deviceBrand - dto.deviceModel = self.deviceModel - dto.deviceType = self.deviceType + dto.deviceBrand = self.deviceBrand ?? "" + dto.deviceModel = self.deviceModel ?? "" + dto.deviceType = self.deviceType ?? "" dto.appName = self.appName dto.appVersion = self.appVersion dto.language = self.language @@ -127,6 +131,8 @@ extension GrowingBaseEvent { dto.path = path() dto.textValue = textValue() dto.xpath = xpath() + dto.xcontent = xcontent() + dto.xindex = xindex() dto.index = index() dto.query = query() dto.hyperlink = hyperlink() @@ -227,6 +233,24 @@ extension GrowingBaseEvent { } return "" } + + fileprivate func xcontent() -> String { + let selector = Selector(("xcontent")) + if self.responds(to: selector) { + let imp: IMP = method_getImplementation(class_getInstanceMethod(type(of: self), selector)!) + return unsafeBitCast(imp, to: (@convention(c)(GrowingBaseEvent, Selector) -> String?).self)(self, selector) ?? "" + } + return "" + } + + fileprivate func xindex() -> String { + let selector = Selector(("xindex")) + if self.responds(to: selector) { + let imp: IMP = method_getImplementation(class_getInstanceMethod(type(of: self), selector)!) + return unsafeBitCast(imp, to: (@convention(c)(GrowingBaseEvent, Selector) -> String?).self)(self, selector) ?? "" + } + return "" + } fileprivate func index() -> Int32 { let selector = Selector(("index")) diff --git a/Modules/SwiftProtobuf/event_v3.pb.swift b/Modules/SwiftProtobuf/event_v3.pb.swift index 454aaa8c7..fccfef6e7 100644 --- a/Modules/SwiftProtobuf/event_v3.pb.swift +++ b/Modules/SwiftProtobuf/event_v3.pb.swift @@ -20,7 +20,7 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP typealias Version = _2 } -enum EventType: SwiftProtobuf.Enum { +enum Io_Growing_Tunnel_Protocol_EventType: SwiftProtobuf.Enum { typealias RawValue = Int case visit // = 0 case custom // = 1 @@ -80,9 +80,9 @@ enum EventType: SwiftProtobuf.Enum { #if swift(>=4.2) -extension EventType: CaseIterable { +extension Io_Growing_Tunnel_Protocol_EventType: CaseIterable { // The compiler won't synthesize support with the UNRECOGNIZED case. - static var allCases: [EventType] = [ + static var allCases: [Io_Growing_Tunnel_Protocol_EventType] = [ .visit, .custom, .visitorAttributes, @@ -100,7 +100,7 @@ extension EventType: CaseIterable { #endif // swift(>=4.2) -struct EventV3Dto { +struct Io_Growing_Tunnel_Protocol_EventV3Dto { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. @@ -115,11 +115,6 @@ struct EventV3Dto { set {_uniqueStorage()._userID = newValue} } - var gioID: String { - get {return _storage._gioID} - set {_uniqueStorage()._gioID = newValue} - } - var sessionID: String { get {return _storage._sessionID} set {_uniqueStorage()._sessionID = newValue} @@ -130,7 +125,7 @@ struct EventV3Dto { set {_uniqueStorage()._dataSourceID = newValue} } - var eventType: EventType { + var eventType: Io_Growing_Tunnel_Protocol_EventType { get {return _storage._eventType} set {_uniqueStorage()._eventType = newValue} } @@ -150,35 +145,26 @@ struct EventV3Dto { set {_uniqueStorage()._domain = newValue} } - ///PageEvent var path: String { get {return _storage._path} set {_uniqueStorage()._path = newValue} } - ///HybridCustomEvent var query: String { get {return _storage._query} set {_uniqueStorage()._query = newValue} } - ///PageEvent var title: String { get {return _storage._title} set {_uniqueStorage()._title = newValue} } - ///PageEvent var referralPage: String { get {return _storage._referralPage} set {_uniqueStorage()._referralPage = newValue} } - var globalSequenceID: Int64 { - get {return _storage._globalSequenceID} - set {_uniqueStorage()._globalSequenceID = newValue} - } - var eventSequenceID: Int32 { get {return _storage._eventSequenceID} set {_uniqueStorage()._eventSequenceID = newValue} @@ -209,33 +195,23 @@ struct EventV3Dto { set {_uniqueStorage()._appVersion = newValue} } - ///VisitEvent var extraSdk: Dictionary { get {return _storage._extraSdk} set {_uniqueStorage()._extraSdk = newValue} } - ///customEvent var eventName: String { get {return _storage._eventName} set {_uniqueStorage()._eventName = newValue} } - ///PageAttributesEvent - var pageShowTimestamp: Int64 { - get {return _storage._pageShowTimestamp} - set {_uniqueStorage()._pageShowTimestamp = newValue} - } - - ///BaseAttributesEvent var attributes: Dictionary { get {return _storage._attributes} set {_uniqueStorage()._attributes = newValue} } - ///ResourceItemCustomEvent - var resourceItem: ResourceItem { - get {return _storage._resourceItem ?? ResourceItem()} + var resourceItem: Io_Growing_Tunnel_Protocol_ResourceItem { + get {return _storage._resourceItem ?? Io_Growing_Tunnel_Protocol_ResourceItem()} set {_uniqueStorage()._resourceItem = newValue} } /// Returns true if `resourceItem` has been explicitly set. @@ -243,31 +219,26 @@ struct EventV3Dto { /// Clears the value of `resourceItem`. Subsequent reads from it will return its default value. mutating func clearResourceItem() {_uniqueStorage()._resourceItem = nil} - ///HybridPageEvent var protocolType: String { get {return _storage._protocolType} set {_uniqueStorage()._protocolType = newValue} } - ///ViewElementEvent var textValue: String { get {return _storage._textValue} set {_uniqueStorage()._textValue = newValue} } - ///ViewElementEvent var xpath: String { get {return _storage._xpath} set {_uniqueStorage()._xpath = newValue} } - ///ViewElementEvent var index: Int32 { get {return _storage._index} set {_uniqueStorage()._index = newValue} } - ///HybridViewElementEvent var hyperlink: String { get {return _storage._hyperlink} set {_uniqueStorage()._hyperlink = newValue} @@ -319,7 +290,6 @@ struct EventV3Dto { set {_uniqueStorage()._deviceType = newValue} } - ///refer platformVersion var operatingSystem: String { get {return _storage._operatingSystem} set {_uniqueStorage()._operatingSystem = newValue} @@ -340,43 +310,36 @@ struct EventV3Dto { set {_uniqueStorage()._longitude = newValue} } - ///VISITEVENT var imei: String { get {return _storage._imei} set {_uniqueStorage()._imei = newValue} } - ///VISITEVENT var androidID: String { get {return _storage._androidID} set {_uniqueStorage()._androidID = newValue} } - ///VISITEVENT var oaid: String { get {return _storage._oaid} set {_uniqueStorage()._oaid = newValue} } - ///VISITEVENT var googleAdvertisingID: String { get {return _storage._googleAdvertisingID} set {_uniqueStorage()._googleAdvertisingID = newValue} } - ///for ios var idfa: String { get {return _storage._idfa} set {_uniqueStorage()._idfa = newValue} } - ///for ios var idfv: String { get {return _storage._idfv} set {_uniqueStorage()._idfv = newValue} } - ///PageEvent var orientation: String { get {return _storage._orientation} set {_uniqueStorage()._orientation = newValue} @@ -397,6 +360,16 @@ struct EventV3Dto { set {_uniqueStorage()._userKey = newValue} } + var xcontent: String { + get {return _storage._xcontent} + set {_uniqueStorage()._xcontent = newValue} + } + + var xindex: String { + get {return _storage._xindex} + set {_uniqueStorage()._xindex = newValue} + } + var unknownFields = SwiftProtobuf.UnknownStorage() init() {} @@ -404,7 +377,7 @@ struct EventV3Dto { fileprivate var _storage = _StorageClass.defaultInstance } -struct ResourceItem { +struct Io_Growing_Tunnel_Protocol_ResourceItem { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. @@ -420,12 +393,12 @@ struct ResourceItem { init() {} } -struct EventV3List { +struct Io_Growing_Tunnel_Protocol_EventV3List { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. - var values: [EventV3Dto] = [] + var values: [Io_Growing_Tunnel_Protocol_EventV3Dto] = [] var unknownFields = SwiftProtobuf.UnknownStorage() @@ -433,15 +406,17 @@ struct EventV3List { } #if swift(>=5.5) && canImport(_Concurrency) -extension EventType: @unchecked Sendable {} -extension EventV3Dto: @unchecked Sendable {} -extension ResourceItem: @unchecked Sendable {} -extension EventV3List: @unchecked Sendable {} +extension Io_Growing_Tunnel_Protocol_EventType: @unchecked Sendable {} +extension Io_Growing_Tunnel_Protocol_EventV3Dto: @unchecked Sendable {} +extension Io_Growing_Tunnel_Protocol_ResourceItem: @unchecked Sendable {} +extension Io_Growing_Tunnel_Protocol_EventV3List: @unchecked Sendable {} #endif // swift(>=5.5) && canImport(_Concurrency) // MARK: - Code below here is support for the SwiftProtobuf runtime. -extension EventType: SwiftProtobuf._ProtoNameProviding { +fileprivate let _protobuf_package = "io.growing.tunnel.protocol" + +extension Io_Growing_Tunnel_Protocol_EventType: SwiftProtobuf._ProtoNameProviding { static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 0: .same(proto: "VISIT"), 1: .same(proto: "CUSTOM"), @@ -458,12 +433,11 @@ extension EventType: SwiftProtobuf._ProtoNameProviding { ] } -extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = "EventV3Dto" +extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".EventV3Dto" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .standard(proto: "device_id"), 2: .standard(proto: "user_id"), - 3: .standard(proto: "gio_id"), 4: .standard(proto: "session_id"), 5: .standard(proto: "data_source_id"), 6: .standard(proto: "event_type"), @@ -474,7 +448,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio 11: .same(proto: "query"), 12: .same(proto: "title"), 13: .standard(proto: "referral_page"), - 14: .standard(proto: "global_sequence_id"), 15: .standard(proto: "event_sequence_id"), 16: .standard(proto: "screen_height"), 17: .standard(proto: "screen_width"), @@ -483,7 +456,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio 20: .standard(proto: "app_version"), 21: .standard(proto: "extra_sdk"), 22: .standard(proto: "event_name"), - 23: .standard(proto: "page_show_timestamp"), 24: .same(proto: "attributes"), 25: .standard(proto: "resource_item"), 26: .standard(proto: "protocol_type"), @@ -514,15 +486,16 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio 53: .standard(proto: "project_key"), 54: .standard(proto: "send_time"), 55: .standard(proto: "user_key"), + 56: .same(proto: "xcontent"), + 57: .same(proto: "xindex"), ] fileprivate class _StorageClass { var _deviceID: String = String() var _userID: String = String() - var _gioID: String = String() var _sessionID: String = String() var _dataSourceID: String = String() - var _eventType: EventType = .visit + var _eventType: Io_Growing_Tunnel_Protocol_EventType = .visit var _platform: String = String() var _timestamp: Int64 = 0 var _domain: String = String() @@ -530,7 +503,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio var _query: String = String() var _title: String = String() var _referralPage: String = String() - var _globalSequenceID: Int64 = 0 var _eventSequenceID: Int32 = 0 var _screenHeight: Int32 = 0 var _screenWidth: Int32 = 0 @@ -539,9 +511,8 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio var _appVersion: String = String() var _extraSdk: Dictionary = [:] var _eventName: String = String() - var _pageShowTimestamp: Int64 = 0 var _attributes: Dictionary = [:] - var _resourceItem: ResourceItem? = nil + var _resourceItem: Io_Growing_Tunnel_Protocol_ResourceItem? = nil var _protocolType: String = String() var _textValue: String = String() var _xpath: String = String() @@ -570,6 +541,8 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio var _projectKey: String = String() var _sendTime: Int64 = 0 var _userKey: String = String() + var _xcontent: String = String() + var _xindex: String = String() static let defaultInstance = _StorageClass() @@ -578,7 +551,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio init(copying source: _StorageClass) { _deviceID = source._deviceID _userID = source._userID - _gioID = source._gioID _sessionID = source._sessionID _dataSourceID = source._dataSourceID _eventType = source._eventType @@ -589,7 +561,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio _query = source._query _title = source._title _referralPage = source._referralPage - _globalSequenceID = source._globalSequenceID _eventSequenceID = source._eventSequenceID _screenHeight = source._screenHeight _screenWidth = source._screenWidth @@ -598,7 +569,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio _appVersion = source._appVersion _extraSdk = source._extraSdk _eventName = source._eventName - _pageShowTimestamp = source._pageShowTimestamp _attributes = source._attributes _resourceItem = source._resourceItem _protocolType = source._protocolType @@ -629,6 +599,8 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio _projectKey = source._projectKey _sendTime = source._sendTime _userKey = source._userKey + _xcontent = source._xcontent + _xindex = source._xindex } } @@ -649,7 +621,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio switch fieldNumber { case 1: try { try decoder.decodeSingularStringField(value: &_storage._deviceID) }() case 2: try { try decoder.decodeSingularStringField(value: &_storage._userID) }() - case 3: try { try decoder.decodeSingularStringField(value: &_storage._gioID) }() case 4: try { try decoder.decodeSingularStringField(value: &_storage._sessionID) }() case 5: try { try decoder.decodeSingularStringField(value: &_storage._dataSourceID) }() case 6: try { try decoder.decodeSingularEnumField(value: &_storage._eventType) }() @@ -660,7 +631,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio case 11: try { try decoder.decodeSingularStringField(value: &_storage._query) }() case 12: try { try decoder.decodeSingularStringField(value: &_storage._title) }() case 13: try { try decoder.decodeSingularStringField(value: &_storage._referralPage) }() - case 14: try { try decoder.decodeSingularInt64Field(value: &_storage._globalSequenceID) }() case 15: try { try decoder.decodeSingularInt32Field(value: &_storage._eventSequenceID) }() case 16: try { try decoder.decodeSingularInt32Field(value: &_storage._screenHeight) }() case 17: try { try decoder.decodeSingularInt32Field(value: &_storage._screenWidth) }() @@ -669,7 +639,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio case 20: try { try decoder.decodeSingularStringField(value: &_storage._appVersion) }() case 21: try { try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: &_storage._extraSdk) }() case 22: try { try decoder.decodeSingularStringField(value: &_storage._eventName) }() - case 23: try { try decoder.decodeSingularInt64Field(value: &_storage._pageShowTimestamp) }() case 24: try { try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: &_storage._attributes) }() case 25: try { try decoder.decodeSingularMessageField(value: &_storage._resourceItem) }() case 26: try { try decoder.decodeSingularStringField(value: &_storage._protocolType) }() @@ -700,6 +669,8 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio case 53: try { try decoder.decodeSingularStringField(value: &_storage._projectKey) }() case 54: try { try decoder.decodeSingularInt64Field(value: &_storage._sendTime) }() case 55: try { try decoder.decodeSingularStringField(value: &_storage._userKey) }() + case 56: try { try decoder.decodeSingularStringField(value: &_storage._xcontent) }() + case 57: try { try decoder.decodeSingularStringField(value: &_storage._xindex) }() default: break } } @@ -718,9 +689,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if !_storage._userID.isEmpty { try visitor.visitSingularStringField(value: _storage._userID, fieldNumber: 2) } - if !_storage._gioID.isEmpty { - try visitor.visitSingularStringField(value: _storage._gioID, fieldNumber: 3) - } if !_storage._sessionID.isEmpty { try visitor.visitSingularStringField(value: _storage._sessionID, fieldNumber: 4) } @@ -751,9 +719,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if !_storage._referralPage.isEmpty { try visitor.visitSingularStringField(value: _storage._referralPage, fieldNumber: 13) } - if _storage._globalSequenceID != 0 { - try visitor.visitSingularInt64Field(value: _storage._globalSequenceID, fieldNumber: 14) - } if _storage._eventSequenceID != 0 { try visitor.visitSingularInt32Field(value: _storage._eventSequenceID, fieldNumber: 15) } @@ -778,9 +743,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if !_storage._eventName.isEmpty { try visitor.visitSingularStringField(value: _storage._eventName, fieldNumber: 22) } - if _storage._pageShowTimestamp != 0 { - try visitor.visitSingularInt64Field(value: _storage._pageShowTimestamp, fieldNumber: 23) - } if !_storage._attributes.isEmpty { try visitor.visitMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: _storage._attributes, fieldNumber: 24) } @@ -871,18 +833,23 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if !_storage._userKey.isEmpty { try visitor.visitSingularStringField(value: _storage._userKey, fieldNumber: 55) } + if !_storage._xcontent.isEmpty { + try visitor.visitSingularStringField(value: _storage._xcontent, fieldNumber: 56) + } + if !_storage._xindex.isEmpty { + try visitor.visitSingularStringField(value: _storage._xindex, fieldNumber: 57) + } } try unknownFields.traverse(visitor: &visitor) } - static func ==(lhs: EventV3Dto, rhs: EventV3Dto) -> Bool { + static func ==(lhs: Io_Growing_Tunnel_Protocol_EventV3Dto, rhs: Io_Growing_Tunnel_Protocol_EventV3Dto) -> Bool { if lhs._storage !== rhs._storage { let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in let _storage = _args.0 let rhs_storage = _args.1 if _storage._deviceID != rhs_storage._deviceID {return false} if _storage._userID != rhs_storage._userID {return false} - if _storage._gioID != rhs_storage._gioID {return false} if _storage._sessionID != rhs_storage._sessionID {return false} if _storage._dataSourceID != rhs_storage._dataSourceID {return false} if _storage._eventType != rhs_storage._eventType {return false} @@ -893,7 +860,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if _storage._query != rhs_storage._query {return false} if _storage._title != rhs_storage._title {return false} if _storage._referralPage != rhs_storage._referralPage {return false} - if _storage._globalSequenceID != rhs_storage._globalSequenceID {return false} if _storage._eventSequenceID != rhs_storage._eventSequenceID {return false} if _storage._screenHeight != rhs_storage._screenHeight {return false} if _storage._screenWidth != rhs_storage._screenWidth {return false} @@ -902,7 +868,6 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if _storage._appVersion != rhs_storage._appVersion {return false} if _storage._extraSdk != rhs_storage._extraSdk {return false} if _storage._eventName != rhs_storage._eventName {return false} - if _storage._pageShowTimestamp != rhs_storage._pageShowTimestamp {return false} if _storage._attributes != rhs_storage._attributes {return false} if _storage._resourceItem != rhs_storage._resourceItem {return false} if _storage._protocolType != rhs_storage._protocolType {return false} @@ -933,6 +898,8 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio if _storage._projectKey != rhs_storage._projectKey {return false} if _storage._sendTime != rhs_storage._sendTime {return false} if _storage._userKey != rhs_storage._userKey {return false} + if _storage._xcontent != rhs_storage._xcontent {return false} + if _storage._xindex != rhs_storage._xindex {return false} return true } if !storagesAreEqual {return false} @@ -942,8 +909,8 @@ extension EventV3Dto: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio } } -extension ResourceItem: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = "ResourceItem" +extension Io_Growing_Tunnel_Protocol_ResourceItem: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".ResourceItem" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "id"), 2: .same(proto: "key"), @@ -977,7 +944,7 @@ extension ResourceItem: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat try unknownFields.traverse(visitor: &visitor) } - static func ==(lhs: ResourceItem, rhs: ResourceItem) -> Bool { + static func ==(lhs: Io_Growing_Tunnel_Protocol_ResourceItem, rhs: Io_Growing_Tunnel_Protocol_ResourceItem) -> Bool { if lhs.id != rhs.id {return false} if lhs.key != rhs.key {return false} if lhs.attributes != rhs.attributes {return false} @@ -986,8 +953,8 @@ extension ResourceItem: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat } } -extension EventV3List: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = "EventV3List" +extension Io_Growing_Tunnel_Protocol_EventV3List: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".EventV3List" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "values"), ] @@ -1011,7 +978,7 @@ extension EventV3List: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati try unknownFields.traverse(visitor: &visitor) } - static func ==(lhs: EventV3List, rhs: EventV3List) -> Bool { + static func ==(lhs: Io_Growing_Tunnel_Protocol_EventV3List, rhs: Io_Growing_Tunnel_Protocol_EventV3List) -> Bool { if lhs.values != rhs.values {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true diff --git a/Podfile.lock b/Podfile.lock index fb92b35df..e05bcd2c2 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -42,7 +42,7 @@ PODS: - GrowingAnalytics/Protobuf/Proto (3.5.0): - GrowingAnalytics/Database (= 3.5.0) - GrowingAnalytics/TrackerCore (= 3.5.0) - - Protobuf + - Protobuf (>= 3.22.0) - GrowingAnalytics/Screenshot (3.5.0): - GrowingAnalytics/TrackerCore - GrowingAnalytics/Tracker (3.5.0): @@ -150,7 +150,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: a01857dc934fa4b0b0b4a04b46d888d2472d5fa2 + GrowingAnalytics: f51d83c651a545a18f3642df92c722350de286ac GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 9c0d6e41c9678397dbaa3304b1738a2867b023ae GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 From 163802483d4c7573c1801885234bfed67f418194 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 31 Jul 2023 07:41:37 +0000 Subject: [PATCH 047/126] style: code format --- Modules/SwiftProtobuf/SwiftProtobuf.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/SwiftProtobuf/SwiftProtobuf.swift b/Modules/SwiftProtobuf/SwiftProtobuf.swift index 60f6c2962..55804488c 100644 --- a/Modules/SwiftProtobuf/SwiftProtobuf.swift +++ b/Modules/SwiftProtobuf/SwiftProtobuf.swift @@ -233,7 +233,7 @@ extension GrowingBaseEvent { } return "" } - + fileprivate func xcontent() -> String { let selector = Selector(("xcontent")) if self.responds(to: selector) { @@ -242,7 +242,7 @@ extension GrowingBaseEvent { } return "" } - + fileprivate func xindex() -> String { let selector = Selector(("xindex")) if self.responds(to: selector) { From b0a30fea5a4cadfea6e23edb3bc7354b0c253796 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 3 Aug 2023 11:34:31 +0800 Subject: [PATCH 048/126] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=20UITableView?= =?UTF-8?q?HeaderFooterView=20=E5=9C=88=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Category/UITableView+GrowingNode.m | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m index a34104ba8..965f432ab 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m @@ -24,9 +24,25 @@ @implementation UITableView (GrowingNode) - (NSArray> *)growingNodeChilds { - // 对于collectionView我们仅需要返回可见cell NSMutableArray *childs = [NSMutableArray array]; [childs addObjectsFromArray:self.visibleCells]; + + NSArray *indexPaths = self.indexPathsForVisibleRows; + NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet]; + for (NSIndexPath *indexPath in indexPaths) { + [indexSet addIndex:indexPath.section]; + } + [indexSet enumerateIndexesUsingBlock:^(NSUInteger section, BOOL * _Nonnull stop) { + UITableViewHeaderFooterView *headerView = [self headerViewForSection:section]; + if (headerView) { + [childs addObject:headerView]; + } + UITableViewHeaderFooterView *footerView = [self footerViewForSection:section]; + if (footerView) { + [childs addObject:footerView]; + } + }]; + if (self.tableFooterView) { [childs addObject:self.tableFooterView]; } From 0f34c5f11e55a04f7b481587830306c2aac198f7 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 3 Aug 2023 03:35:17 +0000 Subject: [PATCH 049/126] style: code format --- .../GrowingNode/Category/UITableView+GrowingNode.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m index 965f432ab..126e64f84 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m @@ -26,13 +26,13 @@ @implementation UITableView (GrowingNode) - (NSArray> *)growingNodeChilds { NSMutableArray *childs = [NSMutableArray array]; [childs addObjectsFromArray:self.visibleCells]; - + NSArray *indexPaths = self.indexPathsForVisibleRows; NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet]; for (NSIndexPath *indexPath in indexPaths) { [indexSet addIndex:indexPath.section]; } - [indexSet enumerateIndexesUsingBlock:^(NSUInteger section, BOOL * _Nonnull stop) { + [indexSet enumerateIndexesUsingBlock:^(NSUInteger section, BOOL *_Nonnull stop) { UITableViewHeaderFooterView *headerView = [self headerViewForSection:section]; if (headerView) { [childs addObject:headerView]; @@ -42,7 +42,7 @@ @implementation UITableView (GrowingNode) [childs addObject:footerView]; } }]; - + if (self.tableFooterView) { [childs addObject:self.tableFooterView]; } From c87cb1c1e1f615cd396b2d24959604da81f93bae Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 7 Aug 2023 16:17:05 +0800 Subject: [PATCH 050/126] =?UTF-8?q?refactor:=20=E6=9C=AC=E5=9C=B0=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E6=8C=89=20channel=20=E5=8C=BA=E5=88=86=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=B0=86=20Protobuf=20=E6=A8=A1=E5=9D=97=E5=86=85?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE --- Example/Example.xcodeproj/project.pbxproj | 28 +- GrowingAnalytics.podspec | 2 + .../Database/GrowingEventDatabase.h | 8 +- .../Database/GrowingEventDatabase.m | 39 +- .../Event/GrowingEventChannel.h | 31 +- .../Event/GrowingEventChannel.m | 95 ++-- .../Event/GrowingEventManager.h | 2 + .../Event/GrowingEventManager.m | 189 +++----- .../Public/GrowingEventDatabaseService.h | 8 +- .../Public/GrowingEventPersistenceProtocol.h | 6 + Modules/Advert/GrowingAdvertising.m | 7 +- .../Protobuf/GrowingEventProtobufDatabase.h | 9 +- .../Protobuf/GrowingEventProtobufDatabase.m | 437 +----------------- .../GrowingEventProtobufPersistence.h | 11 +- .../GrowingEventProtobufPersistence.m | 2 +- Modules/Protobuf/GrowingProtobufModule.m | 3 +- Podfile.lock | 4 +- .../Database/GrowingEventFMDatabase+Private.h | 32 ++ Services/Database/GrowingEventFMDatabase.m | 183 ++++---- Services/Database/GrowingEventJSONDatabase.h | 29 ++ Services/Database/GrowingEventJSONDatabase.m | 62 +++ .../Database/GrowingEventJSONPersistence.h | 11 +- .../Database/GrowingEventJSONPersistence.m | 12 +- 23 files changed, 420 insertions(+), 790 deletions(-) create mode 100644 Services/Database/GrowingEventFMDatabase+Private.h create mode 100644 Services/Database/GrowingEventJSONDatabase.h create mode 100644 Services/Database/GrowingEventJSONDatabase.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 613d114d4..c52a0fa00 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -1783,7 +1783,7 @@ "${BUILT_PRODUCTS_DIR}/GrowingToolsKit/GrowingToolsKit.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/LBXScan/LBXScan.framework", - "${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", "${BUILT_PRODUCTS_DIR}/SDCycleScrollView/SDCycleScrollView.framework", "${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework", ); @@ -1810,13 +1810,15 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsStartTests/Pods-GrowingAnalyticsStartTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-0637fae5/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-9f864bbd/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1963,9 +1965,10 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-ExampleiOS13/Pods-ExampleiOS13-frameworks.sh", "${BUILT_PRODUCTS_DIR}/GrowingAPM/GrowingAPM.framework", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-4e785b40/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-c1567d15/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingToolsKit/GrowingToolsKit.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( @@ -1973,6 +1976,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingToolsKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1986,13 +1990,15 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsTests/Pods-GrowingAnalyticsTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-bae859d0/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-8e13d3d1/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -2006,14 +2012,16 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-ef2c314b/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-61b6cda4/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", "${BUILT_PRODUCTS_DIR}/KIF/KIF.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KIF.framework", ); runOnlyForDeploymentPostprocessing = 0; @@ -2074,7 +2082,7 @@ "${PODS_ROOT}/Target Support Files/Pods-ProtobufTests/Pods-ProtobufTests-frameworks.sh", "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-61b6cda4/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", - "${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( @@ -2094,13 +2102,15 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Example-macOS/Pods-Example-macOS-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-4c71c34d/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-39d19e2e/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-TrackerCore/GrowingUtils.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-macOS/Protobuf.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -2114,13 +2124,15 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-AdvertTests/Pods-AdvertTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-4e785b40/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-c1567d15/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", + "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingAnalytics.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GrowingUtils.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/GrowingAnalytics.podspec b/GrowingAnalytics.podspec index faed2fc77..405c72d5c 100644 --- a/GrowingAnalytics.podspec +++ b/GrowingAnalytics.podspec @@ -23,6 +23,7 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 autotracker.dependency 'GrowingAnalytics/AutotrackerCore', s.version.to_s # Modules + autotracker.dependency 'GrowingAnalytics/Protobuf', s.version.to_s autotracker.ios.dependency 'GrowingAnalytics/Hybrid', s.version.to_s autotracker.ios.dependency 'GrowingAnalytics/MobileDebugger', s.version.to_s autotracker.ios.dependency 'GrowingAnalytics/WebCircle', s.version.to_s @@ -35,6 +36,7 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 tracker.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s # Modules + tracker.dependency 'GrowingAnalytics/Protobuf', s.version.to_s tracker.ios.dependency 'GrowingAnalytics/MobileDebugger', s.version.to_s tracker.dependency 'GrowingAnalytics/DefaultServices', s.version.to_s end diff --git a/GrowingTrackerCore/Database/GrowingEventDatabase.h b/GrowingTrackerCore/Database/GrowingEventDatabase.h index 62f76e236..44c46a5d0 100644 --- a/GrowingTrackerCore/Database/GrowingEventDatabase.h +++ b/GrowingTrackerCore/Database/GrowingEventDatabase.h @@ -24,7 +24,7 @@ @property (nonatomic, assign) NSUInteger autoFlushCount; -+ (instancetype)databaseWithPath:(NSString *)path; ++ (instancetype)databaseWithPath:(NSString *)path isProtobuf:(BOOL)isProtobuf; - (NSUInteger)countOfEvents; @@ -32,8 +32,6 @@ - (BOOL)clearAllItems; -- (BOOL)cleanExpiredDataIfNeeded; - - (void)setEvent:(id)event forKey:(NSString *)key; - (NSArray> *)getEventsWithPackageNum:(NSUInteger)packageNum @@ -41,8 +39,8 @@ - (NSArray> *)getEventsWithPackageNum:(NSUInteger)packageNum; -+ (NSData *)buildRawEventsFromEvents:(NSArray> *)events; +- (NSData *)buildRawEventsFromEvents:(NSArray> *)events; -+ (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; +- (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; @end diff --git a/GrowingTrackerCore/Database/GrowingEventDatabase.m b/GrowingTrackerCore/Database/GrowingEventDatabase.m index d33b0b0dd..ee5f17054 100644 --- a/GrowingTrackerCore/Database/GrowingEventDatabase.m +++ b/GrowingTrackerCore/Database/GrowingEventDatabase.m @@ -28,6 +28,7 @@ @interface GrowingEventDatabase () @property (nonatomic, strong) id db; +@property (nonatomic, assign) BOOL isProtobuf; @property (nonatomic, strong) NSMutableArray *updateKeys; @property (nonatomic, strong) NSMutableArray *updateValues; @@ -39,18 +40,25 @@ @implementation GrowingEventDatabase { #pragma mark - Init -+ (instancetype)databaseWithPath:(NSString *)path { - return [[self alloc] initWithFilePath:path]; ++ (instancetype)databaseWithPath:(NSString *)path isProtobuf:(BOOL)isProtobuf { + return [[self alloc] initWithFilePath:path isProtobuf:isProtobuf]; } -- (instancetype)initWithFilePath:(NSString *)filePath { +- (instancetype)initWithFilePath:(NSString *)filePath isProtobuf:(BOOL)isProtobuf { if (self = [super init]) { _updateValues = [[NSMutableArray alloc] init]; _updateKeys = [[NSMutableArray alloc] init]; + _isProtobuf = isProtobuf; GROWING_LOCK_INIT(lock); - Class serviceClass = - [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingEventDatabaseService)]; + Class serviceClass = nil; + if (isProtobuf) { + serviceClass = + [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingPBEventDatabaseService)]; + } else { + serviceClass = + [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingEventDatabaseService)]; + } if (!serviceClass) { GIOLogError(@"-databaseWithPath: event database error : no event database service support"); return nil; @@ -61,6 +69,7 @@ - (instancetype)initWithFilePath:(NSString *)filePath { if (error) { [self handleDatabaseError:error]; } + [self cleanExpiredDataIfNeeded]; } return self; @@ -195,24 +204,12 @@ - (void)setEvent:(id)event forKey:(NSString *)k return events ?: [[NSArray alloc] init]; } -+ (NSData *)buildRawEventsFromEvents:(NSArray> *)events { - Class serviceClass = - [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingEventDatabaseService)]; - if (!serviceClass) { - return nil; - } - - return [serviceClass buildRawEventsFromEvents:events]; +- (NSData *)buildRawEventsFromEvents:(NSArray> *)events { + return [self.db buildRawEventsFromEvents:events]; } -+ (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { - Class serviceClass = - [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingEventDatabaseService)]; - if (!serviceClass) { - return nil; - } - - return [serviceClass persistenceEventWithEvent:event uuid:uuid]; +- (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { + return [self.db persistenceEventWithEvent:event uuid:uuid]; } #pragma mark - Perform Block diff --git a/GrowingTrackerCore/Event/GrowingEventChannel.h b/GrowingTrackerCore/Event/GrowingEventChannel.h index 319d40aa8..53a1475c8 100644 --- a/GrowingTrackerCore/Event/GrowingEventChannel.h +++ b/GrowingTrackerCore/Event/GrowingEventChannel.h @@ -19,31 +19,30 @@ #import +typedef NS_ENUM(NSUInteger, GrowingEventPersistenceType) { + GrowingEventPersistenceTypeJSON, + GrowingEventPersistenceTypeProtobuf, +}; + NS_ASSUME_NONNULL_BEGIN +@class GrowingEventDatabase; + @interface GrowingEventChannel : NSObject +@property (nonatomic, copy) NSString *name; @property (nonatomic, copy, nullable) NSArray *eventTypes; -@property (nonatomic, copy) NSString *urlTemplate; -@property (nonatomic, assign) BOOL isCustomEvent; +@property (nonatomic, assign) GrowingEventPersistenceType persistenceType; +@property (nonatomic, assign) BOOL isRealtimeEvent; @property (nonatomic, assign) BOOL isUploading; +@property (nonatomic, weak) GrowingEventDatabase *db; -- (instancetype)initWithTypes:(NSArray *_Nullable)eventTypes - urlTemplate:(NSString *)urlTemplate - isCustomEvent:(BOOL)isCustomEvent - isUploading:(BOOL)isUploading; ++ (instancetype)eventChannelWithName:(NSString *)name + eventTypes:(NSArray *_Nullable)eventTypes + persistenceType:(GrowingEventPersistenceType)persistenceType + isRealtimeEvent:(BOOL)isRealtimeEvent; -+ (instancetype)eventChannelWithEventTypes:(NSArray *_Nullable)eventTypes - urlTemplate:(NSString *)urlTemplate - isCustomEvent:(BOOL)isCustomEvent; -/// 所有的channels集合 + (NSMutableArray *)eventChannels; -/// 深拷贝Channels集合,并自动添加一个EventType为nil的Channels -+ (NSArray *)buildAllEventChannels; -/// 根据channels数组,返回 eventType 为key,channel对象为object的字典 -+ (NSDictionary *)eventChannelMapFromAllChannels:(NSArray *)channels; - -+ (GrowingEventChannel *)otherEventChannelFromAllChannels:(NSArray *)channels; @end diff --git a/GrowingTrackerCore/Event/GrowingEventChannel.m b/GrowingTrackerCore/Event/GrowingEventChannel.m index 35c234428..c9a2f5cf6 100644 --- a/GrowingTrackerCore/Event/GrowingEventChannel.m +++ b/GrowingTrackerCore/Event/GrowingEventChannel.m @@ -19,77 +19,66 @@ #import "GrowingTrackerCore/Event/GrowingEventChannel.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" -#import "GrowingTrackerCore/Network/Request/GrowingNetworkConfig.h" @implementation GrowingEventChannel -- (instancetype)initWithTypes:(NSArray *)eventTypes - urlTemplate:(NSString *)urlTemplate - isCustomEvent:(BOOL)isCustomEvent - isUploading:(BOOL)isUploading { +- (instancetype)initWithName:(NSString *)name + eventTypes:(NSArray *_Nullable)eventTypes + persistenceType:(GrowingEventPersistenceType)persistenceType + isRealtimeEvent:(BOOL)isRealtimeEvent + isUploading:(BOOL)isUploading { if (self = [super init]) { + _name = name; _eventTypes = eventTypes; - _urlTemplate = urlTemplate; - _isCustomEvent = isCustomEvent; + _persistenceType = persistenceType; + _isRealtimeEvent = isRealtimeEvent; _isUploading = isUploading; } return self; } -+ (instancetype)eventChannelWithEventTypes:(NSArray *)eventTypes - urlTemplate:(NSString *)urlTemplate - isCustomEvent:(BOOL)isCustomEvent { - return [[GrowingEventChannel alloc] initWithTypes:eventTypes - urlTemplate:urlTemplate - isCustomEvent:isCustomEvent - isUploading:NO]; ++ (instancetype)eventChannelWithName:(NSString *)name + eventTypes:(NSArray *_Nullable)eventTypes + persistenceType:(GrowingEventPersistenceType)persistenceType + isRealtimeEvent:(BOOL)isRealtimeEvent { + return [[GrowingEventChannel alloc] initWithName:name + eventTypes:eventTypes + persistenceType:persistenceType + isRealtimeEvent:isRealtimeEvent + isUploading:NO]; } static NSMutableArray *eventChannels = nil; - + (NSMutableArray *)eventChannels { if (!eventChannels) { eventChannels = [NSMutableArray array]; - [eventChannels addObject:[GrowingEventChannel eventChannelWithEventTypes:@[ - GrowingEventTypeVisit, - GrowingEventTypeAppClosed, - GrowingEventTypePage - ] - urlTemplate:kGrowingEventApiTemplate - isCustomEvent:NO]]; - [eventChannels addObject:[GrowingEventChannel eventChannelWithEventTypes:@[ - GrowingEventTypeCustom, - GrowingEventTypeConversionVariables, - GrowingEventTypeLoginUserAttributes, - GrowingEventTypeVisitorAttributes - ] - urlTemplate:kGrowingEventApiTemplate - isCustomEvent:YES]]; + NSArray *autotrackEventTypes = @[ + GrowingEventTypePage, + GrowingEventTypeViewClick, + GrowingEventTypeViewChange, + GrowingEventTypeAppClosed, + @"FORM_SUBMIT" /* GrowingEventTypeFormSubmit */ + ]; + NSArray *trackEventTypes = + @[GrowingEventTypeVisit, GrowingEventTypeCustom, GrowingEventTypeLoginUserAttributes]; + [eventChannels addObject:[GrowingEventChannel eventChannelWithName:@"Autotrack" + eventTypes:autotrackEventTypes + persistenceType:GrowingEventPersistenceTypeJSON + isRealtimeEvent:NO]]; + [eventChannels addObject:[GrowingEventChannel eventChannelWithName:@"Track" + eventTypes:trackEventTypes + persistenceType:GrowingEventPersistenceTypeJSON + isRealtimeEvent:YES]]; + [eventChannels addObject:[GrowingEventChannel eventChannelWithName:@"Autotrack-Protobuf" + eventTypes:autotrackEventTypes + persistenceType:GrowingEventPersistenceTypeProtobuf + isRealtimeEvent:NO]]; + [eventChannels addObject:[GrowingEventChannel eventChannelWithName:@"Track-Protobuf" + eventTypes:trackEventTypes + persistenceType:GrowingEventPersistenceTypeProtobuf + isRealtimeEvent:YES]]; } return eventChannels; } -+ (NSArray *)buildAllEventChannels { - NSMutableArray *channels = [[self eventChannels] mutableCopy]; - eventChannels = nil; - [channels addObject:[GrowingEventChannel eventChannelWithEventTypes:nil - urlTemplate:kGrowingEventApiTemplate - isCustomEvent:NO]]; - return channels; -} - -+ (NSDictionary *)eventChannelMapFromAllChannels:(NSArray *)channels { - NSMutableDictionary *dictM = [NSMutableDictionary dictionary]; - for (GrowingEventChannel *obj in channels) { - for (NSString *key in obj.eventTypes) { - [dictM setObject:obj forKey:key]; - } - } - return dictM; -} - -+ (GrowingEventChannel *)otherEventChannelFromAllChannels:(NSArray *)channels { - return channels.lastObject; -} - @end diff --git a/GrowingTrackerCore/Event/GrowingEventManager.h b/GrowingTrackerCore/Event/GrowingEventManager.h index b67d27484..55e61ae85 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.h +++ b/GrowingTrackerCore/Event/GrowingEventManager.h @@ -68,6 +68,8 @@ @interface GrowingEventManager : NSObject +@property (nonatomic, assign) GrowingEventPersistenceType persistenceType; + + (_Nonnull instancetype)sharedInstance; /// 配置事件管理者 diff --git a/GrowingTrackerCore/Event/GrowingEventManager.m b/GrowingTrackerCore/Event/GrowingEventManager.m index 08cd40342..16ab591f6 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.m +++ b/GrowingTrackerCore/Event/GrowingEventManager.m @@ -35,29 +35,25 @@ #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" -static const NSUInteger kGrowingMaxQueueSize = 10000; // default: max event queue size there are 10000 events -static const NSUInteger kGrowingFillQueueSize = 1000; // default: determine when event queue is filled from DB -static const NSUInteger kGrowingMaxDBCacheSize = 100; // default: write to DB as soon as there are 300 events -static const NSUInteger kGrowingMaxBatchSize = 500; // default: send no more than 500 events in every batch; - +static const NSUInteger kGrowingMaxDBCacheSize = 100; // default: write to DB as soon as there are 100 events +static const NSUInteger kGrowingMaxBatchSize = 500; // default: send no more than 500 events in every batch static const NSUInteger kGrowingUnit_MB = 1024 * 1024; @interface GrowingEventManager () @property (nonatomic, strong) NSHashTable *allInterceptor; -@property (nonatomic, strong) NSMutableArray> *eventQueue; @property (nonatomic, strong, readonly) NSArray *allEventChannels; -@property (nonatomic, strong, readonly) NSDictionary *eventChannelDict; -@property (nonatomic, strong, readonly) GrowingEventChannel *otherEventChannel; +@property (nonatomic, strong, readonly) NSDictionary *currentEventChannelMap; @property (nonatomic, strong) dispatch_source_t reportTimer; @property (nonatomic, strong) GrowingEventDatabase *timingEventDB; @property (nonatomic, strong) GrowingEventDatabase *realtimeEventDB; +@property (nonatomic, strong) GrowingEventDatabase *timingEventDB_PB; +@property (nonatomic, strong) GrowingEventDatabase *realtimeEventDB_PB; @property (nonatomic, assign) unsigned long long uploadEventSize; @property (nonatomic, assign) unsigned long long uploadLimitOfCellular; -@property (nonatomic, assign) NSUInteger packageNum; @end @@ -78,6 +74,7 @@ + (instancetype)sharedInstance { - (instancetype)init { if (self = [super init]) { _allInterceptor = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory]; + _persistenceType = GrowingEventPersistenceTypeProtobuf; } return self; } @@ -88,30 +85,54 @@ - (void)configManager { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ [GrowingDispatchManager dispatchInGrowingThread:^{ - self->_packageNum = kGrowingMaxBatchSize; // default is 10MB self->_uploadLimitOfCellular = [GrowingConfigurationManager sharedInstance].trackConfiguration.cellularDataLimit * kGrowingUnit_MB; - self->_timingEventDB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath]]; + self->_timingEventDB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath] + isProtobuf:NO]; + self->_timingEventDB_PB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath] + isProtobuf:YES]; self->_timingEventDB.autoFlushCount = kGrowingMaxDBCacheSize; - self->_realtimeEventDB = - [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getRealtimeDatabasePath]]; - // clean expired event data - [self cleanExpiredData_unsafe]; - // load eventQueue for the first time - [self reloadFromDB_unsafe]; + self->_timingEventDB_PB.autoFlushCount = kGrowingMaxDBCacheSize; + self->_realtimeEventDB = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getRealtimeDatabasePath] + isProtobuf:NO]; + self->_realtimeEventDB_PB = + [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getRealtimeDatabasePath] isProtobuf:YES]; + NSMutableArray *eventChannels = [GrowingEventChannel eventChannels]; for (NSObject *obj in self.allInterceptor) { if ([obj respondsToSelector:@selector(growingEventManagerChannels:)]) { - [obj growingEventManagerChannels:[GrowingEventChannel eventChannels]]; + [obj growingEventManagerChannels:eventChannels]; + } + } + for (GrowingEventChannel *ec in eventChannels) { + if (ec.isRealtimeEvent) { + if (ec.persistenceType == GrowingEventPersistenceTypeProtobuf) { + ec.db = self.realtimeEventDB_PB; + } else { + ec.db = self.realtimeEventDB; + } + } else { + if (ec.persistenceType == GrowingEventPersistenceTypeProtobuf) { + ec.db = self.timingEventDB_PB; + } else { + ec.db = self.timingEventDB; + } } } + self->_allEventChannels = eventChannels; - self->_allEventChannels = [GrowingEventChannel buildAllEventChannels]; - self->_eventChannelDict = [GrowingEventChannel eventChannelMapFromAllChannels:self->_allEventChannels]; - // all other events got to this category - self->_otherEventChannel = [GrowingEventChannel otherEventChannelFromAllChannels:self->_allEventChannels]; + NSMutableDictionary *dictM = [NSMutableDictionary dictionary]; + for (GrowingEventChannel *ec in eventChannels) { + if (ec.persistenceType != self->_persistenceType) { + continue; + } + for (NSString *key in ec.eventTypes) { + [dictM setObject:ec forKey:key]; + } + } + self->_currentEventChannelMap = dictM; }]; }); } @@ -170,7 +191,7 @@ - (void)postEventBuilder:(GrowingBaseBuilder *_Nullable)builder { [obj growingEventManagerEventWillBuild:builder]; } } - // TODO: active在page事件之后的情况处理,添加一个interceptor + GrowingBaseEvent *event = builder.build; for (NSObject *obj in self.allInterceptor) { @@ -193,9 +214,6 @@ - (void)postEventBuilder:(GrowingBaseBuilder *_Nullable)builder { - (void)sendAllChannelEvents { [GrowingDispatchManager dispatchInGrowingThread:^{ [self flushDB]; - if (!self.allEventChannels) { - return; - } for (GrowingEventChannel *channel in self.allEventChannels) { [self sendEventsOfChannel_unsafe:channel]; } @@ -213,11 +231,7 @@ - (void)sendEventsInstantWithChannel:(GrowingEventChannel *)channel { - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { NSString *projectId = GrowingConfigurationManager.sharedInstance.trackConfiguration.projectId; if (projectId.length == 0) { - GIOLogError(@"No valid ProjectId (channel = %zd).", [self.allEventChannels indexOfObject:channel]); - return; - } - - if (!channel.isCustomEvent && self.eventQueue.count == 0) { + GIOLogError(@"No valid ProjectId (channel = %@).", channel.name); return; } @@ -230,8 +244,7 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { // 没网络 直接返回 if (![GrowingNetworkInterfaceManager sharedInstance].isReachable) { // 没网络 直接返回 - GIOLogDebug(@"No availabel Internet connection, delay upload (channel = %zd).", - [self.allEventChannels indexOfObject:channel]); + GIOLogDebug(@"No availabel Internet connection, delay upload (channel = %@).", channel.name); return; } NSUInteger policyMask = GrowingEventSendPolicyInstant; @@ -240,13 +253,11 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { } else if ([GrowingNetworkInterfaceManager sharedInstance].WWANValid) { if (self.uploadEventSize < self.uploadLimitOfCellular) { - GIOLogDebug(@"Upload key data with mobile network (channel = %zd).", - [self.allEventChannels indexOfObject:channel]); + GIOLogDebug(@"Upload key data with mobile network (channel = %@).", channel.name); policyMask = GrowingEventSendPolicyInstant | GrowingEventSendPolicyMobileData; isViaCellular = YES; } else { - GIOLogDebug(@"Mobile network is forbidden. upload later (channel = %zd).", - [self.allEventChannels indexOfObject:channel]); + GIOLogDebug(@"Mobile network is forbidden. upload later (channel = %@).", channel.name); // 实时发送策略无视流量限制 policyMask = GrowingEventSendPolicyInstant; } @@ -278,7 +289,7 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { } } - NSData *rawEvents = [GrowingEventDatabase buildRawEventsFromEvents:events]; + NSData *rawEvents = [channel.db buildRawEventsFromEvents:events]; if (!eventRequest) { eventRequest = [[GrowingEventRequest alloc] initWithEvents:rawEvents]; } else { @@ -318,12 +329,8 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { channel.isUploading = NO; // 如果剩余数量 大于单包数量 则直接发送 - if (channel.isCustomEvent && self.realtimeEventDB.countOfEvents >= self.packageNum) { - [self sendAllChannelEvents]; - } - - if (!channel.isCustomEvent && self.eventQueue.count >= self.packageNum) { - [self sendAllChannelEvents]; + if (channel.db.countOfEvents >= kGrowingMaxBatchSize) { + [self sendEventsInstantWithChannel:channel]; } }]; } else { @@ -336,19 +343,6 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { #pragma mark Event Persist -- (void)loadFromDB_unsafe { - NSInteger keyCount = self.timingEventDB.countOfEvents; - NSInteger qCount = self.eventQueue.count; - - if (self.eventQueue && qCount == keyCount) { - return; - } - - self.eventQueue = [[NSMutableArray alloc] init]; - NSArray *array = [self.timingEventDB getEventsWithPackageNum:kGrowingMaxQueueSize]; - [self.eventQueue addObjectsFromArray:array]; -} - - (void)writeToDatabaseWithEvent:(GrowingBaseEvent *)event { GIOLogDebug(@"save: event, type is %@\n%@", event.eventType, @@ -359,20 +353,11 @@ - (void)writeToDatabaseWithEvent:(GrowingBaseEvent *)event { return; } - GrowingEventChannel *eventChannel = self.eventChannelDict[eventType] ?: self.otherEventChannel; - BOOL isCustomEvent = eventChannel.isCustomEvent; + GrowingEventChannel *eventChannel = self.currentEventChannelMap[eventType]; NSString *uuidString = [NSUUID UUID].UUIDString; - id waitForPersist = [GrowingEventDatabase persistenceEventWithEvent:event - uuid:uuidString]; - - if (!isCustomEvent) // custom event never goes into self.eventQueue, event can not be nil - { - [self.eventQueue addObject:waitForPersist]; - } - - GrowingEventDatabase *db = (isCustomEvent ? self.realtimeEventDB : self.timingEventDB); - - [db setEvent:waitForPersist forKey:uuidString]; + id waitForPersist = [eventChannel.db persistenceEventWithEvent:event + uuid:uuidString]; + [eventChannel.db setEvent:waitForPersist forKey:uuidString]; BOOL debugEnabled = GrowingConfigurationManager.sharedInstance.trackConfiguration.debugEnabled; if (GrowingEventSendPolicyInstant & event.sendPolicy || debugEnabled) { // send event instantly @@ -382,73 +367,19 @@ - (void)writeToDatabaseWithEvent:(GrowingBaseEvent *)event { - (void)flushDB { [self.timingEventDB flush]; + [self.timingEventDB_PB flush]; } - (void)removeEvents_unsafe:(NSArray<__kindof id> *)events forChannel:(GrowingEventChannel *)channel { - if (channel.isCustomEvent) { - for (NSInteger i = 0; i < events.count; i++) { - [self.realtimeEventDB setEvent:nil forKey:events[i].eventUUID]; - } - - } else { - [self.eventQueue removeObjectsInArray:events]; - - for (NSInteger i = 0; i < events.count; i++) { - [self.timingEventDB setEvent:nil forKey:events[i].eventUUID]; - } - - if (self.eventQueue.count <= kGrowingFillQueueSize) { - [self loadFromDB_unsafe]; - } + for (NSInteger i = 0; i < events.count; i++) { + [channel.db setEvent:nil forKey:events[i].eventUUID]; } } - (NSArray> *)getEventsToBeUploadUnsafe:(GrowingEventChannel *)channel policy:(NSUInteger)mask { - if (channel.isCustomEvent) { - return [self.realtimeEventDB getEventsWithPackageNum:self.packageNum policy:mask]; - } else { - NSMutableArray> *events = - [[NSMutableArray alloc] initWithCapacity:self.eventQueue.count]; - NSArray *eventTypes = channel.eventTypes; - const NSUInteger eventTypesCount = eventTypes.count; - NSUInteger count = 0; - for (id e in self.eventQueue) { - if (e.policy & mask) { - NSString *type = e.eventType; - // 反向匹配(排除法)event of other type not match eventChannelDict`s all type - if ((eventTypesCount == 0 && self.eventChannelDict[type] == nil) || - (eventTypesCount > 0 && [eventTypes indexOfObject:type] != NSNotFound)) // 正向匹配 - { - [events addObject:e]; - count++; - if (count >= self.packageNum) { - break; - } - } - } - } - return events; - } -} - -- (void)cleanExpiredData_unsafe { - [self.timingEventDB cleanExpiredDataIfNeeded]; - [self.realtimeEventDB cleanExpiredDataIfNeeded]; -} - -- (void)reloadFromDB_unsafe { - self.eventQueue = nil; - [self loadFromDB_unsafe]; -} - -- (void)clearAllEvents { - self.eventQueue = [[NSMutableArray alloc] init]; - [GrowingDispatchManager dispatchInGrowingThread:^() { - [self.timingEventDB clearAllItems]; - [self.realtimeEventDB clearAllItems]; - }]; + return [channel.db getEventsWithPackageNum:kGrowingMaxBatchSize policy:mask]; } #pragma mark Event Log @@ -459,7 +390,7 @@ - (void)prettyLogForEvents:(NSArray> *)event for (id event in events) { [arrayM addObject:event.toJSONObject]; } - GIOLogVerbose(@"(channel = %@, events = %@)\n", channel.urlTemplate, arrayM); + GIOLogVerbose(@"(channel = %@, events = %@)\n", channel.name, arrayM); } #pragma mark - Interceptor diff --git a/GrowingTrackerCore/Public/GrowingEventDatabaseService.h b/GrowingTrackerCore/Public/GrowingEventDatabaseService.h index 363e517b2..49d8226c2 100644 --- a/GrowingTrackerCore/Public/GrowingEventDatabaseService.h +++ b/GrowingTrackerCore/Public/GrowingEventDatabaseService.h @@ -47,12 +47,12 @@ extern NSString *const GrowingEventDatabaseErrorDomain; /// 生成事件数组的二进制数据 /// @param events 事件数据数组 -+ (NSData *)buildRawEventsFromEvents:(NSArray> *)events; +- (NSData *)buildRawEventsFromEvents:(NSArray> *)events; /// 生成持久化事件对象 /// @param event 事件数据 /// @param uuid 唯一key -+ (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; +- (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; /// 获取已存储的事件数量 /// @return 事件数量,大于等于0;若返回值为-1,表示读取错误 @@ -106,4 +106,8 @@ extern NSString *const GrowingEventDatabaseErrorDomain; @end +@protocol GrowingPBEventDatabaseService + +@end + NS_ASSUME_NONNULL_END diff --git a/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h b/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h index dfe030ea0..5d0116954 100644 --- a/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h +++ b/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h @@ -26,12 +26,18 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *eventUUID; @property (nonatomic, copy, readonly) NSString *eventType; +@property (nonatomic, strong, readonly) id data; @property (nonatomic, assign, readonly) GrowingEventSendPolicy policy; + (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; + (NSData *)buildRawEventsFromEvents:(NSArray> *)events; +- (instancetype)initWithUUID:(NSString *)uuid + eventType:(NSString *)eventType + data:(id)data + policy:(GrowingEventSendPolicy)policy; + - (id)toJSONObject; - (void)appendExtraParams:(NSDictionary *)extraParams; diff --git a/Modules/Advert/GrowingAdvertising.m b/Modules/Advert/GrowingAdvertising.m index d7990d0c8..9b64a69c2 100644 --- a/Modules/Advert/GrowingAdvertising.m +++ b/Modules/Advert/GrowingAdvertising.m @@ -105,9 +105,10 @@ - (BOOL)growingHandlerUrl:(NSURL *)url { #pragma mark - GrowingEventInterceptor - (void)growingEventManagerChannels:(NSMutableArray *)channels { - [channels addObject:[GrowingEventChannel eventChannelWithEventTypes:@[GrowingEventTypeActivate] - urlTemplate:kGrowingEventApiTemplate - isCustomEvent:NO]]; + [channels addObject:[GrowingEventChannel eventChannelWithName:@"Advert" + eventTypes:@[GrowingEventTypeActivate] + persistenceType:GrowingEventManager.sharedInstance.persistenceType + isRealtimeEvent:YES]]; } #pragma mark - GrowingULAppLifecycleDelegate diff --git a/Modules/Protobuf/GrowingEventProtobufDatabase.h b/Modules/Protobuf/GrowingEventProtobufDatabase.h index e7990ed62..8ebc5908f 100644 --- a/Modules/Protobuf/GrowingEventProtobufDatabase.h +++ b/Modules/Protobuf/GrowingEventProtobufDatabase.h @@ -18,16 +18,11 @@ // limitations under the License. #import -#import "GrowingEventDatabaseService.h" +#import "Services/Database/GrowingEventFMDatabase.h" NS_ASSUME_NONNULL_BEGIN -@class GrowingFMDatabaseQueue; - -@interface GrowingEventProtobufDatabase : NSObject - -@property (nonatomic, strong) GrowingFMDatabaseQueue *db; -@property (nonatomic, strong) NSError *databaseError; +@interface GrowingEventProtobufDatabase : GrowingEventFMDatabase @end diff --git a/Modules/Protobuf/GrowingEventProtobufDatabase.m b/Modules/Protobuf/GrowingEventProtobufDatabase.m index 1e923aefd..a95892e33 100644 --- a/Modules/Protobuf/GrowingEventProtobufDatabase.m +++ b/Modules/Protobuf/GrowingEventProtobufDatabase.m @@ -18,438 +18,47 @@ // limitations under the License. #import "Modules/Protobuf/GrowingEventProtobufDatabase.h" -#import "GrowingULTimeUtil.h" #import "Modules/Protobuf/GrowingEventProtobufPersistence.h" #import "Services/Database/FMDB/GrowingFMDB.h" - -@interface GrowingEventProtobufDatabase () - -@property (nonatomic, copy, readonly) NSString *lastPathComponent; - -@end +#import "Services/Database/GrowingEventFMDatabase+Private.h" @implementation GrowingEventProtobufDatabase #pragma mark - Init + (instancetype)databaseWithPath:(NSString *)path error:(NSError **)error { - return [[self alloc] initWithFilePath:path error:error]; -} - -- (instancetype)initWithFilePath:(NSString *)filePath error:(NSError **)error { - if (self = [super init]) { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - [self makeDirByFileName:filePath]; - }); - - NSString *lastPathComponent = [NSURL fileURLWithPath:filePath].lastPathComponent; - _lastPathComponent = [NSString stringWithFormat:@"enc_%@", lastPathComponent]; - NSURL *url = [NSURL fileURLWithPath:filePath].URLByDeletingLastPathComponent; - NSString *path = [url URLByAppendingPathComponent:_lastPathComponent].path; - - self.db = [GrowingFMDatabaseQueue databaseQueueWithPath:path]; - if (!self.db) { - self.databaseError = [self createDBErrorInDatabase:nil]; - } else { - [self initDB]; - } - - if (error) { - *error = self.databaseError; - } - } - - return self; -} - -#pragma mark - Public Methods - -+ (NSData *)buildRawEventsFromEvents:(NSArray *)events { - return [GrowingEventProtobufPersistence buildRawEventsFromEvents:events]; -} - -+ (GrowingEventProtobufPersistence *)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { - return [GrowingEventProtobufPersistence persistenceEventWithEvent:event uuid:uuid]; -} - -- (NSInteger)countOfEvents { - __block NSInteger count = 0; - [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { - if (error) { - self.databaseError = error; - count = -1; - return; - } - - GrowingFMResultSet *set = [db executeQuery:@"SELECT COUNT(*) FROM namedcachetable"]; - if (!set) { - self.databaseError = [self readErrorInDatabase:db]; - count = -1; - return; - } - - if ([set next]) { - count = (NSUInteger)[set longLongIntForColumnIndex:0]; - } - - [set close]; - }]; - - return count; -} - -- (nullable NSArray *)getEventsByCount:(NSUInteger)count { - if (self.countOfEvents == 0) { - return [[NSArray alloc] init]; - } - - NSMutableArray *events = [[NSMutableArray alloc] init]; - [self enumerateKeysAndValuesUsingBlock:^(NSString *key, - NSData *value, - NSString *type, - NSUInteger policy, - BOOL *stop) { - GrowingEventProtobufPersistence *event = [[GrowingEventProtobufPersistence alloc] initWithUUID:key - eventType:type - data:value - policy:policy]; - [events addObject:event]; - if (events.count >= count) { - *stop = YES; - } - }]; - - return events.count != 0 ? events : nil; -} - -- (nullable NSArray *)getEventsByCount:(NSUInteger)count policy:(NSUInteger)mask { - if (self.countOfEvents == 0) { - return [[NSArray alloc] init]; - } - - NSMutableArray *events = [[NSMutableArray alloc] init]; - [self enumerateKeysAndValuesUsingBlock:^(NSString *key, - NSData *value, - NSString *type, - NSUInteger policy, - BOOL *stop) { - if (mask & policy) { - GrowingEventProtobufPersistence *event = [[GrowingEventProtobufPersistence alloc] initWithUUID:key - eventType:type - data:value - policy:policy]; - [events addObject:event]; - if (events.count >= count) { - *stop = YES; - } - } - }]; - - return events.count != 0 ? events : nil; -} - -- (BOOL)insertEvent:(GrowingEventProtobufPersistence *)event { - __block BOOL result = NO; - [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - result = [db executeUpdate:@"INSERT INTO namedcachetable(key,value,createAt,type,policy) VALUES(?,?,?,?,?)", - event.eventUUID, - ((GrowingEventProtobufPersistence *)event).data, - @([GrowingULTimeUtil currentTimeMillis]), - event.eventType, - @(event.policy)]; - - if (!result) { - self.databaseError = [self writeErrorInDatabase:db]; - } - }]; - - return result; -} - -- (BOOL)insertEvents:(NSArray *)events { - if (!events || events.count == 0) { - return YES; - } - - __block BOOL result = NO; - [self performTransactionBlock:^(GrowingFMDatabase *db, BOOL *rollback, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - for (int i = 0; i < events.count; i++) { - GrowingEventProtobufPersistence *event = (GrowingEventProtobufPersistence *)events[i]; - result = [db executeUpdate:@"INSERT INTO namedcachetable(key,value,createAt,type,policy) VALUES(?,?,?,?,?)", - event.eventUUID, - event.data, - @([GrowingULTimeUtil currentTimeMillis]), - event.eventType, - @(event.policy)]; - - if (!result) { - self.databaseError = [self writeErrorInDatabase:db]; - break; - } - } - }]; - - return result; -} - -- (BOOL)deleteEvent:(NSString *)key { - __block BOOL result = NO; - [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - result = [db executeUpdate:@"DELETE FROM namedcachetable WHERE key=?;", key]; - - if (!result) { - self.databaseError = [self writeErrorInDatabase:db]; - } - }]; - - return result; -} - -- (BOOL)deleteEvents:(NSArray *)keys { - if (!keys || keys.count == 0) { - return YES; - } - - __block BOOL result = NO; - [self performTransactionBlock:^(GrowingFMDatabase *db, BOOL *rollback, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - - for (NSString *key in keys) { - result = [db executeUpdate:@"DELETE FROM namedcachetable WHERE key=?;", key]; - if (!result) { - self.databaseError = [self writeErrorInDatabase:db]; - break; - } - } - }]; - - return result; -} - -- (BOOL)clearAllEvents { - __block BOOL result = NO; - [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - result = [db executeUpdate:@"DELETE FROM namedcachetable"]; - if (!result) { - self.databaseError = [self writeErrorInDatabase:db]; - } - }]; - - return result; -} - -- (BOOL)cleanExpiredEventIfNeeded { - NSNumber *now = [NSNumber numberWithLongLong:([[NSDate date] timeIntervalSince1970] * 1000LL)]; - NSNumber *sevenDayBefore = [NSNumber numberWithLongLong:(now.longLongValue - GrowingEventDatabaseExpirationTime)]; + NSString *lastPathComponent = [NSURL fileURLWithPath:path].lastPathComponent; + lastPathComponent = [NSString stringWithFormat:@"enc_%@", lastPathComponent]; + NSURL *url = [NSURL fileURLWithPath:path].URLByDeletingLastPathComponent; + path = [url URLByAppendingPathComponent:lastPathComponent].path; - __block BOOL result = NO; - [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - result = [db executeUpdate:@"DELETE FROM namedcachetable WHERE createAt<=?;", sevenDayBefore]; - if (!result) { - self.databaseError = [self writeErrorInDatabase:db]; - } - }]; - - return result; -} - -- (NSError *)lastError { - return self.databaseError; + return [super databaseWithPath:path persistenceClass:GrowingEventProtobufPersistence.class error:error]; } #pragma mark - Private Methods - (BOOL)initDB { - __block BOOL result = NO; - [self performTransactionBlock:^(GrowingFMDatabase *db, BOOL *rollback, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - - NSString *sql = - @"CREATE TABLE IF NOT EXISTS namedcachetable(" - @"id INTEGER PRIMARY KEY," - @"key TEXT," - @"value BLOB," - @"createAt INTEGER NOT NULL," - @"type TEXT," - @"policy INTEGER);"; - NSString *sqlCreateIndexKey = @"CREATE INDEX IF NOT EXISTS namedcachetable_key ON namedcachetable (key);"; - if (![db executeUpdate:sql]) { - self.databaseError = [self createDBErrorInDatabase:db]; - return; - } - if (![db executeUpdate:sqlCreateIndexKey]) { - self.databaseError = [self createDBErrorInDatabase:db]; - return; - } - result = YES; - }]; - - if (result) { - return [self vacuum]; - } else { - return result; - } -} - -- (BOOL)vacuum { - if (!isExecuteVacuum(self.lastPathComponent)) { - return YES; - } - - __block BOOL result = NO; - [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - result = [db executeUpdate:@"VACUUM namedcachetable"]; - if (!result) { - self.databaseError = [self writeErrorInDatabase:db]; - } - }]; - - return result; -} - -static BOOL isExecuteVacuum(NSString *name) { - if (name.length == 0) { - return NO; - } - NSString *vacuumDate = - [NSString stringWithFormat:@"GIO_VACUUM_DATE_E7B96C4E-6EE2-49CD-87F0-B2E62D4EE96A-ENCODE-%@", name]; - NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; - NSDate *beforeDate = [userDefault objectForKey:vacuumDate]; - NSDate *nowDate = [NSDate date]; - - if (beforeDate) { - NSDateComponents *delta = [[NSCalendar currentCalendar] components:NSCalendarUnitDay - fromDate:beforeDate - toDate:nowDate - options:0]; - BOOL flag = delta.day > 7 || delta.day < 0; - if (flag) { - [userDefault setObject:nowDate forKey:vacuumDate]; - [userDefault synchronize]; - } - return flag; - } else { - [userDefault setObject:nowDate forKey:vacuumDate]; - [userDefault synchronize]; - return YES; - } -} - -- (void)makeDirByFileName:(NSString *)filePath { - [[NSFileManager defaultManager] createDirectoryAtPath:[filePath stringByDeletingLastPathComponent] - withIntermediateDirectories:YES - attributes:nil - error:nil]; + NSString *sqlInit = + @"CREATE TABLE IF NOT EXISTS namedcachetable(" + @"id INTEGER PRIMARY KEY," + @"key TEXT," + @"value BLOB," + @"createAt INTEGER NOT NULL," + @"type TEXT," + @"policy INTEGER);"; + NSString *sqlCreateIndex = @"CREATE INDEX IF NOT EXISTS namedcachetable_key ON namedcachetable (key);"; + return [self initDB:sqlInit createIndex:sqlCreateIndex]; } - (void)enumerateKeysAndValuesUsingBlock: - (void (^)(NSString *key, NSData *value, NSString *type, NSUInteger policy, BOOL *stop))block { - if (!block) { - return; - } - - [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { - if (error) { - self.databaseError = error; - return; - } - GrowingFMResultSet *set = [db executeQuery:@"SELECT * FROM namedcachetable ORDER BY id ASC"]; - if (!set) { - self.databaseError = [self readErrorInDatabase:db]; - return; - } - - BOOL stop = NO; - while (!stop && [set next]) { - NSString *key = [set stringForColumn:@"key"]; - NSData *value = [set dataForColumn:@"value"]; - NSString *type = [set stringForColumn:@"type"]; - NSUInteger policy = [set intForColumn:@"policy"]; - block(key, value, type, policy, &stop); - } - - [set close]; - }]; -} - -#pragma mark - Perform Block - -- (void)performDatabaseBlock:(void (^)(GrowingFMDatabase *db, NSError *error))block { - [self.db inDatabase:^(GrowingFMDatabase *db) { - if (!db) { - block(db, [self openErrorInDatabase:db]); - } else { - block(db, nil); - } + (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop))block { + [self enumerateTableUsingBlock:^(GrowingFMResultSet *set, BOOL *s) { + NSString *key = [set stringForColumn:@"key"]; + id value = [set dataForColumn:@"value"]; + NSString *type = [set stringForColumn:@"type"]; + NSUInteger policy = [set intForColumn:@"policy"]; + block(key, value, type, policy, &s); }]; } -- (void)performTransactionBlock:(void (^)(GrowingFMDatabase *db, BOOL *rollback, NSError *error))block { - [self.db inTransaction:^(GrowingFMDatabase *db, BOOL *rollback) { - if (!db) { - block(db, rollback, [self openErrorInDatabase:db]); - } else { - block(db, rollback, nil); - } - }]; -} - -#pragma mark - Error - -- (NSError *)openErrorInDatabase:(GrowingFMDatabase *)db { - return [NSError errorWithDomain:GrowingEventDatabaseErrorDomain - code:GrowingEventDatabaseOpenError - userInfo:@{NSLocalizedDescriptionKey: @"open database error"}]; -} - -- (NSError *)readErrorInDatabase:(GrowingFMDatabase *)db { - return [NSError errorWithDomain:GrowingEventDatabaseErrorDomain - code:GrowingEventDatabaseReadError - userInfo:@{NSLocalizedDescriptionKey: ([db lastErrorMessage] ?: @"")}]; -} - -- (NSError *)writeErrorInDatabase:(GrowingFMDatabase *)db { - return [NSError errorWithDomain:GrowingEventDatabaseErrorDomain - code:GrowingEventDatabaseWriteError - userInfo:@{NSLocalizedDescriptionKey: ([db lastErrorMessage] ?: @"")}]; -} - -- (NSError *)createDBErrorInDatabase:(GrowingFMDatabase *)db { - return - [NSError errorWithDomain:GrowingEventDatabaseErrorDomain - code:GrowingEventDatabaseCreateDBError - userInfo:@{NSLocalizedDescriptionKey: ([db lastErrorMessage] ?: @"Could not create database")}]; -} - @end diff --git a/Modules/Protobuf/GrowingEventProtobufPersistence.h b/Modules/Protobuf/GrowingEventProtobufPersistence.h index ee2110f84..bb38c650e 100644 --- a/Modules/Protobuf/GrowingEventProtobufPersistence.h +++ b/Modules/Protobuf/GrowingEventProtobufPersistence.h @@ -28,18 +28,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *eventUUID; @property (nonatomic, copy, readonly) NSString *eventType; -@property (nonatomic, strong, readonly) NSData *data; +@property (nonatomic, strong, readonly) id data; @property (nonatomic, assign, readonly) GrowingEventSendPolicy policy; -- (instancetype)initWithUUID:(NSString *)uuid - eventType:(NSString *)eventType - data:(NSData *)data - policy:(GrowingEventSendPolicy)policy; - -+ (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; - -+ (NSData *)buildRawEventsFromEvents:(NSArray *)events; - @end NS_ASSUME_NONNULL_END diff --git a/Modules/Protobuf/GrowingEventProtobufPersistence.m b/Modules/Protobuf/GrowingEventProtobufPersistence.m index e9ce9ae2f..b24be03c2 100644 --- a/Modules/Protobuf/GrowingEventProtobufPersistence.m +++ b/Modules/Protobuf/GrowingEventProtobufPersistence.m @@ -41,7 +41,7 @@ @implementation GrowingEventProtobufPersistence - (instancetype)initWithUUID:(NSString *)uuid eventType:(NSString *)eventType - data:(NSData *)data + data:(id)data policy:(GrowingEventSendPolicy)policy { if (self = [super init]) { _eventUUID = uuid; diff --git a/Modules/Protobuf/GrowingProtobufModule.m b/Modules/Protobuf/GrowingProtobufModule.m index d80b94f86..940d07562 100644 --- a/Modules/Protobuf/GrowingProtobufModule.m +++ b/Modules/Protobuf/GrowingProtobufModule.m @@ -23,13 +23,12 @@ #import "Modules/Protobuf/GrowingEventRequestProtobufAdapter.h" GrowingMod(GrowingProtobufModule) +GrowingService(GrowingPBEventDatabaseService, GrowingEventProtobufDatabase) @implementation GrowingProtobufModule - (void)growingModInit:(GrowingContext *)context { [GrowingEventRequestAdapters.sharedInstance addAdapter:GrowingEventRequestProtobufAdapter.class]; - [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventProtobufDatabase.class]; } @end diff --git a/Podfile.lock b/Podfile.lock index e05bcd2c2..d2bfc00f7 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -9,6 +9,7 @@ PODS: - GrowingAnalytics/DefaultServices (= 3.5.0) - GrowingAnalytics/Hybrid (= 3.5.0) - GrowingAnalytics/MobileDebugger (= 3.5.0) + - GrowingAnalytics/Protobuf (= 3.5.0) - GrowingAnalytics/WebCircle (= 3.5.0) - GrowingAnalytics/AutotrackerCore (3.5.0): - GrowingAnalytics/TrackerCore (= 3.5.0) @@ -48,6 +49,7 @@ PODS: - GrowingAnalytics/Tracker (3.5.0): - GrowingAnalytics/DefaultServices (= 3.5.0) - GrowingAnalytics/MobileDebugger (= 3.5.0) + - GrowingAnalytics/Protobuf (= 3.5.0) - GrowingAnalytics/TrackerCore (= 3.5.0) - GrowingAnalytics/TrackerCore (3.5.0): - GrowingUtils/TrackerCore (= 0.0.5) @@ -150,7 +152,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: f51d83c651a545a18f3642df92c722350de286ac + GrowingAnalytics: 88f565a894472016ecd0c1354c231bd7896f13f5 GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 9c0d6e41c9678397dbaa3304b1738a2867b023ae GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 diff --git a/Services/Database/GrowingEventFMDatabase+Private.h b/Services/Database/GrowingEventFMDatabase+Private.h new file mode 100644 index 000000000..1022e9eb4 --- /dev/null +++ b/Services/Database/GrowingEventFMDatabase+Private.h @@ -0,0 +1,32 @@ +// +// GrowingEventFMDatabase+Private.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/8/7. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "Services/Database/GrowingEventFMDatabase.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingEventFMDatabase (Private) + ++ (instancetype)databaseWithPath:(NSString *)path persistenceClass:(Class)cls error:(NSError **)error; +- (BOOL)initDB:(NSString *)sqlInit createIndex:(NSString *)sqlCreateIndex; +- (void)enumerateTableUsingBlock:(void (^)(GrowingFMResultSet *set, BOOL *stop))block; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Services/Database/GrowingEventFMDatabase.m b/Services/Database/GrowingEventFMDatabase.m index 4f7cd5d41..92a05315d 100644 --- a/Services/Database/GrowingEventFMDatabase.m +++ b/Services/Database/GrowingEventFMDatabase.m @@ -19,17 +19,14 @@ #import "Services/Database/GrowingEventFMDatabase.h" #import "GrowingTrackerCore/FileStorage/GrowingFileStorage.h" +#import "GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h" #import "GrowingULTimeUtil.h" #import "Services/Database/FMDB/GrowingFMDB.h" -#import "Services/Database/GrowingEventJSONPersistence.h" - -GrowingService(GrowingEventDatabaseService, GrowingEventFMDatabase) - -#define VACUUM_DATE(name) [NSString stringWithFormat:@"GIO_VACUUM_DATE_E7B96C4E-6EE2-49CD-87F0-B2E62D4EE96A-%@", name] @interface GrowingEventFMDatabase () -@property (nonatomic, copy, readonly) NSString *name; +@property (nonatomic, copy, readonly) NSString *lastPathComponent; +@property (nonatomic, strong) Class persistenceClass; @end @@ -38,22 +35,25 @@ @implementation GrowingEventFMDatabase #pragma mark - Init + (instancetype)databaseWithPath:(NSString *)path error:(NSError **)error { - return [[self alloc] initWithFilePath:path error:error]; + @throw [NSException + exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + ++ (instancetype)databaseWithPath:(NSString *)path persistenceClass:(Class)cls error:(NSError **)error { + return [[self alloc] initWithFilePath:path persistenceClass:cls error:error]; } -- (instancetype)initWithFilePath:(NSString *)filePath error:(NSError **)error { +- (instancetype)initWithFilePath:(NSString *)filePath persistenceClass:(Class)cls error:(NSError **)error { if (self = [super init]) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ [self makeDirByFileName:filePath]; }); - if ([filePath isEqualToString:[GrowingFileStorage getTimingDatabasePath]]) { - _name = @"growingtimingevent"; - } else if ([filePath isEqualToString:[GrowingFileStorage getRealtimeDatabasePath]]) { - _name = @"growingrealtimevent"; - } - + _lastPathComponent = [NSURL fileURLWithPath:filePath].lastPathComponent; + _persistenceClass = cls; _db = [GrowingFMDatabaseQueue databaseQueueWithPath:filePath]; if (!_db) { _databaseError = [self createDBErrorInDatabase:nil]; @@ -71,12 +71,12 @@ - (instancetype)initWithFilePath:(NSString *)filePath error:(NSError **)error { #pragma mark - Public Methods -+ (NSData *)buildRawEventsFromEvents:(NSArray *)events { - return [GrowingEventJSONPersistence buildRawEventsFromEvents:events]; +- (NSData *)buildRawEventsFromEvents:(NSArray> *)events { + return [self.persistenceClass buildRawEventsFromEvents:events]; } -+ (GrowingEventJSONPersistence *)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { - return [GrowingEventJSONPersistence persistenceEventWithEvent:event uuid:uuid]; +- (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { + return [self.persistenceClass persistenceEventWithEvent:event uuid:uuid]; } - (NSInteger)countOfEvents { @@ -87,9 +87,7 @@ - (NSInteger)countOfEvents { count = -1; return; } - GrowingFMResultSet *set = [db executeQuery:@"select count(*) from namedcachetable where name=?" - values:@[self.name] - error:nil]; + GrowingFMResultSet *set = [db executeQuery:@"SELECT COUNT(*) FROM namedcachetable"]; if (!set) { self.databaseError = [self readErrorInDatabase:db]; count = -1; @@ -106,49 +104,41 @@ - (NSInteger)countOfEvents { return count; } -- (nullable NSArray *)getEventsByCount:(NSUInteger)count { +- (nullable NSArray> *)getEventsByCount:(NSUInteger)count { if (self.countOfEvents == 0) { return [[NSArray alloc] init]; } - NSMutableArray *events = [[NSMutableArray alloc] init]; - [self enumerateKeysAndValuesUsingBlock:^(NSString *key, - NSString *value, - NSString *type, - NSUInteger policy, - BOOL *stop) { - GrowingEventJSONPersistence *event = [[GrowingEventJSONPersistence alloc] initWithUUID:key - eventType:type - jsonString:value - policy:policy]; + NSMutableArray> *events = [[NSMutableArray alloc] init]; + [self enumerateKeysAndValuesUsingBlock:^(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop) { + id event = [[self.persistenceClass alloc] initWithUUID:key + eventType:type + data:value + policy:policy]; [events addObject:event]; if (events.count >= count) { - *stop = YES; + **stop = YES; } }]; return events.count != 0 ? events : nil; } -- (nullable NSArray *)getEventsByCount:(NSUInteger)count policy:(NSUInteger)mask { +- (nullable NSArray> *)getEventsByCount:(NSUInteger)count policy:(NSUInteger)mask { if (self.countOfEvents == 0) { return [[NSArray alloc] init]; } - NSMutableArray *events = [[NSMutableArray alloc] init]; - [self enumerateKeysAndValuesUsingBlock:^(NSString *key, - NSString *value, - NSString *type, - NSUInteger policy, - BOOL *stop) { + NSMutableArray> *events = [[NSMutableArray alloc] init]; + [self enumerateKeysAndValuesUsingBlock:^(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop) { if (mask & policy) { - GrowingEventJSONPersistence *event = [[GrowingEventJSONPersistence alloc] initWithUUID:key - eventType:type - jsonString:value - policy:policy]; + id event = [[self.persistenceClass alloc] initWithUUID:key + eventType:type + data:value + policy:policy]; [events addObject:event]; if (events.count >= count) { - *stop = YES; + **stop = YES; } } }]; @@ -156,21 +146,19 @@ - (NSInteger)countOfEvents { return events.count != 0 ? events : nil; } -- (BOOL)insertEvent:(GrowingEventJSONPersistence *)event { +- (BOOL)insertEvent:(id)event { __block BOOL result = NO; [self performDatabaseBlock:^(GrowingFMDatabase *db, NSError *error) { if (error) { self.databaseError = error; return; } - result = - [db executeUpdate:@"insert into namedcachetable(name,key,value,createAt,type,policy) values(?,?,?,?,?,?)", - self.name, - event.eventUUID, - ((GrowingEventJSONPersistence *)event).rawJsonString, - @([GrowingULTimeUtil currentTimeMillis]), - event.eventType, - @(event.policy)]; + result = [db executeUpdate:@"INSERT INTO namedcachetable(key,value,createAt,type,policy) values(?,?,?,?,?)", + event.eventUUID, + event.data, + @([GrowingULTimeUtil currentTimeMillis]), + event.eventType, + @(event.policy)]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; @@ -180,7 +168,7 @@ - (BOOL)insertEvent:(GrowingEventJSONPersistence *)event { return result; } -- (BOOL)insertEvents:(NSArray *)events { +- (BOOL)insertEvents:(NSArray> *)events { if (!events || events.count == 0) { return YES; } @@ -192,15 +180,13 @@ - (BOOL)insertEvents:(NSArray *)events { return; } for (int i = 0; i < events.count; i++) { - GrowingEventJSONPersistence *event = (GrowingEventJSONPersistence *)events[i]; - result = [db - executeUpdate:@"insert into namedcachetable(name,key,value,createAt,type,policy) values(?,?,?,?,?,?)", - self.name, - event.eventUUID, - event.rawJsonString, - @([GrowingULTimeUtil currentTimeMillis]), - event.eventType, - @(event.policy)]; + id event = events[i]; + result = [db executeUpdate:@"INSERT INTO namedcachetable(key,value,createAt,type,policy) values(?,?,?,?,?)", + event.eventUUID, + event.data, + @([GrowingULTimeUtil currentTimeMillis]), + event.eventType, + @(event.policy)]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; @@ -219,7 +205,7 @@ - (BOOL)deleteEvent:(NSString *)key { self.databaseError = error; return; } - result = [db executeUpdate:@"delete from namedcachetable where name=? and key=?;", self.name, key]; + result = [db executeUpdate:@"DELETE FROM namedcachetable WHERE key=?;", key]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; @@ -242,7 +228,7 @@ - (BOOL)deleteEvents:(NSArray *)keys { } for (NSString *key in keys) { - result = [db executeUpdate:@"delete from namedcachetable where name=? and key=?;", self.name, key]; + result = [db executeUpdate:@"DELETE FROM namedcachetable WHERE key=?;", key]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; break; @@ -260,7 +246,7 @@ - (BOOL)clearAllEvents { self.databaseError = error; return; } - result = [db executeUpdate:@"delete from namedcachetable where name=?" values:@[self.name] error:nil]; + result = [db executeUpdate:@"DELETE FROM namedcachetable"]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; } @@ -279,8 +265,7 @@ - (BOOL)cleanExpiredEventIfNeeded { self.databaseError = error; return; } - result = - [db executeUpdate:@"delete from namedcachetable where name=? and createAt<=?;", self.name, sevenDayBefore]; + result = [db executeUpdate:@"DELETE FROM namedcachetable WHERE createAt<=?;", sevenDayBefore]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; } @@ -296,6 +281,13 @@ - (NSError *)lastError { #pragma mark - Private Methods - (BOOL)initDB { + @throw [NSException + exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + +- (BOOL)initDB:(NSString *)sqlInit createIndex:(NSString *)sqlCreateIndex { __block BOOL result = NO; [self performTransactionBlock:^(GrowingFMDatabase *db, BOOL *rollback, NSError *error) { if (error) { @@ -303,32 +295,17 @@ - (BOOL)initDB { return; } - NSString *sql = - @"create table if not exists namedcachetable(" - @"id INTEGER PRIMARY KEY," - @"name text," - @"key text," - @"value text," - @"createAt INTEGER NOT NULL," - @"type text," - @"policy INTEGER);"; - NSString *sqlCreateIndexNameKey = - @"create index if not exists namedcachetable_name_key on namedcachetable (name, key);"; - NSString *sqlCreateIndexNameId = - @"create index if not exists namedcachetable_name_id on namedcachetable (name, id);"; - NSString *sqlCreateColumnIfNotExist = @"ALTER TABLE namedcachetable ADD policy INTEGER default 6"; - if (![db executeUpdate:sql]) { - self.databaseError = [self createDBErrorInDatabase:db]; - return; - } - if (![db executeUpdate:sqlCreateIndexNameKey]) { + if (![db executeUpdate:sqlInit]) { self.databaseError = [self createDBErrorInDatabase:db]; return; } - if (![db executeUpdate:sqlCreateIndexNameId]) { + if (![db executeUpdate:sqlCreateIndex]) { self.databaseError = [self createDBErrorInDatabase:db]; return; } + + // 兼容早期无policy + NSString *sqlCreateColumnIfNotExist = @"ALTER TABLE namedcachetable ADD policy INTEGER DEFAULT 6"; if (![db columnExists:@"policy" inTableWithName:@"namedcachetable"]) { if (![db executeUpdate:sqlCreateColumnIfNotExist]) { self.databaseError = [self createDBErrorInDatabase:db]; @@ -346,7 +323,7 @@ - (BOOL)initDB { } - (BOOL)vacuum { - if (!isExecuteVacuum(self.name)) { + if (!isExecuteVacuum(self.lastPathComponent)) { return YES; } @@ -369,8 +346,9 @@ static BOOL isExecuteVacuum(NSString *name) { if (name.length == 0) { return NO; } + NSString *vacuumDate = [NSString stringWithFormat:@"GIO_VACUUM_DATE_E7B96C4E-6EE2-49CD-87F0-B2E62D4EE96A-%@", name]; NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; - NSDate *beforeDate = [userDefault objectForKey:VACUUM_DATE(name)]; + NSDate *beforeDate = [userDefault objectForKey:vacuumDate]; NSDate *nowDate = [NSDate date]; if (beforeDate) { @@ -380,12 +358,12 @@ static BOOL isExecuteVacuum(NSString *name) { options:0]; BOOL flag = delta.day > 7 || delta.day < 0; if (flag) { - [userDefault setObject:nowDate forKey:VACUUM_DATE(name)]; + [userDefault setObject:nowDate forKey:vacuumDate]; [userDefault synchronize]; } return flag; } else { - [userDefault setObject:nowDate forKey:VACUUM_DATE(name)]; + [userDefault setObject:nowDate forKey:vacuumDate]; [userDefault synchronize]; return YES; } @@ -399,7 +377,14 @@ - (void)makeDirByFileName:(NSString *)filePath { } - (void)enumerateKeysAndValuesUsingBlock: - (void (^)(NSString *key, NSString *value, NSString *type, NSUInteger policy, BOOL *stop))block { + (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop))block { + @throw [NSException + exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + +- (void)enumerateTableUsingBlock:(void (^)(GrowingFMResultSet *set, BOOL *stop))block { if (!block) { return; } @@ -409,9 +394,7 @@ - (void)enumerateKeysAndValuesUsingBlock: self.databaseError = error; return; } - GrowingFMResultSet *set = [db executeQuery:@"select * from namedcachetable where name=? order by id asc" - values:@[self.name] - error:nil]; + GrowingFMResultSet *set = [db executeQuery:@"SELECT * FROM namedcachetable ORDER BY id ASC"]; if (!set) { self.databaseError = [self readErrorInDatabase:db]; return; @@ -419,11 +402,7 @@ - (void)enumerateKeysAndValuesUsingBlock: BOOL stop = NO; while (!stop && [set next]) { - NSString *key = [set stringForColumn:@"key"]; - NSString *value = [set stringForColumn:@"value"]; - NSString *type = [set stringForColumn:@"type"]; - NSUInteger policy = [set intForColumn:@"policy"]; - block(key, value, type, policy, &stop); + block(set, &stop); } [set close]; diff --git a/Services/Database/GrowingEventJSONDatabase.h b/Services/Database/GrowingEventJSONDatabase.h new file mode 100644 index 000000000..f916b3077 --- /dev/null +++ b/Services/Database/GrowingEventJSONDatabase.h @@ -0,0 +1,29 @@ +// +// GrowingEventJSONDatabase.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/8/7. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import +#import "Services/Database/GrowingEventFMDatabase.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface GrowingEventJSONDatabase : GrowingEventFMDatabase + +@end + +NS_ASSUME_NONNULL_END diff --git a/Services/Database/GrowingEventJSONDatabase.m b/Services/Database/GrowingEventJSONDatabase.m new file mode 100644 index 000000000..3f0307de8 --- /dev/null +++ b/Services/Database/GrowingEventJSONDatabase.m @@ -0,0 +1,62 @@ +// +// GrowingEventJSONDatabase.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/8/7. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "Services/Database/GrowingEventJSONDatabase.h" +#import "Services/Database/FMDB/GrowingFMDB.h" +#import "Services/Database/GrowingEventFMDatabase+Private.h" +#import "Services/Database/GrowingEventJSONPersistence.h" + +GrowingService(GrowingEventDatabaseService, GrowingEventJSONDatabase) + +@implementation GrowingEventJSONDatabase + +#pragma mark - Init + ++ (instancetype)databaseWithPath:(NSString *)path error:(NSError **)error { + return [super databaseWithPath:path persistenceClass:GrowingEventJSONPersistence.class error:error]; +} + +#pragma mark - Private Methods + +- (BOOL)initDB { + NSString *sqlInit = + @"CREATE TABLE IF NOT EXISTS namedcachetable(" + @"id INTEGER PRIMARY KEY," + @"name TEXT," + @"key TEXT," + @"value TEXT," + @"createAt INTEGER NOT NULL," + @"type TEXT," + @"policy INTEGER);"; + NSString *sqlCreateIndex = @"CREATE INDEX IF NOT EXISTS namedcachetable_key ON namedcachetable (key);"; + return [self initDB:sqlInit createIndex:sqlCreateIndex]; +} + +- (void)enumerateKeysAndValuesUsingBlock: + (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop))block { + [self enumerateTableUsingBlock:^(GrowingFMResultSet *set, BOOL *s) { + NSString *key = [set stringForColumn:@"key"]; + id value = [set stringForColumn:@"value"]; + NSString *type = [set stringForColumn:@"type"]; + NSUInteger policy = [set intForColumn:@"policy"]; + block(key, value, type, policy, &s); + }]; +} + +@end diff --git a/Services/Database/GrowingEventJSONPersistence.h b/Services/Database/GrowingEventJSONPersistence.h index dd394c705..c251f7f9c 100644 --- a/Services/Database/GrowingEventJSONPersistence.h +++ b/Services/Database/GrowingEventJSONPersistence.h @@ -26,18 +26,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *eventUUID; @property (nonatomic, copy, readonly) NSString *eventType; -@property (nonatomic, copy, readonly) NSString *rawJsonString; +@property (nonatomic, strong, readonly) id data; @property (nonatomic, assign, readonly) GrowingEventSendPolicy policy; -- (instancetype)initWithUUID:(NSString *)uuid - eventType:(NSString *)eventType - jsonString:(NSString *)jsonString - policy:(GrowingEventSendPolicy)policy; - -+ (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; - -+ (NSData *)buildRawEventsFromEvents:(NSArray *)events; - @end NS_ASSUME_NONNULL_END diff --git a/Services/Database/GrowingEventJSONPersistence.m b/Services/Database/GrowingEventJSONPersistence.m index 0b99420fd..192ba3a21 100644 --- a/Services/Database/GrowingEventJSONPersistence.m +++ b/Services/Database/GrowingEventJSONPersistence.m @@ -24,12 +24,12 @@ @implementation GrowingEventJSONPersistence - (instancetype)initWithUUID:(NSString *)uuid eventType:(NSString *)eventType - jsonString:(NSString *)jsonString + data:(id)data policy:(GrowingEventSendPolicy)policy { if (self = [super init]) { _eventUUID = uuid; _eventType = eventType; - _rawJsonString = jsonString; + _data = data; _policy = policy; } return self; @@ -40,14 +40,14 @@ + (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSStri return [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:event.eventType - jsonString:eventJsonString + data:eventJsonString policy:event.sendPolicy]; } + (NSData *)buildRawEventsFromEvents:(NSArray *)events { NSMutableArray *raws = [NSMutableArray array]; for (GrowingEventJSONPersistence *e in events) { - NSString *rawStr = e.rawJsonString; + NSString *rawStr = e.data; if (rawStr && rawStr.length > 0) { [raws addObject:rawStr]; } @@ -58,7 +58,7 @@ + (NSData *)buildRawEventsFromEvents:(NSArray *)e } - (id)toJSONObject { - return self.rawJsonString.growingHelper_jsonObject; + return ((NSString *)self.data).growingHelper_jsonObject; } - (void)appendExtraParams:(NSDictionary *)extraParams { @@ -71,7 +71,7 @@ - (void)appendExtraParams:(NSDictionary *)extraParams { [attributes addEntriesFromDictionary:extraParams]; dictM[@"attributes"] = attributes.copy; NSString *eventJsonString = [[NSString alloc] initWithJsonObject_growingHelper:dictM]; - _rawJsonString = eventJsonString; + _data = eventJsonString; } @end From 852fd79f00ab700e35f1754ee9cab0d9079c3530 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 7 Aug 2023 19:58:24 +0800 Subject: [PATCH 051/126] =?UTF-8?q?refactor:=20=E6=95=B0=E6=8D=AE=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=BB=98=E8=AE=A4=E4=BD=BF=E7=94=A8=20Protobuf=20?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE --- .../Event/GrowingEventChannel.h | 1 - .../Event/GrowingEventChannel.m | 21 ++++++++++++++----- .../Event/GrowingEventManager.h | 2 -- .../Event/GrowingEventManager.m | 7 +++++-- .../GrowingTrackConfiguration.m | 2 ++ .../Public/GrowingTrackConfiguration.h | 1 + Modules/Advert/GrowingAdvertising.m | 1 - .../GrowingEventRequestJSONAdapter.m | 4 +++- .../GrowingEventRequestProtobufAdapter.m | 4 +++- 9 files changed, 30 insertions(+), 13 deletions(-) diff --git a/GrowingTrackerCore/Event/GrowingEventChannel.h b/GrowingTrackerCore/Event/GrowingEventChannel.h index 53a1475c8..6bd10f546 100644 --- a/GrowingTrackerCore/Event/GrowingEventChannel.h +++ b/GrowingTrackerCore/Event/GrowingEventChannel.h @@ -39,7 +39,6 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)eventChannelWithName:(NSString *)name eventTypes:(NSArray *_Nullable)eventTypes - persistenceType:(GrowingEventPersistenceType)persistenceType isRealtimeEvent:(BOOL)isRealtimeEvent; + (NSMutableArray *)eventChannels; diff --git a/GrowingTrackerCore/Event/GrowingEventChannel.m b/GrowingTrackerCore/Event/GrowingEventChannel.m index c9a2f5cf6..10a27336f 100644 --- a/GrowingTrackerCore/Event/GrowingEventChannel.m +++ b/GrowingTrackerCore/Event/GrowingEventChannel.m @@ -19,24 +19,36 @@ #import "GrowingTrackerCore/Event/GrowingEventChannel.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" @implementation GrowingEventChannel - (instancetype)initWithName:(NSString *)name eventTypes:(NSArray *_Nullable)eventTypes persistenceType:(GrowingEventPersistenceType)persistenceType - isRealtimeEvent:(BOOL)isRealtimeEvent - isUploading:(BOOL)isUploading { + isRealtimeEvent:(BOOL)isRealtimeEvent { if (self = [super init]) { _name = name; _eventTypes = eventTypes; _persistenceType = persistenceType; _isRealtimeEvent = isRealtimeEvent; - _isUploading = isUploading; + _isUploading = NO; } return self; } ++ (instancetype)eventChannelWithName:(NSString *)name + eventTypes:(NSArray *_Nullable)eventTypes + isRealtimeEvent:(BOOL)isRealtimeEvent { + GrowingTrackConfiguration *trackConfiguration = GrowingConfigurationManager.sharedInstance.trackConfiguration; + GrowingEventPersistenceType type = + trackConfiguration.useProtobuf ? GrowingEventPersistenceTypeProtobuf : GrowingEventPersistenceTypeJSON; + return [[GrowingEventChannel alloc] initWithName:name + eventTypes:eventTypes + persistenceType:type + isRealtimeEvent:isRealtimeEvent]; +} + + (instancetype)eventChannelWithName:(NSString *)name eventTypes:(NSArray *_Nullable)eventTypes persistenceType:(GrowingEventPersistenceType)persistenceType @@ -44,8 +56,7 @@ + (instancetype)eventChannelWithName:(NSString *)name return [[GrowingEventChannel alloc] initWithName:name eventTypes:eventTypes persistenceType:persistenceType - isRealtimeEvent:isRealtimeEvent - isUploading:NO]; + isRealtimeEvent:isRealtimeEvent]; } static NSMutableArray *eventChannels = nil; diff --git a/GrowingTrackerCore/Event/GrowingEventManager.h b/GrowingTrackerCore/Event/GrowingEventManager.h index 55e61ae85..b67d27484 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.h +++ b/GrowingTrackerCore/Event/GrowingEventManager.h @@ -68,8 +68,6 @@ @interface GrowingEventManager : NSObject -@property (nonatomic, assign) GrowingEventPersistenceType persistenceType; - + (_Nonnull instancetype)sharedInstance; /// 配置事件管理者 diff --git a/GrowingTrackerCore/Event/GrowingEventManager.m b/GrowingTrackerCore/Event/GrowingEventManager.m index 16ab591f6..cd55aede1 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.m +++ b/GrowingTrackerCore/Event/GrowingEventManager.m @@ -74,7 +74,6 @@ + (instancetype)sharedInstance { - (instancetype)init { if (self = [super init]) { _allInterceptor = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory]; - _persistenceType = GrowingEventPersistenceTypeProtobuf; } return self; } @@ -123,9 +122,13 @@ - (void)configManager { } self->_allEventChannels = eventChannels; + GrowingTrackConfiguration *trackConfiguration = + GrowingConfigurationManager.sharedInstance.trackConfiguration; + GrowingEventPersistenceType currentType = + trackConfiguration.useProtobuf ? GrowingEventPersistenceTypeProtobuf : GrowingEventPersistenceTypeJSON; NSMutableDictionary *dictM = [NSMutableDictionary dictionary]; for (GrowingEventChannel *ec in eventChannels) { - if (ec.persistenceType != self->_persistenceType) { + if (ec.persistenceType != currentType) { continue; } for (NSString *key in ec.eventTypes) { diff --git a/GrowingTrackerCore/GrowingTrackConfiguration.m b/GrowingTrackerCore/GrowingTrackConfiguration.m index 613ebf740..264effafc 100644 --- a/GrowingTrackerCore/GrowingTrackConfiguration.m +++ b/GrowingTrackerCore/GrowingTrackConfiguration.m @@ -55,6 +55,7 @@ - (instancetype)initWithProjectId:(NSString *)projectId { _idMappingEnabled = NO; _urlScheme = nil; _encryptEnabled = NO; + _useProtobuf = YES; // Advert _ASAEnabled = NO; @@ -89,6 +90,7 @@ - (id)copyWithZone:(NSZone *)zone { configuration->_idMappingEnabled = _idMappingEnabled; configuration->_urlScheme = _urlScheme; configuration->_encryptEnabled = _encryptEnabled; + configuration->_useProtobuf = _useProtobuf; // Advert configuration->_ASAEnabled = _ASAEnabled; diff --git a/GrowingTrackerCore/Public/GrowingTrackConfiguration.h b/GrowingTrackerCore/Public/GrowingTrackConfiguration.h index 6a68241c5..c6e36601c 100644 --- a/GrowingTrackerCore/Public/GrowingTrackConfiguration.h +++ b/GrowingTrackerCore/Public/GrowingTrackConfiguration.h @@ -39,6 +39,7 @@ FOUNDATION_EXPORT NSString *const kGrowingDefaultDataCollectionServerHost; @property (nonatomic, assign) BOOL idMappingEnabled; @property (nonatomic, copy) NSString *urlScheme; @property (nonatomic, assign) BOOL encryptEnabled; +@property (nonatomic, assign) BOOL useProtobuf; - (instancetype)initWithProjectId:(NSString *)projectId; diff --git a/Modules/Advert/GrowingAdvertising.m b/Modules/Advert/GrowingAdvertising.m index 9b64a69c2..5c1a71b03 100644 --- a/Modules/Advert/GrowingAdvertising.m +++ b/Modules/Advert/GrowingAdvertising.m @@ -107,7 +107,6 @@ - (BOOL)growingHandlerUrl:(NSURL *)url { - (void)growingEventManagerChannels:(NSMutableArray *)channels { [channels addObject:[GrowingEventChannel eventChannelWithName:@"Advert" eventTypes:@[GrowingEventTypeActivate] - persistenceType:GrowingEventManager.sharedInstance.persistenceType isRealtimeEvent:YES]]; } diff --git a/Modules/DefaultServices/GrowingEventRequestJSONAdapter.m b/Modules/DefaultServices/GrowingEventRequestJSONAdapter.m index b17da0378..7f75efeb0 100644 --- a/Modules/DefaultServices/GrowingEventRequestJSONAdapter.m +++ b/Modules/DefaultServices/GrowingEventRequestJSONAdapter.m @@ -18,6 +18,7 @@ // limitations under the License. #import "Modules/DefaultServices/GrowingEventRequestJSONAdapter.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" @implementation GrowingEventRequestJSONAdapter @@ -33,7 +34,8 @@ - (NSMutableURLRequest *)adaptedURLRequest:(NSMutableURLRequest *)request { } - (NSUInteger)priority { - return 1; + GrowingTrackConfiguration *trackConfiguration = GrowingConfigurationManager.sharedInstance.trackConfiguration; + return trackConfiguration.useProtobuf ? 1 : 5; } @end diff --git a/Modules/Protobuf/GrowingEventRequestProtobufAdapter.m b/Modules/Protobuf/GrowingEventRequestProtobufAdapter.m index 6b6dfb6d5..a1e8119fe 100644 --- a/Modules/Protobuf/GrowingEventRequestProtobufAdapter.m +++ b/Modules/Protobuf/GrowingEventRequestProtobufAdapter.m @@ -18,6 +18,7 @@ // limitations under the License. #import "Modules/Protobuf/GrowingEventRequestProtobufAdapter.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" @implementation GrowingEventRequestProtobufAdapter @@ -33,7 +34,8 @@ - (NSMutableURLRequest *)adaptedURLRequest:(NSMutableURLRequest *)request { } - (NSUInteger)priority { - return 5; + GrowingTrackConfiguration *trackConfiguration = GrowingConfigurationManager.sharedInstance.trackConfiguration; + return trackConfiguration.useProtobuf ? 5 : 1; } @end From ce918a853511be91317099e5f3b3e70e10a22a1c Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 8 Aug 2023 17:43:29 +0800 Subject: [PATCH 052/126] =?UTF-8?q?refactor:=20Protobuf=20=E4=BB=8E=20modu?= =?UTF-8?q?le=20=E6=94=B9=E4=B8=BA=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/Example.xcodeproj/project.pbxproj | 16 +++--- .../ProtobufTests/ProtobufDatabaseTest.m | 6 +- .../ProtobufTests/ProtobufEventsTest.m | 4 +- .../ProtobufTests/ProtobufPersistenceTest.m | 6 +- .../ProtobufTests/ProtobufRequestHeaderTest.m | 2 +- GrowingAnalytics.podspec | 40 +++++++------ .../GrowingDefaultServicesWrapper.m | 2 + .../GrowingEventRequestProtobufAdapter.h | 0 .../GrowingEventRequestProtobufAdapter.m | 2 +- Modules/Protobuf/GrowingProtobufModule.m | 34 ----------- Package.swift | 56 ++++++++++--------- Podfile.lock | 11 ++-- .../GrowingEventJSONDatabase.h | 0 .../GrowingEventJSONDatabase.m | 4 +- .../GrowingEventJSONPersistence.h | 0 .../GrowingEventJSONPersistence.m | 2 +- .../JSON/include/Dummy-GrowingService-JSON.h | 0 .../Catagory/GrowingBaseEvent+Protobuf.h | 0 .../Catagory/GrowingBaseEvent+Protobuf.m | 6 +- .../GrowingPBEventV3Dto+GrowingHelper.h | 2 +- .../GrowingPBEventV3Dto+GrowingHelper.m | 2 +- .../Protobuf/GrowingEventProtobufDatabase.h | 0 .../Protobuf/GrowingEventProtobufDatabase.m | 6 +- .../GrowingEventProtobufPersistence.h | 0 .../GrowingEventProtobufPersistence.m | 10 ++-- .../Protobuf/Proto/GrowingEvent.pbobjc.h | 0 .../Protobuf/Proto/GrowingEvent.pbobjc.m | 2 +- .../Protobuf/Proto/event_v3.proto | 0 .../Dummy-GrowingService-Protobuf-Proto.h | 0 .../include/Dummy-GrowingService-Protobuf.h | 16 ++---- .../SwiftProtobuf/SwiftProtobuf.swift | 0 .../SwiftProtobuf/event_v3.pb.swift | 0 32 files changed, 99 insertions(+), 130 deletions(-) rename Modules/{Protobuf => DefaultServices}/GrowingEventRequestProtobufAdapter.h (100%) rename Modules/{Protobuf => DefaultServices}/GrowingEventRequestProtobufAdapter.m (95%) delete mode 100644 Modules/Protobuf/GrowingProtobufModule.m rename Services/{Database => JSON}/GrowingEventJSONDatabase.h (100%) rename Services/{Database => JSON}/GrowingEventJSONDatabase.m (94%) rename Services/{Database => JSON}/GrowingEventJSONPersistence.h (100%) rename Services/{Database => JSON}/GrowingEventJSONPersistence.m (98%) rename Modules/Protobuf/include/Dummy-GrowingModule-Protobuf.h => Services/JSON/include/Dummy-GrowingService-JSON.h (100%) rename {Modules => Services}/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h (100%) rename {Modules => Services}/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m (96%) rename {Modules => Services}/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h (94%) rename {Modules => Services}/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m (98%) rename {Modules => Services}/Protobuf/GrowingEventProtobufDatabase.h (100%) rename {Modules => Services}/Protobuf/GrowingEventProtobufDatabase.m (92%) rename {Modules => Services}/Protobuf/GrowingEventProtobufPersistence.h (100%) rename {Modules => Services}/Protobuf/GrowingEventProtobufPersistence.m (91%) rename {Modules => Services}/Protobuf/Proto/GrowingEvent.pbobjc.h (100%) rename {Modules => Services}/Protobuf/Proto/GrowingEvent.pbobjc.m (99%) rename {Modules => Services}/Protobuf/Proto/event_v3.proto (100%) rename Modules/Protobuf/Proto/include/Dummy-GrowingModule-Protobuf-Proto.h => Services/Protobuf/Proto/include/Dummy-GrowingService-Protobuf-Proto.h (100%) rename Modules/Protobuf/GrowingProtobufModule.h => Services/Protobuf/include/Dummy-GrowingService-Protobuf.h (71%) rename {Modules => Services}/SwiftProtobuf/SwiftProtobuf.swift (100%) rename {Modules => Services}/SwiftProtobuf/event_v3.pb.swift (100%) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index c52a0fa00..c0a75c9c9 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -1779,7 +1779,7 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Example/Pods-Example-frameworks.sh", "${BUILT_PRODUCTS_DIR}/GrowingAPM/GrowingAPM.framework", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-411db831/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-f61463e2/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingToolsKit/GrowingToolsKit.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/LBXScan/LBXScan.framework", @@ -1810,7 +1810,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsStartTests/Pods-GrowingAnalyticsStartTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-9f864bbd/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-88384491/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); @@ -1965,7 +1965,7 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-ExampleiOS13/Pods-ExampleiOS13-frameworks.sh", "${BUILT_PRODUCTS_DIR}/GrowingAPM/GrowingAPM.framework", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-c1567d15/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-30913d41/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingToolsKit/GrowingToolsKit.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", @@ -1990,7 +1990,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsTests/Pods-GrowingAnalyticsTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-8e13d3d1/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-b35945a7/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); @@ -2012,7 +2012,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-61b6cda4/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-d5b2e835/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", "${BUILT_PRODUCTS_DIR}/KIF/KIF.framework", @@ -2080,7 +2080,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-ProtobufTests/Pods-ProtobufTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-61b6cda4/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-d5b2e835/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); @@ -2102,7 +2102,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Example-macOS/Pods-Example-macOS-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-39d19e2e/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-19c77ac5/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/Protobuf-macOS/Protobuf.framework", ); @@ -2124,7 +2124,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-AdvertTests/Pods-AdvertTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-c1567d15/GrowingAnalytics.framework", + "${BUILT_PRODUCTS_DIR}/GrowingAnalytics-30913d41/GrowingAnalytics.framework", "${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore/GrowingUtils.framework", "${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework", ); diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m index 24bcc66ff..349bc3a98 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m @@ -19,11 +19,11 @@ #import -#import "Modules/Protobuf/GrowingEventProtobufPersistence.h" -#import "Modules/Protobuf/GrowingEventProtobufDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingTrackerCore/Event/GrowingVisitEvent.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" -#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" @interface ProtobufDatabaseTest : XCTestCase diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m index e9696eba2..3fe3f05da 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m @@ -19,8 +19,8 @@ #import -#import "Modules/Protobuf/GrowingEventProtobufPersistence.h" -#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" #import "GrowingTrackerCore/Event/GrowingVisitEvent.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h" diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m index ec817b874..6ad40f408 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m @@ -19,10 +19,10 @@ #import -#import "Modules/Protobuf/GrowingEventProtobufPersistence.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" -#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" -#import "Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" +#import "Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h" @interface ProtobufPersistenceTest : XCTestCase diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m index ee736ff10..73aa27835 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m @@ -19,7 +19,7 @@ #import -#import "Modules/Protobuf/GrowingEventRequestProtobufAdapter.h" +#import "Services/Protobuf/GrowingEventRequestProtobufAdapter.h" #import "Modules/DefaultServices/GrowingEventRequestJSONAdapter.h" @interface ProtobufRequestHeaderTest : XCTestCase diff --git a/GrowingAnalytics.podspec b/GrowingAnalytics.podspec index 405c72d5c..2f3227962 100644 --- a/GrowingAnalytics.podspec +++ b/GrowingAnalytics.podspec @@ -23,7 +23,6 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 autotracker.dependency 'GrowingAnalytics/AutotrackerCore', s.version.to_s # Modules - autotracker.dependency 'GrowingAnalytics/Protobuf', s.version.to_s autotracker.ios.dependency 'GrowingAnalytics/Hybrid', s.version.to_s autotracker.ios.dependency 'GrowingAnalytics/MobileDebugger', s.version.to_s autotracker.ios.dependency 'GrowingAnalytics/WebCircle', s.version.to_s @@ -36,7 +35,6 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 tracker.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s # Modules - tracker.dependency 'GrowingAnalytics/Protobuf', s.version.to_s tracker.ios.dependency 'GrowingAnalytics/MobileDebugger', s.version.to_s tracker.dependency 'GrowingAnalytics/DefaultServices', s.version.to_s end @@ -64,6 +62,26 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 service.public_header_files = 'Services/Database/include/*.h' service.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s end + + s.subspec 'JSON' do |service| + service.source_files = 'Services/JSON/**/*{.h,.m,.c,.cpp,.mm}' + service.public_header_files = 'Services/JSON/include/*.h' + service.dependency 'GrowingAnalytics/Database', s.version.to_s + end + + s.subspec 'Protobuf' do |protobuf| + protobuf.source_files = 'Services/Protobuf/**/*{.h,.m,.c,.cpp,.mm}' + protobuf.exclude_files = 'Services/Protobuf/Proto/**/*{.h,.m,.c,.cpp,.mm}' + protobuf.public_header_files = 'Services/Protobuf/include/*.h' + protobuf.dependency 'GrowingAnalytics/Database', s.version.to_s + + protobuf.subspec 'Proto' do |proto| + proto.source_files = 'Services/Protobuf/Proto/**/*{.h,.m,.c,.cpp,.mm}' + proto.public_header_files = 'Services/Protobuf/Proto/include/*.h' + proto.requires_arc = false + proto.dependency 'Protobuf', '>= 3.22.0' + end + end s.subspec 'Network' do |service| service.source_files = 'Services/Network/**/*{.h,.m,.c,.cpp,.mm}' @@ -102,7 +120,8 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 services.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s # Default Services - services.dependency 'GrowingAnalytics/Database', s.version.to_s + services.dependency 'GrowingAnalytics/JSON', s.version.to_s + services.dependency 'GrowingAnalytics/Protobuf', s.version.to_s services.dependency 'GrowingAnalytics/Network', s.version.to_s services.dependency 'GrowingAnalytics/Encryption', s.version.to_s services.dependency 'GrowingAnalytics/Compression', s.version.to_s @@ -148,21 +167,6 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 advert.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s end - s.subspec 'Protobuf' do |protobuf| - protobuf.source_files = 'Modules/Protobuf/**/*{.h,.m,.c,.cpp,.mm}' - protobuf.exclude_files = 'Modules/Protobuf/Proto/**/*{.h,.m,.c,.cpp,.mm}' - protobuf.public_header_files = 'Modules/Protobuf/include/*.h' - protobuf.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s - protobuf.dependency 'GrowingAnalytics/Database', s.version.to_s - - protobuf.subspec 'Proto' do |proto| - proto.source_files = 'Modules/Protobuf/Proto/**/*{.h,.m,.c,.cpp,.mm}' - proto.public_header_files = 'Modules/Protobuf/Proto/include/*.h' - proto.requires_arc = false - proto.dependency 'Protobuf', '>= 3.22.0' - end - end - s.subspec 'APM' do |apm| apm.ios.deployment_target = '10.0' apm.source_files = 'Modules/APM/**/*{.h,.m,.c,.cpp,.mm}' diff --git a/Modules/DefaultServices/GrowingDefaultServicesWrapper.m b/Modules/DefaultServices/GrowingDefaultServicesWrapper.m index 5fa9d0730..3283b001e 100644 --- a/Modules/DefaultServices/GrowingDefaultServicesWrapper.m +++ b/Modules/DefaultServices/GrowingDefaultServicesWrapper.m @@ -22,6 +22,7 @@ #import "Modules/DefaultServices/GrowingEventRequestCompressionAdapter.h" #import "Modules/DefaultServices/GrowingEventRequestEncryptionAdapter.h" #import "Modules/DefaultServices/GrowingEventRequestJSONAdapter.h" +#import "Modules/DefaultServices/GrowingEventRequestProtobufAdapter.h" GrowingMod(GrowingDefaultServicesWrapper) @@ -29,6 +30,7 @@ @implementation GrowingDefaultServicesWrapper - (void)growingModInit:(GrowingContext *)context { [GrowingEventRequestAdapters.sharedInstance addAdapter:GrowingEventRequestJSONAdapter.class]; + [GrowingEventRequestAdapters.sharedInstance addAdapter:GrowingEventRequestProtobufAdapter.class]; [GrowingEventRequestAdapters.sharedInstance addAdapter:GrowingEventRequestCompressionAdapter.class]; [GrowingEventRequestAdapters.sharedInstance addAdapter:GrowingEventRequestEncryptionAdapter.class]; } diff --git a/Modules/Protobuf/GrowingEventRequestProtobufAdapter.h b/Modules/DefaultServices/GrowingEventRequestProtobufAdapter.h similarity index 100% rename from Modules/Protobuf/GrowingEventRequestProtobufAdapter.h rename to Modules/DefaultServices/GrowingEventRequestProtobufAdapter.h diff --git a/Modules/Protobuf/GrowingEventRequestProtobufAdapter.m b/Modules/DefaultServices/GrowingEventRequestProtobufAdapter.m similarity index 95% rename from Modules/Protobuf/GrowingEventRequestProtobufAdapter.m rename to Modules/DefaultServices/GrowingEventRequestProtobufAdapter.m index a1e8119fe..c1930465b 100644 --- a/Modules/Protobuf/GrowingEventRequestProtobufAdapter.m +++ b/Modules/DefaultServices/GrowingEventRequestProtobufAdapter.m @@ -17,7 +17,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "Modules/Protobuf/GrowingEventRequestProtobufAdapter.h" +#import "Modules/DefaultServices/GrowingEventRequestProtobufAdapter.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" @implementation GrowingEventRequestProtobufAdapter diff --git a/Modules/Protobuf/GrowingProtobufModule.m b/Modules/Protobuf/GrowingProtobufModule.m deleted file mode 100644 index 940d07562..000000000 --- a/Modules/Protobuf/GrowingProtobufModule.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// GrowingProtobufModule.m -// GrowingAnalytics -// -// Created by YoloMao on 2022/4/26. -// Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#import "Modules/Protobuf/GrowingProtobufModule.h" -#import "GrowingTrackerCore/Network/Request/Adapter/GrowingEventRequestAdapters.h" -#import "Modules/Protobuf/GrowingEventProtobufDatabase.h" -#import "Modules/Protobuf/GrowingEventRequestProtobufAdapter.h" - -GrowingMod(GrowingProtobufModule) -GrowingService(GrowingPBEventDatabaseService, GrowingEventProtobufDatabase) - -@implementation GrowingProtobufModule - -- (void)growingModInit:(GrowingContext *)context { - [GrowingEventRequestAdapters.sharedInstance addAdapter:GrowingEventRequestProtobufAdapter.class]; -} - -@end diff --git a/Package.swift b/Package.swift index c6b02101f..954319d0c 100644 --- a/Package.swift +++ b/Package.swift @@ -50,10 +50,6 @@ let package = Package( name: "GrowingModule_Hybrid", targets: ["GrowingModule_Hybrid"] ), - .library( - name: "GrowingModule_Protobuf", - targets: ["GrowingModule_Protobuf"] - ), .library( name: "GrowingModule_Advert", targets: ["GrowingModule_Advert"] @@ -200,6 +196,34 @@ let package = Package( .headerSearchPath("../.."), ] ), + .target( + name: "GrowingService_JSON", + dependencies: ["GrowingService_Database"], + path: "Services/JSON", + cSettings: [ + .headerSearchPath("../..") + ] + ), + .target( + name: "GrowingService_Protobuf", + dependencies: [ + "GrowingService_Database", + "GrowingService_SwiftProtobuf" + ], + path: "Services/Protobuf", + exclude: ["Proto", "Catagory"], + cSettings: [ + .headerSearchPath("../..") + ] + ), + .target( + name: "GrowingService_SwiftProtobuf", + dependencies: [ + "GrowingTrackerCore", + .product(name: "SwiftProtobuf", package: "swift-protobuf") + ], + path: "Services/SwiftProtobuf" + ), .target( name: "GrowingService_Network", dependencies: ["GrowingTrackerCore"], @@ -247,7 +271,8 @@ let package = Package( name: "GrowingModule_DefaultServices", dependencies: [ "GrowingTrackerCore", - "GrowingService_Database", + "GrowingService_JSON", + "GrowingService_Protobuf", "GrowingService_Network", "GrowingService_Encryption", "GrowingService_Compression", @@ -303,27 +328,6 @@ let package = Package( .linkedFramework("WebKit", .when(platforms: [.iOS, .macCatalyst])), ] ), - .target( - name: "GrowingModule_Protobuf", - dependencies: [ - "GrowingTrackerCore", - "GrowingService_Database", - "GrowingModule_SwiftProtobuf", - ], - path: "Modules/Protobuf", - exclude: ["Proto", "Catagory"], - cSettings: [ - .headerSearchPath("../.."), - ] - ), - .target( - name: "GrowingModule_SwiftProtobuf", - dependencies: [ - "GrowingTrackerCore", - .product(name: "SwiftProtobuf", package: "swift-protobuf"), - ], - path: "Modules/SwiftProtobuf" - ), .target( name: "GrowingModule_Advert", dependencies: ["GrowingTrackerCore"], diff --git a/Podfile.lock b/Podfile.lock index d2bfc00f7..eed680014 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -9,7 +9,6 @@ PODS: - GrowingAnalytics/DefaultServices (= 3.5.0) - GrowingAnalytics/Hybrid (= 3.5.0) - GrowingAnalytics/MobileDebugger (= 3.5.0) - - GrowingAnalytics/Protobuf (= 3.5.0) - GrowingAnalytics/WebCircle (= 3.5.0) - GrowingAnalytics/AutotrackerCore (3.5.0): - GrowingAnalytics/TrackerCore (= 3.5.0) @@ -20,9 +19,10 @@ PODS: - GrowingAnalytics/TrackerCore (= 3.5.0) - GrowingAnalytics/DefaultServices (3.5.0): - GrowingAnalytics/Compression (= 3.5.0) - - GrowingAnalytics/Database (= 3.5.0) - GrowingAnalytics/Encryption (= 3.5.0) + - GrowingAnalytics/JSON (= 3.5.0) - GrowingAnalytics/Network (= 3.5.0) + - GrowingAnalytics/Protobuf (= 3.5.0) - GrowingAnalytics/TrackerCore (= 3.5.0) - GrowingAnalytics/Encryption (3.5.0): - GrowingAnalytics/TrackerCore (= 3.5.0) @@ -30,6 +30,8 @@ PODS: - GrowingAnalytics/TrackerCore (= 3.5.0) - GrowingAnalytics/ImpressionTrack (3.5.0): - GrowingAnalytics/AutotrackerCore (= 3.5.0) + - GrowingAnalytics/JSON (3.5.0): + - GrowingAnalytics/Database (= 3.5.0) - GrowingAnalytics/MobileDebugger (3.5.0): - GrowingAnalytics/Screenshot (= 3.5.0) - GrowingAnalytics/TrackerCore (= 3.5.0) @@ -39,17 +41,14 @@ PODS: - GrowingAnalytics/Protobuf (3.5.0): - GrowingAnalytics/Database (= 3.5.0) - GrowingAnalytics/Protobuf/Proto (= 3.5.0) - - GrowingAnalytics/TrackerCore (= 3.5.0) - GrowingAnalytics/Protobuf/Proto (3.5.0): - GrowingAnalytics/Database (= 3.5.0) - - GrowingAnalytics/TrackerCore (= 3.5.0) - Protobuf (>= 3.22.0) - GrowingAnalytics/Screenshot (3.5.0): - GrowingAnalytics/TrackerCore - GrowingAnalytics/Tracker (3.5.0): - GrowingAnalytics/DefaultServices (= 3.5.0) - GrowingAnalytics/MobileDebugger (= 3.5.0) - - GrowingAnalytics/Protobuf (= 3.5.0) - GrowingAnalytics/TrackerCore (= 3.5.0) - GrowingAnalytics/TrackerCore (3.5.0): - GrowingUtils/TrackerCore (= 0.0.5) @@ -152,7 +151,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: 88f565a894472016ecd0c1354c231bd7896f13f5 + GrowingAnalytics: d8bac28422b170858d3d5523a06170d55dd2148a GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 9c0d6e41c9678397dbaa3304b1738a2867b023ae GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 diff --git a/Services/Database/GrowingEventJSONDatabase.h b/Services/JSON/GrowingEventJSONDatabase.h similarity index 100% rename from Services/Database/GrowingEventJSONDatabase.h rename to Services/JSON/GrowingEventJSONDatabase.h diff --git a/Services/Database/GrowingEventJSONDatabase.m b/Services/JSON/GrowingEventJSONDatabase.m similarity index 94% rename from Services/Database/GrowingEventJSONDatabase.m rename to Services/JSON/GrowingEventJSONDatabase.m index 3f0307de8..f0c2c73e2 100644 --- a/Services/Database/GrowingEventJSONDatabase.m +++ b/Services/JSON/GrowingEventJSONDatabase.m @@ -17,10 +17,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "Services/Database/GrowingEventJSONDatabase.h" +#import "Services/JSON/GrowingEventJSONDatabase.h" #import "Services/Database/FMDB/GrowingFMDB.h" #import "Services/Database/GrowingEventFMDatabase+Private.h" -#import "Services/Database/GrowingEventJSONPersistence.h" +#import "Services/JSON/GrowingEventJSONPersistence.h" GrowingService(GrowingEventDatabaseService, GrowingEventJSONDatabase) diff --git a/Services/Database/GrowingEventJSONPersistence.h b/Services/JSON/GrowingEventJSONPersistence.h similarity index 100% rename from Services/Database/GrowingEventJSONPersistence.h rename to Services/JSON/GrowingEventJSONPersistence.h diff --git a/Services/Database/GrowingEventJSONPersistence.m b/Services/JSON/GrowingEventJSONPersistence.m similarity index 98% rename from Services/Database/GrowingEventJSONPersistence.m rename to Services/JSON/GrowingEventJSONPersistence.m index 192ba3a21..b2367a8ec 100644 --- a/Services/Database/GrowingEventJSONPersistence.m +++ b/Services/JSON/GrowingEventJSONPersistence.m @@ -17,7 +17,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "Services/Database/GrowingEventJSONPersistence.h" +#import "Services/JSON/GrowingEventJSONPersistence.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" @implementation GrowingEventJSONPersistence diff --git a/Modules/Protobuf/include/Dummy-GrowingModule-Protobuf.h b/Services/JSON/include/Dummy-GrowingService-JSON.h similarity index 100% rename from Modules/Protobuf/include/Dummy-GrowingModule-Protobuf.h rename to Services/JSON/include/Dummy-GrowingService-JSON.h diff --git a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h similarity index 100% rename from Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h rename to Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h diff --git a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m similarity index 96% rename from Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m rename to Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index 355d404d6..53329b890 100644 --- a/Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -18,9 +18,9 @@ // limitations under the License. #import -#import "Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h" -#import "Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h" -#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" +#import "Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h" +#import "Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" @implementation GrowingBaseEvent (Protobuf) diff --git a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h similarity index 94% rename from Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h rename to Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h index 211192333..7841a1efc 100644 --- a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h +++ b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h @@ -17,7 +17,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m similarity index 98% rename from Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m rename to Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index 279f1f191..c0432f20f 100644 --- a/Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -17,7 +17,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h" +#import "Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h" @implementation GrowingPBEventV3Dto (GrowingHelper) diff --git a/Modules/Protobuf/GrowingEventProtobufDatabase.h b/Services/Protobuf/GrowingEventProtobufDatabase.h similarity index 100% rename from Modules/Protobuf/GrowingEventProtobufDatabase.h rename to Services/Protobuf/GrowingEventProtobufDatabase.h diff --git a/Modules/Protobuf/GrowingEventProtobufDatabase.m b/Services/Protobuf/GrowingEventProtobufDatabase.m similarity index 92% rename from Modules/Protobuf/GrowingEventProtobufDatabase.m rename to Services/Protobuf/GrowingEventProtobufDatabase.m index a95892e33..740b003a3 100644 --- a/Modules/Protobuf/GrowingEventProtobufDatabase.m +++ b/Services/Protobuf/GrowingEventProtobufDatabase.m @@ -17,11 +17,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "Modules/Protobuf/GrowingEventProtobufDatabase.h" -#import "Modules/Protobuf/GrowingEventProtobufPersistence.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" #import "Services/Database/FMDB/GrowingFMDB.h" #import "Services/Database/GrowingEventFMDatabase+Private.h" +GrowingService(GrowingPBEventDatabaseService, GrowingEventProtobufDatabase) + @implementation GrowingEventProtobufDatabase #pragma mark - Init diff --git a/Modules/Protobuf/GrowingEventProtobufPersistence.h b/Services/Protobuf/GrowingEventProtobufPersistence.h similarity index 100% rename from Modules/Protobuf/GrowingEventProtobufPersistence.h rename to Services/Protobuf/GrowingEventProtobufPersistence.h diff --git a/Modules/Protobuf/GrowingEventProtobufPersistence.m b/Services/Protobuf/GrowingEventProtobufPersistence.m similarity index 91% rename from Modules/Protobuf/GrowingEventProtobufPersistence.m rename to Services/Protobuf/GrowingEventProtobufPersistence.m index b24be03c2..2e743d6e3 100644 --- a/Modules/Protobuf/GrowingEventProtobufPersistence.m +++ b/Services/Protobuf/GrowingEventProtobufPersistence.m @@ -17,14 +17,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "Modules/Protobuf/GrowingEventProtobufPersistence.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" #if SWIFT_PACKAGE -@import GrowingModule_SwiftProtobuf; +@import GrowingService_SwiftProtobuf; #else -#import "Modules/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h" -#import "Modules/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h" -#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" +#import "Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h" +#import "Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" #endif @interface GrowingEventProtobufPersistence () diff --git a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.h b/Services/Protobuf/Proto/GrowingEvent.pbobjc.h similarity index 100% rename from Modules/Protobuf/Proto/GrowingEvent.pbobjc.h rename to Services/Protobuf/Proto/GrowingEvent.pbobjc.h diff --git a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m b/Services/Protobuf/Proto/GrowingEvent.pbobjc.m similarity index 99% rename from Modules/Protobuf/Proto/GrowingEvent.pbobjc.m rename to Services/Protobuf/Proto/GrowingEvent.pbobjc.m index 066e45bfb..d9a2da6ba 100644 --- a/Modules/Protobuf/Proto/GrowingEvent.pbobjc.m +++ b/Services/Protobuf/Proto/GrowingEvent.pbobjc.m @@ -23,7 +23,7 @@ #import -#import "Modules/Protobuf/Proto/GrowingEvent.pbobjc.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" // @@protoc_insertion_point(imports) #pragma clang diagnostic push diff --git a/Modules/Protobuf/Proto/event_v3.proto b/Services/Protobuf/Proto/event_v3.proto similarity index 100% rename from Modules/Protobuf/Proto/event_v3.proto rename to Services/Protobuf/Proto/event_v3.proto diff --git a/Modules/Protobuf/Proto/include/Dummy-GrowingModule-Protobuf-Proto.h b/Services/Protobuf/Proto/include/Dummy-GrowingService-Protobuf-Proto.h similarity index 100% rename from Modules/Protobuf/Proto/include/Dummy-GrowingModule-Protobuf-Proto.h rename to Services/Protobuf/Proto/include/Dummy-GrowingService-Protobuf-Proto.h diff --git a/Modules/Protobuf/GrowingProtobufModule.h b/Services/Protobuf/include/Dummy-GrowingService-Protobuf.h similarity index 71% rename from Modules/Protobuf/GrowingProtobufModule.h rename to Services/Protobuf/include/Dummy-GrowingService-Protobuf.h index 1eb467b05..95fc27a5a 100644 --- a/Modules/Protobuf/GrowingProtobufModule.h +++ b/Services/Protobuf/include/Dummy-GrowingService-Protobuf.h @@ -1,8 +1,8 @@ // -// GrowingProtobufModule.h +// dummy.h // GrowingAnalytics // -// Created by YoloMao on 2022/4/26. +// Created by YoloMao on 2022/3/18. // Copyright (C) 2022 Beijing Yishu Technology Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import -#import "GrowingModuleProtocol.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface GrowingProtobufModule : NSObject - -@end - -NS_ASSUME_NONNULL_END +// There are no actual public headers in the lib. This is a dummy public header to prevent Cocoapods +// from adding all internal headers as public. diff --git a/Modules/SwiftProtobuf/SwiftProtobuf.swift b/Services/SwiftProtobuf/SwiftProtobuf.swift similarity index 100% rename from Modules/SwiftProtobuf/SwiftProtobuf.swift rename to Services/SwiftProtobuf/SwiftProtobuf.swift diff --git a/Modules/SwiftProtobuf/event_v3.pb.swift b/Services/SwiftProtobuf/event_v3.pb.swift similarity index 100% rename from Modules/SwiftProtobuf/event_v3.pb.swift rename to Services/SwiftProtobuf/event_v3.pb.swift From 9c87eb9acf98657fc156f26aa39d96e908d05356 Mon Sep 17 00:00:00 2001 From: runner Date: Tue, 8 Aug 2023 09:44:34 +0000 Subject: [PATCH 053/126] style: code format --- Services/Protobuf/GrowingEventProtobufDatabase.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Services/Protobuf/GrowingEventProtobufDatabase.m b/Services/Protobuf/GrowingEventProtobufDatabase.m index 740b003a3..94551d352 100644 --- a/Services/Protobuf/GrowingEventProtobufDatabase.m +++ b/Services/Protobuf/GrowingEventProtobufDatabase.m @@ -18,9 +18,9 @@ // limitations under the License. #import "Services/Protobuf/GrowingEventProtobufDatabase.h" -#import "Services/Protobuf/GrowingEventProtobufPersistence.h" #import "Services/Database/FMDB/GrowingFMDB.h" #import "Services/Database/GrowingEventFMDatabase+Private.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" GrowingService(GrowingPBEventDatabaseService, GrowingEventProtobufDatabase) From f80d9afa672e5456ed54eccc5af4f6577908af5a Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 16:08:29 +0800 Subject: [PATCH 054/126] =?UTF-8?q?refactor:=20JSON=E3=80=81Protobuf=20?= =?UTF-8?q?=E4=BA=92=E7=9B=B8=E8=BD=AC=E6=8D=A2=E6=97=B6=EF=BC=8C=E6=8C=89?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=9A=84=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8F=91=E9=80=81=E4=BA=8B=E4=BB=B6=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Database/GrowingEventDatabase.m | 6 +- .../Event/GrowingEventManager.m | 50 +++++++++++- .../Public/GrowingEventDatabaseService.h | 11 ++- .../Public/GrowingEventPersistenceProtocol.h | 2 + Services/Database/GrowingEventFMDatabase.m | 44 ++++++----- Services/JSON/GrowingEventJSONDatabase.m | 4 +- Services/JSON/GrowingEventJSONPersistence.m | 5 ++ .../Catagory/GrowingBaseEvent+Protobuf.m | 30 +------- .../GrowingPBEventV3Dto+GrowingHelper.h | 4 + .../GrowingPBEventV3Dto+GrowingHelper.m | 76 +++++++++++++++++++ .../Protobuf/GrowingEventProtobufDatabase.m | 6 +- .../GrowingEventProtobufPersistence.m | 22 ++++++ Services/SwiftProtobuf/SwiftProtobuf.swift | 11 +++ 13 files changed, 208 insertions(+), 63 deletions(-) diff --git a/GrowingTrackerCore/Database/GrowingEventDatabase.m b/GrowingTrackerCore/Database/GrowingEventDatabase.m index ee5f17054..749aeff86 100644 --- a/GrowingTrackerCore/Database/GrowingEventDatabase.m +++ b/GrowingTrackerCore/Database/GrowingEventDatabase.m @@ -28,7 +28,6 @@ @interface GrowingEventDatabase () @property (nonatomic, strong) id db; -@property (nonatomic, assign) BOOL isProtobuf; @property (nonatomic, strong) NSMutableArray *updateKeys; @property (nonatomic, strong) NSMutableArray *updateValues; @@ -48,7 +47,6 @@ - (instancetype)initWithFilePath:(NSString *)filePath isProtobuf:(BOOL)isProtobu if (self = [super init]) { _updateValues = [[NSMutableArray alloc] init]; _updateKeys = [[NSMutableArray alloc] init]; - _isProtobuf = isProtobuf; GROWING_LOCK_INIT(lock); Class serviceClass = nil; @@ -205,11 +203,11 @@ - (void)setEvent:(id)event forKey:(NSString *)k } - (NSData *)buildRawEventsFromEvents:(NSArray> *)events { - return [self.db buildRawEventsFromEvents:events]; + return [self.db.class buildRawEventsFromEvents:events]; } - (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { - return [self.db persistenceEventWithEvent:event uuid:uuid]; + return [self.db.class persistenceEventWithEvent:event uuid:uuid]; } #pragma mark - Perform Block diff --git a/GrowingTrackerCore/Event/GrowingEventManager.m b/GrowingTrackerCore/Event/GrowingEventManager.m index cd55aede1..092aeb243 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.m +++ b/GrowingTrackerCore/Event/GrowingEventManager.m @@ -232,7 +232,8 @@ - (void)sendEventsInstantWithChannel:(GrowingEventChannel *)channel { // 非安全 发送日志 - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { - NSString *projectId = GrowingConfigurationManager.sharedInstance.trackConfiguration.projectId; + GrowingTrackConfiguration *trackConfiguration = GrowingConfigurationManager.sharedInstance.trackConfiguration; + NSString *projectId = trackConfiguration.projectId; if (projectId.length == 0) { GIOLogError(@"No valid ProjectId (channel = %@).", channel.name); return; @@ -281,7 +282,7 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { #ifdef DEBUG [self prettyLogForEvents:events withChannel:channel]; #endif - /// 如果需要改变发送地址以及请求参数 + // 如果需要改变发送地址以及请求参数 NSObject *eventRequest = nil; for (NSObject *obj in self.allInterceptor) { if ([obj respondsToSelector:@selector(growingEventManagerRequestWithChannel:)]) { @@ -292,11 +293,52 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { } } - NSData *rawEvents = [channel.db buildRawEventsFromEvents:events]; + NSData *rawEvents = nil; + if ((channel.persistenceType == GrowingEventPersistenceTypeJSON && trackConfiguration.useProtobuf) || + (channel.persistenceType == GrowingEventPersistenceTypeProtobuf && !trackConfiguration.useProtobuf)) { + // 该channel的持久化数据格式与配置不同,需要转换为配置的数据格式 + // 步骤为先转成jsonObject,再转成对应格式 + Class dbClass = nil; + if (trackConfiguration.useProtobuf) { + dbClass = + [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingPBEventDatabaseService)]; + } else { + dbClass = [[GrowingServiceManager sharedInstance] serviceImplClass:@protocol(GrowingEventDatabaseService)]; + } + if (!dbClass) { + GIOLogError(@"-sendEventsOfChannel_unsafe: error : no event database service support"); + return; + } + NSMutableArray *jsonObjects = [NSMutableArray array]; + for (id e in events) { + id jsonObject = e.toJSONObject; + if (jsonObject) { + NSString *eventType = jsonObject[@"eventType"]; + NSString *sdkVersion = jsonObject[@"sdkVersion"]; + if ([sdkVersion hasPrefix:@"3."]) { + if ([eventType isEqualToString:@"PAGE"] || [eventType isEqualToString:@"VIEW_CLICK"] || + [eventType isEqualToString:@"VIEW_CHANGE"] || [eventType isEqualToString:@"FORM_SUBMIT"] || + [eventType isEqualToString:@"APP_CLOSED"]) { + // 不兼容3.x的无埋点 + continue; + } + } + [jsonObjects addObject:jsonObject]; + } + } + + rawEvents = [dbClass buildRawEventsFromJsonObjects:jsonObjects]; + } + + if (!rawEvents) { + // 该channel的持久化数据格式与配置相同 + rawEvents = [channel.db buildRawEventsFromEvents:events]; + } + if (!eventRequest) { eventRequest = [[GrowingEventRequest alloc] initWithEvents:rawEvents]; } else { - if ([eventRequest respondsToSelector:@selector(events)]) { + if ([eventRequest respondsToSelector:@selector(setEvents:)]) { eventRequest.events = rawEvents; } } diff --git a/GrowingTrackerCore/Public/GrowingEventDatabaseService.h b/GrowingTrackerCore/Public/GrowingEventDatabaseService.h index 49d8226c2..be5d761bf 100644 --- a/GrowingTrackerCore/Public/GrowingEventDatabaseService.h +++ b/GrowingTrackerCore/Public/GrowingEventDatabaseService.h @@ -45,14 +45,21 @@ extern NSString *const GrowingEventDatabaseErrorDomain; /// @return 事件数据库实例对象 + (instancetype)databaseWithPath:(NSString *)path error:(NSError **)error; +/// 返回对应的数据持久化Class ++ (Class)persistenceClass; + /// 生成事件数组的二进制数据 /// @param events 事件数据数组 -- (NSData *)buildRawEventsFromEvents:(NSArray> *)events; ++ (NSData *)buildRawEventsFromEvents:(NSArray> *)events; + +/// 生成事件数组的二进制数据 +/// @param jsonObjects 事件数据数组 ++ (NSData *)buildRawEventsFromJsonObjects:(NSArray *)jsonObjects; /// 生成持久化事件对象 /// @param event 事件数据 /// @param uuid 唯一key -- (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; ++ (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; /// 获取已存储的事件数量 /// @return 事件数量,大于等于0;若返回值为-1,表示读取错误 diff --git a/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h b/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h index 5d0116954..26e08bbbf 100644 --- a/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h +++ b/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h @@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSData *)buildRawEventsFromEvents:(NSArray> *)events; ++ (NSData *)buildRawEventsFromJsonObjects:(NSArray *)jsonObjects; + - (instancetype)initWithUUID:(NSString *)uuid eventType:(NSString *)eventType data:(id)data diff --git a/Services/Database/GrowingEventFMDatabase.m b/Services/Database/GrowingEventFMDatabase.m index 92a05315d..e6abe9fed 100644 --- a/Services/Database/GrowingEventFMDatabase.m +++ b/Services/Database/GrowingEventFMDatabase.m @@ -26,7 +26,6 @@ @interface GrowingEventFMDatabase () @property (nonatomic, copy, readonly) NSString *lastPathComponent; -@property (nonatomic, strong) Class persistenceClass; @end @@ -35,17 +34,10 @@ @implementation GrowingEventFMDatabase #pragma mark - Init + (instancetype)databaseWithPath:(NSString *)path error:(NSError **)error { - @throw [NSException - exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] - userInfo:nil]; + return [[self alloc] initWithFilePath:path error:error]; } -+ (instancetype)databaseWithPath:(NSString *)path persistenceClass:(Class)cls error:(NSError **)error { - return [[self alloc] initWithFilePath:path persistenceClass:cls error:error]; -} - -- (instancetype)initWithFilePath:(NSString *)filePath persistenceClass:(Class)cls error:(NSError **)error { +- (instancetype)initWithFilePath:(NSString *)filePath error:(NSError **)error { if (self = [super init]) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -53,7 +45,6 @@ - (instancetype)initWithFilePath:(NSString *)filePath persistenceClass:(Class)cl }); _lastPathComponent = [NSURL fileURLWithPath:filePath].lastPathComponent; - _persistenceClass = cls; _db = [GrowingFMDatabaseQueue databaseQueueWithPath:filePath]; if (!_db) { _databaseError = [self createDBErrorInDatabase:nil]; @@ -69,13 +60,24 @@ - (instancetype)initWithFilePath:(NSString *)filePath persistenceClass:(Class)cl return self; } ++ (Class)persistenceClass { + @throw [NSException + exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + #pragma mark - Public Methods -- (NSData *)buildRawEventsFromEvents:(NSArray> *)events { ++ (NSData *)buildRawEventsFromEvents:(NSArray> *)events { return [self.persistenceClass buildRawEventsFromEvents:events]; } -- (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { ++ (NSData *)buildRawEventsFromJsonObjects:(NSArray *)jsonObjects { + return [self.persistenceClass buildRawEventsFromJsonObjects:jsonObjects]; +} + ++ (id)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid { return [self.persistenceClass persistenceEventWithEvent:event uuid:uuid]; } @@ -111,10 +113,10 @@ - (NSInteger)countOfEvents { NSMutableArray> *events = [[NSMutableArray alloc] init]; [self enumerateKeysAndValuesUsingBlock:^(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop) { - id event = [[self.persistenceClass alloc] initWithUUID:key - eventType:type - data:value - policy:policy]; + id event = [[self.class.persistenceClass alloc] initWithUUID:key + eventType:type + data:value + policy:policy]; [events addObject:event]; if (events.count >= count) { **stop = YES; @@ -132,10 +134,10 @@ - (NSInteger)countOfEvents { NSMutableArray> *events = [[NSMutableArray alloc] init]; [self enumerateKeysAndValuesUsingBlock:^(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop) { if (mask & policy) { - id event = [[self.persistenceClass alloc] initWithUUID:key - eventType:type - data:value - policy:policy]; + id event = [[self.class.persistenceClass alloc] initWithUUID:key + eventType:type + data:value + policy:policy]; [events addObject:event]; if (events.count >= count) { **stop = YES; diff --git a/Services/JSON/GrowingEventJSONDatabase.m b/Services/JSON/GrowingEventJSONDatabase.m index f0c2c73e2..b194a819e 100644 --- a/Services/JSON/GrowingEventJSONDatabase.m +++ b/Services/JSON/GrowingEventJSONDatabase.m @@ -28,8 +28,8 @@ @implementation GrowingEventJSONDatabase #pragma mark - Init -+ (instancetype)databaseWithPath:(NSString *)path error:(NSError **)error { - return [super databaseWithPath:path persistenceClass:GrowingEventJSONPersistence.class error:error]; ++ (Class)persistenceClass { + return GrowingEventJSONPersistence.class; } #pragma mark - Private Methods diff --git a/Services/JSON/GrowingEventJSONPersistence.m b/Services/JSON/GrowingEventJSONPersistence.m index b2367a8ec..2ce780e5a 100644 --- a/Services/JSON/GrowingEventJSONPersistence.m +++ b/Services/JSON/GrowingEventJSONPersistence.m @@ -57,6 +57,11 @@ + (NSData *)buildRawEventsFromEvents:(NSArray *)e return JSONData; } ++ (NSData *)buildRawEventsFromJsonObjects:(NSArray *)jsonObjects { + // 如果是3.x的数据,会多出gioId/globalSequenceId字段 + return [jsonObjects growingHelper_jsonData]; +} + - (id)toJSONObject { return ((NSString *)self.data).growingHelper_jsonObject; } diff --git a/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index 53329b890..d6c23a828 100644 --- a/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -29,7 +29,7 @@ - (GrowingPBEventV3Dto *)toProtobuf { dto.dataSourceId = self.dataSourceId; dto.sessionId = self.sessionId; dto.timestamp = self.timestamp; - dto.eventType = self.pbEventType; + dto.eventType = [dto growingHelper_eventType:self.eventType]; dto.domain = self.domain; dto.userId = self.userId; dto.deviceId = self.deviceId; @@ -102,32 +102,4 @@ - (GrowingPBEventV3Dto *)toProtobuf { return dto; } -- (GrowingPBEventType)pbEventType { - if ([self.eventType isEqualToString:@"VISIT"]) { - return GrowingPBEventType_Visit; - } else if ([self.eventType isEqualToString:@"CUSTOM"]) { - return GrowingPBEventType_Custom; - } else if ([self.eventType isEqualToString:@"VISITOR_ATTRIBUTES"]) { - return GrowingPBEventType_VisitorAttributes; - } else if ([self.eventType isEqualToString:@"LOGIN_USER_ATTRIBUTES"]) { - return GrowingPBEventType_LoginUserAttributes; - } else if ([self.eventType isEqualToString:@"CONVERSION_VARIABLES"]) { - return GrowingPBEventType_ConversionVariables; - } else if ([self.eventType isEqualToString:@"APP_CLOSED"]) { - return GrowingPBEventType_AppClosed; - } else if ([self.eventType isEqualToString:@"PAGE"]) { - return GrowingPBEventType_Page; - } else if ([self.eventType isEqualToString:@"VIEW_CLICK"]) { - return GrowingPBEventType_ViewClick; - } else if ([self.eventType isEqualToString:@"VIEW_CHANGE"]) { - return GrowingPBEventType_ViewChange; - } else if ([self.eventType isEqualToString:@"FORM_SUBMIT"]) { - return GrowingPBEventType_FormSubmit; - } else if ([self.eventType isEqualToString:@"ACTIVATE"]) { - return GrowingPBEventType_Activate; - } - - return GrowingPBEventType_GPBUnrecognizedEnumeratorValue; -} - @end diff --git a/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h index 7841a1efc..1fb9ca57b 100644 --- a/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h +++ b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.h @@ -25,8 +25,12 @@ NS_ASSUME_NONNULL_BEGIN - (id)growingHelper_jsonObject; ++ (nullable instancetype)growingHelper_parseFromJsonObject:(NSDictionary *)jsonObject; + - (NSMutableDictionary *)growingHelper_safeMap:(NSDictionary *)originMap; +- (GrowingPBEventType)growingHelper_eventType:(NSString *)eventType; + @end NS_ASSUME_NONNULL_END diff --git a/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index c0432f20f..17bfc3fa9 100644 --- a/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -187,6 +187,54 @@ - (id)growingHelper_jsonObject { return dic; } ++ (nullable instancetype)growingHelper_parseFromJsonObject:(NSDictionary *)jsonObject { + GrowingPBEventV3Dto *dto = [[GrowingPBEventV3Dto alloc] init]; + dto.dataSourceId = jsonObject[@"dataSourceId"]; + dto.sessionId = jsonObject[@"sessionId"]; + dto.timestamp = ((NSNumber *)jsonObject[@"timestamp"]).longLongValue; + dto.eventType = [dto growingHelper_eventType:jsonObject[@"eventType"]]; + dto.domain = jsonObject[@"domain"]; + dto.userId = jsonObject[@"userId"]; + dto.deviceId = jsonObject[@"deviceId"]; + dto.platform = jsonObject[@"platform"]; + dto.platformVersion = jsonObject[@"platformVersion"]; + dto.eventSequenceId = ((NSNumber *)jsonObject[@"eventSequenceId"]).intValue; + dto.appState = jsonObject[@"appState"]; + dto.URLScheme = jsonObject[@"urlScheme"]; + dto.networkState = jsonObject[@"networkState"]; + dto.screenWidth = ((NSNumber *)jsonObject[@"screenWidth"]).intValue; + dto.screenHeight = ((NSNumber *)jsonObject[@"screenHeight"]).intValue; + dto.deviceBrand = jsonObject[@"deviceBrand"]; + dto.deviceModel = jsonObject[@"deviceModel"]; + dto.deviceType = jsonObject[@"deviceType"]; + dto.appName = jsonObject[@"appName"]; + dto.appVersion = jsonObject[@"appVersion"]; + dto.language = jsonObject[@"language"]; + dto.latitude = ((NSNumber *)jsonObject[@"latitude"]).doubleValue; + dto.longitude = ((NSNumber *)jsonObject[@"longitude"]).doubleValue; + dto.sdkVersion = jsonObject[@"sdkVersion"]; + dto.userKey = jsonObject[@"userKey"]; + dto.idfa = jsonObject[@"idfa"]; + dto.idfv = jsonObject[@"idfv"]; + dto.extraSdk = jsonObject[@"extraSdk"]; + dto.path = jsonObject[@"path"]; + dto.textValue = jsonObject[@"textValue"]; + dto.xpath = jsonObject[@"xpath"]; + dto.xcontent = jsonObject[@"xcontent"]; + dto.xindex = jsonObject[@"xindex"]; + dto.index = ((NSNumber *)jsonObject[@"index"]).intValue; + dto.query = jsonObject[@"query"]; + dto.hyperlink = jsonObject[@"hyperlink"]; + dto.attributes = jsonObject[@"attributes"]; + dto.orientation = jsonObject[@"orientation"]; + dto.title = jsonObject[@"title"]; + dto.referralPage = jsonObject[@"referralPage"]; + dto.protocolType = jsonObject[@"protocolType"]; + dto.eventName = jsonObject[@"eventName"]; + + return dto; +} + - (NSMutableDictionary *)growingHelper_safeMap:(NSDictionary *)originMap { NSMutableDictionary *map = originMap.mutableCopy; for (NSString *key in map.allKeys) { @@ -199,4 +247,32 @@ - (id)growingHelper_jsonObject { return map; } +- (GrowingPBEventType)growingHelper_eventType:(NSString *)eventType { + if ([eventType isEqualToString:@"VISIT"]) { + return GrowingPBEventType_Visit; + } else if ([eventType isEqualToString:@"CUSTOM"]) { + return GrowingPBEventType_Custom; + } else if ([eventType isEqualToString:@"VISITOR_ATTRIBUTES"]) { + return GrowingPBEventType_VisitorAttributes; + } else if ([eventType isEqualToString:@"LOGIN_USER_ATTRIBUTES"]) { + return GrowingPBEventType_LoginUserAttributes; + } else if ([eventType isEqualToString:@"CONVERSION_VARIABLES"]) { + return GrowingPBEventType_ConversionVariables; + } else if ([eventType isEqualToString:@"APP_CLOSED"]) { + return GrowingPBEventType_AppClosed; + } else if ([eventType isEqualToString:@"PAGE"]) { + return GrowingPBEventType_Page; + } else if ([eventType isEqualToString:@"VIEW_CLICK"]) { + return GrowingPBEventType_ViewClick; + } else if ([eventType isEqualToString:@"VIEW_CHANGE"]) { + return GrowingPBEventType_ViewChange; + } else if ([eventType isEqualToString:@"FORM_SUBMIT"]) { + return GrowingPBEventType_FormSubmit; + } else if ([eventType isEqualToString:@"ACTIVATE"]) { + return GrowingPBEventType_Activate; + } + + return GrowingPBEventType_GPBUnrecognizedEnumeratorValue; +} + @end diff --git a/Services/Protobuf/GrowingEventProtobufDatabase.m b/Services/Protobuf/GrowingEventProtobufDatabase.m index 94551d352..e94bcebd8 100644 --- a/Services/Protobuf/GrowingEventProtobufDatabase.m +++ b/Services/Protobuf/GrowingEventProtobufDatabase.m @@ -34,7 +34,11 @@ + (instancetype)databaseWithPath:(NSString *)path error:(NSError **)error { NSURL *url = [NSURL fileURLWithPath:path].URLByDeletingLastPathComponent; path = [url URLByAppendingPathComponent:lastPathComponent].path; - return [super databaseWithPath:path persistenceClass:GrowingEventProtobufPersistence.class error:error]; + return [super databaseWithPath:path error:error]; +} + ++ (Class)persistenceClass { + return GrowingEventProtobufPersistence.class; } #pragma mark - Private Methods diff --git a/Services/Protobuf/GrowingEventProtobufPersistence.m b/Services/Protobuf/GrowingEventProtobufPersistence.m index 2e743d6e3..6c9d682fd 100644 --- a/Services/Protobuf/GrowingEventProtobufPersistence.m +++ b/Services/Protobuf/GrowingEventProtobufPersistence.m @@ -93,6 +93,28 @@ + (NSData *)buildRawEventsFromEvents:(NSArray #endif } ++ (NSData *)buildRawEventsFromJsonObjects:(NSArray *)jsonObjects { +#if SWIFT_PACKAGE + NSMutableArray *list = [NSMutableArray array]; + for (NSDictionary *jsonObject in jsonObjects) { + GrowingSwiftProtobuf *dtoBox = [GrowingSwiftProtobuf parseFromJsonObject:jsonObject]; + if (dtoBox) { + [list addObject:dtoBox]; + } + } + return [GrowingSwiftProtobuf serializedDatasFromList:list]; +#else + GrowingPBEventV3List *list = [[GrowingPBEventV3List alloc] init]; + for (NSDictionary *jsonObject in jsonObjects) { + GrowingPBEventV3Dto *dto = [GrowingPBEventV3Dto growingHelper_parseFromJsonObject:jsonObject]; + if (dto) { + [list.valuesArray addObject:dto]; + } + } + return list.data; +#endif +} + - (id)toJSONObject { #if SWIFT_PACKAGE return self.dtoBox.toJsonObject; diff --git a/Services/SwiftProtobuf/SwiftProtobuf.swift b/Services/SwiftProtobuf/SwiftProtobuf.swift index 55804488c..9bc127cae 100644 --- a/Services/SwiftProtobuf/SwiftProtobuf.swift +++ b/Services/SwiftProtobuf/SwiftProtobuf.swift @@ -42,6 +42,17 @@ public class SwiftProtobufWrapper: NSObject { return nil } } + + @objc(parseFromJsonObject:) + public static func parse(from jsonObject: [String: AnyObject]) -> SwiftProtobufWrapper? { + do { + let data = try JSONSerialization.data(withJSONObject: jsonObject) + let dto = try EventDto(jsonUTF8Data: data) + return SwiftProtobufWrapper(dto) + } catch { + return nil + } + } @objc public func toJsonObject() -> [String: AnyObject]? { From f7ef646230c87d88be73cd3771b8935bb4dffede Mon Sep 17 00:00:00 2001 From: runner Date: Wed, 9 Aug 2023 08:09:33 +0000 Subject: [PATCH 055/126] style: code format --- Services/SwiftProtobuf/SwiftProtobuf.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Services/SwiftProtobuf/SwiftProtobuf.swift b/Services/SwiftProtobuf/SwiftProtobuf.swift index 9bc127cae..c9011b9a6 100644 --- a/Services/SwiftProtobuf/SwiftProtobuf.swift +++ b/Services/SwiftProtobuf/SwiftProtobuf.swift @@ -42,7 +42,7 @@ public class SwiftProtobufWrapper: NSObject { return nil } } - + @objc(parseFromJsonObject:) public static func parse(from jsonObject: [String: AnyObject]) -> SwiftProtobufWrapper? { do { From b9f02f60892d1a9c151e995a1b371df3735a4133 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 16:46:38 +0800 Subject: [PATCH 056/126] ci: update ci --- .../NSNotificationCenterAutotrackTest.m | 6 ++-- .../Autotrack/UICollectionViewAutotrackTest.m | 6 ++-- .../Autotrack/UITableViewAutotrackTest.m | 6 ++-- .../Autotrack/UIApplicationAutotrackTest.m | 1 - .../ModulesTests/HybridTests/HybridTest.m | 6 ++-- .../ProtobufTests/ProtobufRequestHeaderTest.m | 34 +++++++++++++++++-- .../DatabaseTests/JSONDatabaseTest.m | 14 ++++---- .../DatabaseTests/JSONPersistenceTest.m | 8 ++--- .../DatabaseTests/DatabaseTest.m | 17 +++++----- .../TrackerCoreTests/EventTests/EventTest.m | 6 ++-- .../ManagerTests/GrowingSessionTest.m | 6 ++-- Example/Podfile | 2 -- Podfile.lock | 7 ++-- 13 files changed, 72 insertions(+), 47 deletions(-) diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m index cde098583..996533386 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m @@ -24,7 +24,7 @@ #import "GrowingTrackerCore/Manager/GrowingSession.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingAutotrackerCore/Autotrack/NSNotificationCenter+GrowingAutotracker.h" #import "MockEventQueue.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" @@ -61,8 +61,8 @@ + (void)setUp { GrowingConfigurationManager.sharedInstance.trackConfiguration = config; // 避免insertEventToDatabase异常 - [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventFMDatabase.class]; + [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) + implClass:GrowingEventProtobufDatabase.class]; // 初始化sessionId [GrowingSession startSession]; } diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m index 7fcdc40a9..479a672cd 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m @@ -24,7 +24,7 @@ #import "GrowingTrackerCore/Manager/GrowingSession.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingAutotrackerCore/Autotrack/UICollectionView+GrowingAutotracker.h" #import "MockEventQueue.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" @@ -104,8 +104,8 @@ + (void)setUp { GrowingConfigurationManager.sharedInstance.trackConfiguration = config; // 避免insertEventToDatabase异常 - [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventFMDatabase.class]; + [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) + implClass:GrowingEventProtobufDatabase.class]; // 初始化sessionId [GrowingSession startSession]; } diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m index 68b666c84..db88cc41e 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m @@ -24,7 +24,7 @@ #import "GrowingTrackerCore/Manager/GrowingSession.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.h" #import "MockEventQueue.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" @@ -104,8 +104,8 @@ + (void)setUp { GrowingConfigurationManager.sharedInstance.trackConfiguration = config; // 避免insertEventToDatabase异常 - [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventFMDatabase.class]; + [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) + implClass:GrowingEventProtobufDatabase.class]; // 初始化sessionId [GrowingSession startSession]; } diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m index 514b6f740..0e3cda04f 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m @@ -24,7 +24,6 @@ #import "GrowingTrackerCore/Manager/GrowingSession.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" #import "GrowingAutotrackerCore/Autotrack/UIApplication+GrowingAutotracker.h" #import "MockEventQueue.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" diff --git a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m index 61fab98e1..6e80af6d3 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m @@ -31,7 +31,7 @@ #import "GrowingTrackerCore/Event/GrowingEventGenerator.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" @interface GrowingHybridBridgeProvider (XCTest) @@ -54,8 +54,8 @@ @implementation HybridTest - (void)setUp { self.provider = GrowingHybridBridgeProvider.sharedInstance; - [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventFMDatabase.class]; + [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) + implClass:GrowingEventProtobufDatabase.class]; [GrowingSession startSession]; GrowingTrackConfiguration *config = [GrowingTrackConfiguration configurationWithProjectId:@"test"]; config.idMappingEnabled = YES; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m index 73aa27835..2fc3c1d9f 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m @@ -19,7 +19,10 @@ #import -#import "Services/Protobuf/GrowingEventRequestProtobufAdapter.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "GrowingAutotrackConfiguration.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "Modules/DefaultServices/GrowingEventRequestProtobufAdapter.h" #import "Modules/DefaultServices/GrowingEventRequestJSONAdapter.h" @interface ProtobufRequestHeaderTest : XCTestCase @@ -36,7 +39,11 @@ - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. } -- (void)testRequestHeader { +- (void)test01RequestHeaderProtobufFirst { + GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; + config.useProtobuf = YES; + [GrowingRealAutotracker trackerWithConfiguration:config launchOptions:nil]; + GrowingEventRequestProtobufAdapter *adapter = [GrowingEventRequestProtobufAdapter adapterWithRequest:nil]; GrowingEventRequestJSONAdapter *adapter2 = [GrowingEventRequestJSONAdapter adapterWithRequest:nil]; XCTAssertLessThan(adapter2.priority, adapter.priority); @@ -55,4 +62,27 @@ - (void)testRequestHeader { } } +- (void)test02RequestHeaderJSONFirst { + GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; + config.useProtobuf = NO; + [GrowingRealAutotracker trackerWithConfiguration:config launchOptions:nil]; + + GrowingEventRequestProtobufAdapter *adapter = [GrowingEventRequestProtobufAdapter adapterWithRequest:nil]; + GrowingEventRequestJSONAdapter *adapter2 = [GrowingEventRequestJSONAdapter adapterWithRequest:nil]; + XCTAssertLessThan(adapter.priority, adapter2.priority); + + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.growingio.com"]]; + request = [adapter adaptedURLRequest:request]; + request = [adapter2 adaptedURLRequest:request]; + + NSDictionary *allHTTPHeaderFields = request.allHTTPHeaderFields; + for (NSString *key in allHTTPHeaderFields.allKeys) { + if ([key isEqualToString:@"Content-Type"]) { + NSString *value = allHTTPHeaderFields[key]; + XCTAssertEqualObjects(value, @"application/json"); + break; + } + } +} + @end diff --git a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m index c79d41dc9..42872de11 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m @@ -20,8 +20,8 @@ #import #import "InvocationHelper.h" -#import "Services/Database/GrowingEventFMDatabase.h" -#import "Services/Database/GrowingEventJSONPersistence.h" +#import "Services/JSON/GrowingEventJSONDatabase.h" +#import "Services/JSON/GrowingEventJSONPersistence.h" #import "GrowingTrackerCore/Event/GrowingVisitEvent.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" #import "GrowingTrackerCore/FileStorage/GrowingFileStorage.h" @@ -43,18 +43,18 @@ - (void)tearDown { } - (void)testDatabaseBuildRawEvents { - NSData *raw = [GrowingEventFMDatabase buildRawEventsFromEvents:@[self.customEventPersistence]]; + NSData *raw = [GrowingEventJSONDatabase buildRawEventsFromEvents:@[self.customEventPersistence]]; XCTAssertNotNil(raw); } - (void)testDatabasePersistence { GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder.build); - id persistence = [GrowingEventFMDatabase persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; + id persistence = [GrowingEventJSONDatabase persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; XCTAssertNotNil(persistence); } - (void)testDatabaseInstanceMethods { - GrowingEventFMDatabase *database = [GrowingEventFMDatabase databaseWithPath:self.path error:nil]; + GrowingEventJSONDatabase *database = [GrowingEventJSONDatabase databaseWithPath:self.path error:nil]; XCTAssertNotNil(database.db); // clean expired event if need @@ -102,7 +102,7 @@ - (void)testDatabaseInstanceMethods { // last error NSString *errorPath = @"errorPath"; NSError *error = nil; - GrowingEventFMDatabase *errorDatabase = [GrowingEventFMDatabase databaseWithPath:errorPath error:&error]; + GrowingEventJSONDatabase *errorDatabase = [GrowingEventJSONDatabase databaseWithPath:errorPath error:&error]; if (error) { // 这里使用一个错误/无权限路径来实现 Database 初始化异常 // 使用模拟器运行,实测不会因错误/无权限路径导致初始化异常,error 为 nil,不会进到这一步 @@ -111,7 +111,7 @@ - (void)testDatabaseInstanceMethods { } - (void)testDatabaseEventIO { - GrowingEventFMDatabase *database = [GrowingEventFMDatabase databaseWithPath:self.path error:nil]; + GrowingEventJSONDatabase *database = [GrowingEventJSONDatabase databaseWithPath:self.path error:nil]; XCTAssertNotNil(database.db); // clear all events diff --git a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m index 698ef303f..da94db485 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m @@ -19,7 +19,7 @@ #import -#import "Services/Database/GrowingEventJSONPersistence.h" +#import "Services/JSON/GrowingEventJSONPersistence.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" @@ -41,13 +41,13 @@ - (void)testPersistenceInit { GrowingEventJSONPersistence *p = [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:self.event.eventType - jsonString:self.event.toDictionary.growingHelper_jsonString + data:self.event.toDictionary.growingHelper_jsonString policy:self.event.sendPolicy]; XCTAssertNotNil(p); XCTAssertEqualObjects(p.eventUUID, uuid); XCTAssertEqualObjects(p.eventType, self.event.eventType); XCTAssertEqual(p.policy, self.event.sendPolicy); - XCTAssertEqualObjects(p.rawJsonString, self.event.toDictionary.growingHelper_jsonString); + XCTAssertEqualObjects(p.data, self.event.toDictionary.growingHelper_jsonString); } - (void)testPersistenceWithEvent { @@ -57,7 +57,7 @@ - (void)testPersistenceWithEvent { XCTAssertEqualObjects(p.eventUUID, uuid); XCTAssertEqualObjects(p.eventType, self.event.eventType); XCTAssertEqual(p.policy, self.event.sendPolicy); - XCTAssertEqualObjects(p.rawJsonString, self.event.toDictionary.growingHelper_jsonString); + XCTAssertEqualObjects(p.data, self.event.toDictionary.growingHelper_jsonString); } - (void)testBuildRawEventsFromEvents { diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m index af6a60686..06b3ff5b5 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m @@ -23,9 +23,9 @@ #import "InvocationHelper.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" +#import "Services/JSON/GrowingEventJSONDatabase.h" #import "GrowingTrackerCore/Database/GrowingEventDatabase.h" -#import "Services/Database/GrowingEventJSONPersistence.h" +#import "Services/JSON/GrowingEventJSONPersistence.h" #import "GrowingTrackerCore/Event/GrowingVisitEvent.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/FileStorage/GrowingFileStorage.h" @@ -42,11 +42,11 @@ @implementation DatabaseTest + (void)setUp { [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventFMDatabase.class]; + implClass:GrowingEventJSONDatabase.class]; } - (void)setUp { - GrowingEventDatabase *database = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath]]; + GrowingEventDatabase *database = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath] isProtobuf:NO]; XCTAssertNotNil(database); self.database = database; @@ -80,7 +80,6 @@ - (void)tearDown { - (void)testDatabase { { XCTAssertTrue([self.database clearAllItems]); - XCTAssertTrue([self.database cleanExpiredDataIfNeeded]); XCTAssertEqual(self.database.countOfEvents, 0); NSArray *events = [self.database getEventsWithPackageNum:1]; @@ -94,7 +93,7 @@ - (void)testDatabase { GrowingEventJSONPersistence *event = [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:GrowingEventTypeVisit - jsonString:self.event.toDictionary.growingHelper_jsonString + data:self.event.toDictionary.growingHelper_jsonString policy:GrowingEventSendPolicyInstant]; XCTAssertNoThrow([self.database setEvent:event forKey:uuid]); XCTAssertEqual(self.database.countOfEvents, 1); @@ -107,10 +106,10 @@ - (void)testDatabase { GrowingEventJSONPersistence *event = [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:GrowingEventTypeVisit - jsonString:self.event.toDictionary.growingHelper_jsonString + data:self.event.toDictionary.growingHelper_jsonString policy:GrowingEventSendPolicyInstant]; - XCTAssertNoThrow([GrowingEventDatabase buildRawEventsFromEvents:@[event]]); - XCTAssertNoThrow([GrowingEventDatabase persistenceEventWithEvent:self.event uuid:uuid]); + XCTAssertNoThrow([self.database buildRawEventsFromEvents:@[event]]); + XCTAssertNoThrow([self.database persistenceEventWithEvent:self.event uuid:uuid]); } } diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m index 248475908..7b7e503f8 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m @@ -25,7 +25,7 @@ #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" #import "MockEventQueue.h" #import "ManualTrackHelper.h" @@ -55,8 +55,8 @@ + (void)setUp { GrowingConfigurationManager.sharedInstance.trackConfiguration = config; // 避免insertEventToDatabase异常 - [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventFMDatabase.class]; + [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) + implClass:GrowingEventProtobufDatabase.class]; // 初始化sessionId [GrowingSession startSession]; // userId userKey diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m index 06bab8df6..ece677483 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m @@ -24,7 +24,7 @@ #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" #import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Database/GrowingEventFMDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "MockEventQueue.h" #import "GrowingTrackerCore/Event/GrowingTrackEventType.h" #import "InvocationHelper.h" @@ -43,8 +43,8 @@ + (void)setUp { GrowingConfigurationManager.sharedInstance.trackConfiguration = config; // 避免insertEventToDatabase异常 - [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingEventDatabaseService) - implClass:GrowingEventFMDatabase.class]; + [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) + implClass:GrowingEventProtobufDatabase.class]; [GrowingSession startSession]; [GrowingSession.currentSession generateVisit]; diff --git a/Example/Podfile b/Example/Podfile index 88b9126dd..a2eea6741 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -13,7 +13,6 @@ target 'Example' do pod 'GrowingAnalytics/Autotracker', :path => '../' # pod 'GrowingAnalytics/Tracker', :path => '../' # pod 'GrowingAnalytics/Hybrid', :path => '../' - pod 'GrowingAnalytics/Protobuf', :path => '../' pod 'GrowingAnalytics/Advert', :path => '../' # pod 'GrowingAnalytics/Flutter', :path => '../' # pod 'GrowingAnalytics/DISABLE_IDFA', :path => '../' #禁用idfa @@ -50,7 +49,6 @@ end target 'ProtobufTests' do pod 'GrowingAnalytics/Autotracker', :path => '../' - pod 'GrowingAnalytics/Protobuf', :path => '../' end target 'AdvertTests' do diff --git a/Podfile.lock b/Podfile.lock index eed680014..c4853306f 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -114,7 +114,7 @@ PODS: - LBXScan/Types (2.3) - LBXScan/UI (2.3): - LBXScan/Types (~> 2.2) - - Protobuf (3.23.4) + - Protobuf (3.24.0) - SDCycleScrollView (1.82): - SDWebImage (>= 5.0.0) - SDWebImage (5.17.0): @@ -126,7 +126,6 @@ DEPENDENCIES: - GrowingAnalytics/APM (from `./`) - GrowingAnalytics/Autotracker (from `./`) - GrowingAnalytics/ImpressionTrack (from `./`) - - GrowingAnalytics/Protobuf (from `./`) - GrowingAnalytics/Tracker (from `./`) - GrowingAPM - GrowingToolsKit (>= 1.1.3) @@ -157,10 +156,10 @@ SPEC CHECKSUMS: GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 KIF: 7660c626b0f2d4562533590960db70a36d640558 LBXScan: e51449f0832d1fe17da632af0d22adeb3cfa3543 - Protobuf: c6bc59bbab3d38a71c67f62d7cb7ca8f8ea4eca1 + Protobuf: 74a8b46ebe3001096a6f4b624e9efbae8adb2edd SDCycleScrollView: a0d74c3384caa72bdfc81470bdbc8c14b3e1fbcf SDWebImage: 750adf017a315a280c60fde706ab1e552a3ae4e9 -PODFILE CHECKSUM: d18ae04aaea2c73be8383f04c6feea89caed3e99 +PODFILE CHECKSUM: 86ce707be5dfe866874f2b2c58992e50404ff30e COCOAPODS: 1.12.1 From d7e731fcc039a85d2773bfe76be2a30fc667e88d Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 17:07:38 +0800 Subject: [PATCH 057/126] fix: xindex -> xcontent --- .../Helper/ManualTrackHelper.m | 8 +-- .../Event/A1ViewClickEventsTest.m | 64 +++++++++---------- .../AutotrackerTests/Event/A3PageEventsTest.m | 14 ++-- .../WebCircleTests/WebCircleTest.m | 2 +- .../GrowingNode/GrowingNodeHelper.h | 2 +- .../GrowingNode/GrowingNodeHelper.m | 22 +++---- .../GrowingNode/GrowingViewChangeProvider.m | 5 +- .../GrowingNode/GrowingViewClickProvider.m | 4 +- .../GrowingNode/GrowingViewNode.h | 18 +++--- .../GrowingNode/GrowingViewNode.m | 42 ++++++------ GrowingAutotrackerCore/Page/GrowingPage.m | 6 +- .../Event/Autotrack/GrowingViewElementEvent.h | 6 +- .../Event/Autotrack/GrowingViewElementEvent.m | 8 +-- .../Event/GrowingNodeProtocol.h | 2 +- .../Events/GrowingHybridViewElementEvent.h | 3 - .../Events/GrowingHybridViewElementEvent.m | 9 --- Modules/WebCircle/GrowingWebCircle.m | 10 +-- Modules/WebCircle/GrowingWebCircleElement.h | 12 ++-- Modules/WebCircle/GrowingWebCircleElement.m | 16 ++--- .../Catagory/GrowingBaseEvent+Protobuf.m | 1 - .../GrowingPBEventV3Dto+GrowingHelper.m | 4 -- Services/Protobuf/Proto/GrowingEvent.pbobjc.h | 3 - Services/Protobuf/Proto/GrowingEvent.pbobjc.m | 11 ---- Services/Protobuf/Proto/event_v3.proto | 1 - Services/SwiftProtobuf/SwiftProtobuf.swift | 10 --- Services/SwiftProtobuf/event_v3.pb.swift | 13 ---- 26 files changed, 121 insertions(+), 175 deletions(-) diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m index f819ce385..37e99c8e0 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m @@ -75,8 +75,8 @@ + (BOOL)viewClickEventCheck:(NSDictionary *)event { if (event.count == 0) { return NO; } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"xpath"]]; - NSArray *optional = @[@"path", @"textValue", @"index", @"hyperlink", @"query", @"xindex", @"xcontent"]; + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"xpath", @"xcontent"]]; + NSArray *optional = @[@"path", @"textValue", @"index", @"hyperlink", @"query"]; return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } @@ -84,8 +84,8 @@ + (BOOL)viewChangeEventCheck:(NSDictionary *)event { if (event.count == 0) { return NO; } - NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"xpath"]]; - NSArray *optional = @[@"path", @"textValue", @"index", @"hyperlink", @"query", @"xindex", @"xcontent"]; + NSArray *protocol = [self.context arrayByAddingObjectsFromArray:@[@"xpath", @"xcontent"]]; + NSArray *optional = @[@"path", @"textValue", @"index", @"hyperlink", @"query"]; return [self protocolCheck:event protocol:protocol] && [self emptyPropertyCheck:event optional:optional]; } diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index e97e19537..dea38303b 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -37,19 +37,19 @@ - (void)tearDown { [[viewTester usingLabel:@"UI界面"] tap]; } -- (void)checkWebCirclePathWithView:(UIView *)view xpath:(NSString *)xpathForView xindex:(NSString *)xindexForView originxindex:(NSString *)originxindexForView { - // 检查圈选的计算逻辑得出的xpath、xindex是否正确 +- (void)checkWebCirclePathWithView:(UIView *)view xpath:(NSString *)xpathForView xcontent:(NSString *)xcontentForView originxcontent:(NSString *)originxcontentForView { + // 检查圈选的计算逻辑得出的xpath、xcontent是否正确 GrowingPage *page = [[GrowingPageManager sharedInstance] findPageByView:view]; NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; - NSString *pagexindex = pathInfo[@"xindex"]; - [GrowingNodeHelper recalculateXpath:view block:^(NSString * _Nonnull xpath, NSString * _Nonnull xindex, NSString * _Nonnull originxindex) { + NSString *pagexcontent = pathInfo[@"xcontent"]; + [GrowingNodeHelper recalculateXpath:view block:^(NSString * _Nonnull xpath, NSString * _Nonnull xcontent, NSString * _Nonnull originxcontent) { xpath = [NSString stringWithFormat:@"%@/%@", pagexpath, xpath]; - xindex = [NSString stringWithFormat:@"%@/%@", pagexindex, xindex]; - originxindex = [NSString stringWithFormat:@"%@/%@", pagexindex, originxindex]; + xcontent = [NSString stringWithFormat:@"%@/%@", pagexcontent, xcontent]; + originxcontent = [NSString stringWithFormat:@"%@/%@", pagexcontent, originxcontent]; XCTAssertEqualObjects(xpathForView, xpath); - XCTAssertEqualObjects(xindexForView, xindex); - XCTAssertEqualObjects(originxindexForView, originxindex); + XCTAssertEqualObjects(xcontentForView, xcontent); + XCTAssertEqualObjects(originxcontentForView, originxcontent); }]; } @@ -64,9 +64,9 @@ - (void)test01AlertButtonClick { NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/" @"_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfac" @"eActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"; - NSString *xindexForView = @"/0/1/0/0/0/0/0/0/0/1/0"; - NSString *originxindexForView = @"/0/1/0/0/0/0/0/0/0/1/0"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + NSString *xcontentForView = @"/0/1/0/0/0/0/0/0/0/1/0"; + NSString *originxcontentForView = @"/0/1/0/0/0/0/0/0/0/1/0"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; [actor tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -82,7 +82,7 @@ - (void)test01AlertButtonClick { XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"取消"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); - XCTAssertEqualObjects(dic[@"xindex"], xindexForView); + XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); } { @@ -95,7 +95,7 @@ - (void)test01AlertButtonClick { XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"ShowAlert"); XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/3"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/3"); } } @@ -149,9 +149,9 @@ - (void)test03ButtonWithImageViewClick { KIFUIViewTestActor *actor = [viewTester usingLabel:@"Food"]; NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; - NSString *xindexForView = @"/0/1/0/0/0/0"; - NSString *originxindexForView = @"/0/1/0/0/0/0"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + NSString *xcontentForView = @"/0/1/0/0/0/0"; + NSString *originxcontentForView = @"/0/1/0/0/0/0"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; [actor tap]; [[viewTester usingLabel:@"好的"] tap]; @@ -167,7 +167,7 @@ - (void)test03ButtonWithImageViewClick { XCTAssertEqualObjects(dic[@"textValue"], @"Food"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); - XCTAssertEqualObjects(dic[@"xindex"], xindexForView); + XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); } } @@ -178,9 +178,9 @@ - (void)test04UIViewButtonClick { KIFUIViewTestActor *actor = [viewTester usingLabel:@"Fire"]; NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; - NSString *xindexForView = @"/0/1/0/0/0/1"; - NSString *originxindexForView = @"/0/1/0/0/0/1"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + NSString *xcontentForView = @"/0/1/0/0/0/1"; + NSString *originxcontentForView = @"/0/1/0/0/0/1"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; [actor tap]; [[viewTester usingLabel:@"好的"] tap]; @@ -196,7 +196,7 @@ - (void)test04UIViewButtonClick { XCTAssertEqualObjects(dic[@"textValue"], @"Fire"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); - XCTAssertEqualObjects(dic[@"xindex"], xindexForView); + XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); } } @@ -208,9 +208,9 @@ - (void)test05UISegmentedControlClick { KIFUIViewTestActor *actor = [viewTester usingLabel:@"ThirdSegment"]; NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UISegmentedControl/UISegment"; - NSString *xindexForView = @"/0/1/0/0/0/-"; - NSString *originxindexForView = @"/0/1/0/0/0/2"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + NSString *xcontentForView = @"/0/1/0/0/0/-"; + NSString *originxcontentForView = @"/0/1/0/0/0/2"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; [actor tap]; [viewTester waitForAnimationsToFinish]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -226,7 +226,7 @@ - (void)test05UISegmentedControlClick { XCTAssertEqualObjects(dic[@"textValue"], @"Third"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); XCTAssertEqualObjects(dic[@"index"], @(2)); - XCTAssertEqualObjects(dic[@"xindex"], xindexForView); + XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); } } @@ -254,7 +254,7 @@ - (void)test06ClickCustomContent { XCTAssertEqualObjects(dic[@"textValue"], @"Water"); XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0/1"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/0/1"); } [[viewTester usingLabel:@"好的"] tap]; @@ -267,9 +267,9 @@ - (void)test07UITableViewHeaderFooterViewButtonClick { KIFUIViewTestActor *actor = [viewTester usingLabel:@"header1"]; NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOMeasurementProtocolTableViewController/UITableView/UITableViewHeaderFooterView/UIButton"; - NSString *xindexForView = @"/0/0/0/0/1/0"; - NSString *originxindexForView = @"/0/0/0/0/1/0"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xindex:xindexForView originxindex:originxindexForView]; + NSString *xcontentForView = @"/0/0/0/0/1/0"; + NSString *originxcontentForView = @"/0/0/0/0/1/0"; + [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; [actor tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -284,7 +284,7 @@ - (void)test07UITableViewHeaderFooterViewButtonClick { XCTAssertEqualObjects(dic[@"textValue"], @"header1"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); - XCTAssertEqualObjects(dic[@"xindex"], xindexForView); + XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); } } @@ -314,7 +314,7 @@ - (void)test08IgnoreViewClass { XCTAssertEqualObjects(dic[@"textValue"], @"IgnoreButton2"); XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingIgnoreButton2"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/0"); } - (void)test09IgnoreViewClasses { @@ -343,7 +343,7 @@ - (void)test09IgnoreViewClasses { XCTAssertEqualObjects(dic[@"textValue"], @"NotIgnoreButton4"); XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingNotIgnoreButton4"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/1/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/0"); } @end diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m index 8fc98241c..dde856e72 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m @@ -86,7 +86,7 @@ - (void)test01AutotrackPage { XCTAssertEqualObjects( dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } } @@ -114,7 +114,7 @@ - (void)test02AutotrackPageDelay { XCTAssertEqualObjects( dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); } @@ -155,7 +155,7 @@ - (void)test02AutotrackPageDelay { XCTAssertEqualObjects( dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -194,7 +194,7 @@ - (void)test03AutotrackPageWithoutCallSuperViewDidAppear { XCTAssertEqualObjects( dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } } @@ -222,7 +222,7 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects( dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); } @@ -263,7 +263,7 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects( dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -318,7 +318,7 @@ - (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertEqualObjects( dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingAutotrackPageViewController/UIView/UIButton"); - XCTAssertEqualObjects(dic[@"xindex"], @"/0/0/0/0/0"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0/0/0/0"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index 0db1c3afe..8bc04a363 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -272,7 +272,7 @@ - (void)webCircleSocketParamsCheck:(NSDictionary *)dic { XCTAssertNotNil(element[@"domain"]); XCTAssertNotNil(element[@"zLevel"]); XCTAssertNotNil(element[@"xpath"]); - XCTAssertNotNil(element[@"xindex"]); + XCTAssertNotNil(element[@"xcontent"]); XCTAssertNotNil(element[@"page"]); XCTAssertNotNil(element[@"isContainer"]); } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h index 6a08aefbb..716a07ac3 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingNodeHelper : NSObject + (void)recalculateXpath:(UIView *)view - block:(void (^)(NSString *xpath, NSString *xindex, NSString *originxindex))block; + block:(void (^)(NSString *xpath, NSString *xcontent, NSString *originxcontent))block; + (GrowingViewNode *)getViewNode:(UIView *)view; + (NSString *)getViewNodeType:(UIView *)view; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index 5d6eecd31..cc93331eb 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -29,11 +29,11 @@ @implementation GrowingNodeHelper + (void)recalculateXpath:(UIView *)view - block:(void (^)(NSString *xpath, NSString *xindex, NSString *originxindex))block { + block:(void (^)(NSString *xpath, NSString *xcontent, NSString *originxcontent))block { id node = view; NSMutableArray *viewPathArray = [NSMutableArray array]; - NSMutableArray *xindexArray = [NSMutableArray array]; - NSMutableArray *originxindexArray = [NSMutableArray array]; + NSMutableArray *xcontentArray = [NSMutableArray array]; + NSMutableArray *originxcontentArray = [NSMutableArray array]; BOOL isSimilar = YES; while (node && [node isKindOfClass:[UIView class]]) { if ([self isIgnoredPrivateView:node]) { @@ -42,12 +42,12 @@ + (void)recalculateXpath:(UIView *)view } [viewPathArray addObject:node.growingNodeSubPath]; - [originxindexArray addObject:node.growingNodeSubIndex]; + [originxcontentArray addObject:node.growingNodeSubIndex]; if (isSimilar) { - [xindexArray addObject:node.growingNodeSubSimilarIndex]; + [xcontentArray addObject:node.growingNodeSubSimilarIndex]; isSimilar = NO; } else { - [xindexArray addObject:node.growingNodeSubIndex]; + [xcontentArray addObject:node.growingNodeSubIndex]; } node = node.growingNodeParent; @@ -59,10 +59,10 @@ + (void)recalculateXpath:(UIView *)view }; NSString *xpath = toStringBlock(viewPathArray); - NSString *xindex = toStringBlock(xindexArray); - NSString *originxindex = toStringBlock(originxindexArray); + NSString *xcontent = toStringBlock(xcontentArray); + NSString *originxcontent = toStringBlock(originxcontentArray); if (block) { - block(xpath, xindex, originxindex); + block(xpath, xcontent, originxcontent); } } @@ -92,8 +92,8 @@ + (GrowingViewNode *)getTopViewNode:(UIView *)view array:(NSPointerArray *)weakA .setIndex(-1) .setViewContent(rootview.growingNodeContent) .setXpath(rootview.growingNodeSubPath) - .setXindex(rootview.growingNodeSubSimilarIndex) - .setOriginXindex(rootview.growingNodeSubIndex) + .setXcontent(rootview.growingNodeSubSimilarIndex) + .setOriginXcontent(rootview.growingNodeSubIndex) .setNodeType([self getViewNodeType:rootview]) .build; } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index d35dcdc59..a2623f272 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -33,17 +33,18 @@ + (void)viewOnChange:(UIView *)view { GIOLogDebug(@"viewOnChange %@ is donotTrack", view); return; } + GrowingPage *page = [GrowingPageManager.sharedInstance findPageByView:view]; GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page]; GrowingViewNode *node = [GrowingNodeHelper getViewNode:view]; NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; - NSString *pagexindex = pathInfo[@"xindex"]; + NSString *pagexcontent = pathInfo[@"xcontent"]; GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange) .setPath(@"") .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) + .setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent]) .setIndex(node.index) .setTextValue(node.viewContent); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index d8b54853c..274b3090c 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -40,11 +40,11 @@ + (void)viewOnClick:(UIView *)view { NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; - NSString *pagexindex = pathInfo[@"xindex"]; + NSString *pagexcontent = pathInfo[@"xcontent"]; GrowingViewElementBuilder *builder = GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick) .setPath(@"") .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) + .setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent]) .setIndex(node.index) .setTextValue(node.viewContent); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h index 8301851ad..1151cf498 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.h @@ -30,12 +30,12 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak, readonly) UIView *view; @property (nonatomic, copy, readonly) NSString *_Nullable viewContent; @property (nonatomic, copy, readonly) NSString *xpath; -@property (nonatomic, copy, readonly) NSString *xindex; +@property (nonatomic, copy, readonly) NSString *xcontent; // 原始的位置组 -@property (nonatomic, copy, readonly) NSString *originxindex; +@property (nonatomic, copy, readonly) NSString *originxcontent; // 可点击的父节点xpath @property (nonatomic, copy, readonly) NSString *clickableParentXpath; -@property (nonatomic, copy, readonly) NSString *clickableParentXindex; +@property (nonatomic, copy, readonly) NSString *clickableParentXcontent; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; @@ -61,12 +61,12 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, readonly) UIView *view; @property (nonatomic, copy, readonly) NSString *_Nullable viewContent; @property (nonatomic, copy, readonly) NSString *xpath; -@property (nonatomic, copy, readonly) NSString *xindex; +@property (nonatomic, copy, readonly) NSString *xcontent; // 原始的位置组 -@property (nonatomic, copy, readonly) NSString *originxindex; +@property (nonatomic, copy, readonly) NSString *originxcontent; // 可点击的父节点xpath @property (nonatomic, copy, readonly) NSString *clickableParentXpath; -@property (nonatomic, copy, readonly) NSString *clickableParentXindex; +@property (nonatomic, copy, readonly) NSString *clickableParentXcontent; @property (nonatomic, copy, readonly) NSString *_Nullable nodeType; // 如果有父节点,且父节点为列表,则index有值,和父节点一致,否则为-1 @property (nonatomic, assign, readonly) int index; @@ -77,10 +77,10 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingViewNodeBuilder * (^)(UIView *value))setView; - (GrowingViewNodeBuilder * (^)(NSString *value))setXpath; -- (GrowingViewNodeBuilder * (^)(NSString *value))setXindex; -- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXindex; +- (GrowingViewNodeBuilder * (^)(NSString *value))setXcontent; +- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXcontent; - (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXpath; -- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXindex; +- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXcontent; - (GrowingViewNodeBuilder * (^)(int value))setIndex; - (GrowingViewNodeBuilder * (^)(int value))setPosition; - (GrowingViewNodeBuilder * (^)(NSString *value))setViewContent; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m index c6dfa7f1a..603c162fc 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m @@ -28,8 +28,8 @@ @interface GrowingViewNode () @property (nonatomic, copy, readwrite) NSString *xpath; -@property (nonatomic, copy, readwrite) NSString *xindex; -@property (nonatomic, copy, readwrite) NSString *originxindex; +@property (nonatomic, copy, readwrite) NSString *xcontent; +@property (nonatomic, copy, readwrite) NSString *originxcontent; @end @@ -40,10 +40,10 @@ - (instancetype)initWithBuilder:(GrowingViewNodeBuilder *)builder { _view = builder.view; _viewContent = builder.viewContent; _xpath = builder.xpath; - _xindex = builder.xindex; - _originxindex = builder.originxindex; + _xcontent = builder.xcontent; + _originxcontent = builder.originxcontent; _clickableParentXpath = builder.clickableParentXpath; - _clickableParentXindex = builder.clickableParentXindex; + _clickableParentXcontent = builder.clickableParentXcontent; _nodeType = builder.nodeType; _index = builder.index; _position = builder.position; @@ -60,11 +60,11 @@ - (void)recalculate { __weak typeof(self) weakSelf = self; [GrowingNodeHelper recalculateXpath:self.view - block:^(NSString *_Nonnull xpath, NSString *_Nonnull xindex, NSString *_Nonnull originxindex) { + block:^(NSString *_Nonnull xpath, NSString *_Nonnull xcontent, NSString *_Nonnull originxcontent) { __strong typeof(weakSelf) self = weakSelf; self.xpath = xpath; - self.xindex = xindex; - self.originxindex = originxindex; + self.xcontent = xcontent; + self.originxcontent = originxcontent; }]; } @@ -79,10 +79,10 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { return GrowingViewNode.builder.setView(view) .setIndex(self.index) .setXpath(self.xpath) - .setXindex(self.xindex) - .setOriginXindex(self.originxindex) + .setXcontent(self.xcontent) + .setOriginXcontent(self.originxcontent) .setClickableParentXpath(self.clickableParentXpath) - .setClickableParentXindex(self.clickableParentXindex) + .setClickableParentXcontent(self.clickableParentXcontent) .setHasListParent(self.hasListParent) .setViewContent(self.viewContent) .setPosition(self.position) @@ -105,16 +105,16 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { } NSString *parentXpath = self.view.growingNodeUserInteraction ? self.xpath : self.clickableParentXpath; - NSString *parentXindex = self.view.growingNodeUserInteraction ? self.xindex : self.clickableParentXindex; + NSString *parentXcontent = self.view.growingNodeUserInteraction ? self.xcontent : self.clickableParentXcontent; NSString *content = view.growingNodeContent; return GrowingViewNode.builder.setView(view) .setIndex((int)index) .setXpath([self.xpath stringByAppendingFormat:@"/%@", view.growingNodeSubPath]) - .setXindex([self.originxindex stringByAppendingFormat:@"/%@", view.growingNodeSubSimilarIndex]) - .setOriginXindex([self.originxindex stringByAppendingFormat:@"/%@", view.growingNodeSubIndex]) + .setXcontent([self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubSimilarIndex]) + .setOriginXcontent([self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubIndex]) .setClickableParentXpath(parentXpath) - .setClickableParentXindex(parentXindex) + .setClickableParentXcontent(parentXcontent) .setHasListParent(haslistParent) .setViewContent(content ? [content growingHelper_safeSubStringWithLength:50] : nil) .setPosition((int)view.growingNodeKeyIndex) @@ -141,16 +141,16 @@ @implementation GrowingViewNodeBuilder }; } -- (GrowingViewNodeBuilder * (^)(NSString *value))setXindex { +- (GrowingViewNodeBuilder * (^)(NSString *value))setXcontent { return ^(NSString *value) { - self->_xindex = value; + self->_xcontent = value; return self; }; } -- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXindex { +- (GrowingViewNodeBuilder * (^)(NSString *value))setOriginXcontent { return ^(NSString *value) { - self->_originxindex = value; + self->_originxcontent = value; return self; }; } @@ -162,9 +162,9 @@ @implementation GrowingViewNodeBuilder }; } -- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXindex { +- (GrowingViewNodeBuilder * (^)(NSString *value))setClickableParentXcontent { return ^(NSString *value) { - self->_clickableParentXindex = value; + self->_clickableParentXcontent = value; return self; }; } diff --git a/GrowingAutotrackerCore/Page/GrowingPage.m b/GrowingAutotrackerCore/Page/GrowingPage.m index d767bef74..bc66f5c71 100644 --- a/GrowingAutotrackerCore/Page/GrowingPage.m +++ b/GrowingAutotrackerCore/Page/GrowingPage.m @@ -117,15 +117,15 @@ - (NSDictionary *)pathInfo { } while (pageParent != nil); NSMutableString *xpath = [NSMutableString string]; - NSMutableString *xindex = [NSMutableString string]; + NSMutableString *xcontent = [NSMutableString string]; NSArray *array = pageTree.allObjects; for (int i = (int)(array.count - 1); i >= 0; i--) { GrowingPage *page = array[i]; [xpath appendFormat:@"/%@", NSStringFromClass(page.carrier.class)]; - [xindex appendFormat:@"/%@", page.tag ?: @"0"]; + [xcontent appendFormat:@"/%@", page.tag ?: @"0"]; } - return @{@"xpath": xpath, @"xindex": xindex}; + return @{@"xpath": xpath, @"xcontent": xcontent}; } @end diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h index 44d6d7c94..4d19250ff 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *path; @property (nonatomic, copy, readonly) NSString *textValue; @property (nonatomic, copy, readonly) NSString *xpath; -@property (nonatomic, copy, readonly) NSString *xindex; +@property (nonatomic, copy, readonly) NSString *xcontent; @property (nonatomic, assign, readonly) int index; + (GrowingViewElementBuilder *)builder; @@ -43,13 +43,13 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *pageName; @property (nonatomic, copy, readonly) NSString *textValue; @property (nonatomic, copy, readonly) NSString *xpath; -@property (nonatomic, copy, readonly) NSString *xindex; +@property (nonatomic, copy, readonly) NSString *xcontent; @property (nonatomic, assign, readonly) int index; - (GrowingViewElementBuilder * (^)(NSString *value))setPath; - (GrowingViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingViewElementBuilder * (^)(NSString *value))setXpath; -- (GrowingViewElementBuilder * (^)(NSString *value))setXindex; +- (GrowingViewElementBuilder * (^)(NSString *value))setXcontent; - (GrowingViewElementBuilder * (^)(int value))setIndex; - (GrowingViewElementBuilder * (^)(NSDictionary *value))setAttributes; diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m index 4e73d1526..3ed2107cc 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m @@ -31,7 +31,7 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { _path = subBuilder.pageName; _textValue = subBuilder.textValue; _xpath = subBuilder.xpath; - _xindex = subBuilder.xindex; + _xcontent = subBuilder.xcontent; _index = subBuilder.index; } return self; @@ -42,7 +42,7 @@ - (NSDictionary *)toDictionary { dataDictM[@"path"] = self.path; dataDictM[@"textValue"] = self.textValue; dataDictM[@"xpath"] = self.xpath; - dataDictM[@"xindex"] = self.xindex; + dataDictM[@"xcontent"] = self.xcontent; dataDictM[@"index"] = self.index >= 0 ? @(self.index) : nil; return dataDictM; } @@ -74,9 +74,9 @@ @implementation GrowingViewElementBuilder }; } -- (GrowingViewElementBuilder * (^)(NSString *value))setXindex { +- (GrowingViewElementBuilder * (^)(NSString *value))setXcontent { return ^(NSString *value) { - self->_xindex = value; + self->_xcontent = value; return self; }; } diff --git a/GrowingTrackerCore/Event/GrowingNodeProtocol.h b/GrowingTrackerCore/Event/GrowingNodeProtocol.h index ec4b50aed..c4e7c08c3 100644 --- a/GrowingTrackerCore/Event/GrowingNodeProtocol.h +++ b/GrowingTrackerCore/Event/GrowingNodeProtocol.h @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) NSInteger growingNodeKeyIndex; /// 完整的xpath由各个node的subPath拼接而成 @property (nonatomic, copy, readonly) NSString *growingNodeSubPath; -/// 完整的xindex由各个node的subIndex拼接而成 +/// 完整的xcontent由各个node的subIndex拼接而成 @property (nonatomic, copy, readonly) NSString *growingNodeSubIndex; /// 当同一视图下相同class的两个node点击行为相似 /// 当不需要区分点击哪一个node,仅需要区分点击那种类型时,使用该属性 diff --git a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h index 11b034337..a387aa402 100644 --- a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h +++ b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h @@ -25,7 +25,6 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingHybridViewElementEvent : GrowingViewElementEvent -@property (nonatomic, copy, readonly) NSString *xcontent; @property (nonatomic, copy, readonly) NSString *hyperlink; @property (nonatomic, copy, readonly) NSString *query; @@ -35,11 +34,9 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingHybridViewElementBuilder : GrowingViewElementBuilder -@property (nonatomic, copy, readonly) NSString *xcontent; @property (nonatomic, copy, readonly) NSString *hyperlink; @property (nonatomic, copy, readonly) NSString *query; -- (GrowingHybridViewElementBuilder * (^)(NSString *value))setXcontent; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setQuery; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setHyperlink; diff --git a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m index 618521c14..425eb2778 100644 --- a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m +++ b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.m @@ -24,7 +24,6 @@ @implementation GrowingHybridViewElementEvent - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { if (self = [super initWithBuilder:builder]) { GrowingHybridViewElementBuilder *subBuilder = (GrowingHybridViewElementBuilder *)builder; - _xcontent = subBuilder.xcontent; _query = subBuilder.query; _hyperlink = subBuilder.hyperlink; } @@ -37,7 +36,6 @@ + (GrowingHybridViewElementBuilder *)builder { - (NSDictionary *)toDictionary { NSMutableDictionary *dataDictM = [NSMutableDictionary dictionaryWithDictionary:[super toDictionary]]; - dataDictM[@"xcontent"] = self.xcontent; dataDictM[@"query"] = self.query; dataDictM[@"hyperlink"] = self.hyperlink; return dataDictM; @@ -50,13 +48,6 @@ - (NSDictionary *)toDictionary { @implementation GrowingHybridViewElementBuilder -- (GrowingHybridViewElementBuilder * (^)(NSString *value))setXcontent { - return ^(NSString *value) { - self->_xcontent = value; - return self; - }; -} - - (GrowingHybridViewElementBuilder * (^)(NSString *value))setQuery { return ^(NSString *value) { self->_query = value; diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index 80fc74c03..ca9a441fd 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -145,19 +145,19 @@ - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node { GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page]; NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; - NSString *pagexindex = pathInfo[@"xindex"]; + NSString *pagexcontent = pathInfo[@"xcontent"]; GrowingWebCircleElementBuilder *builder = GrowingWebCircleElement.builder.setRect(node.view.growingNodeFrame) .setContent(node.viewContent) .setZLevel(self.zLevel++) .setIndex(node.index) .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) - .setXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.xindex]) + .setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent]) .setNodeType(node.nodeType) .setPage(autotrackPage ? autotrackPage.alias : @""); if (node.clickableParentXpath) { builder = builder.setParentXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.clickableParentXpath]) - .setParentXindex([NSString stringWithFormat:@"%@/%@", pagexindex, node.clickableParentXindex]); + .setParentXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.clickableParentXcontent]); } GrowingWebCircleElement *element = builder.build; @@ -248,8 +248,8 @@ - (void)fillAllViewsForWebCircle:(NSDictionary *)dataDict completion:(void (^)(N .setIndex(-1) .setViewContent(topwindow.growingNodeContent) .setXpath(topwindow.growingNodeSubPath) - .setXindex(topwindow.growingNodeSubSimilarIndex) - .setOriginXindex(topwindow.growingNodeSubIndex) + .setXcontent(topwindow.growingNodeSubSimilarIndex) + .setOriginXcontent(topwindow.growingNodeSubIndex) .setNodeType([GrowingNodeHelper getViewNodeType:topwindow]) .build]; } diff --git a/Modules/WebCircle/GrowingWebCircleElement.h b/Modules/WebCircle/GrowingWebCircleElement.h index f0b9f51e5..9eb4e5c85 100644 --- a/Modules/WebCircle/GrowingWebCircleElement.h +++ b/Modules/WebCircle/GrowingWebCircleElement.h @@ -27,10 +27,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) int zLevel; @property (nonatomic, copy, readonly) NSString *_Nullable content; @property (nonatomic, copy, readonly) NSString *_Nonnull xpath; -@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; +@property (nonatomic, copy, readonly) NSString *_Nonnull xcontent; @property (nonatomic, copy, readonly) NSString *_Nonnull nodeType; @property (nonatomic, copy, readonly) NSString *_Nullable parentXpath; -@property (nonatomic, copy, readonly) NSString *_Nullable parentXindex; +@property (nonatomic, copy, readonly) NSString *_Nullable parentXcontent; @property (nonatomic, assign, readonly) BOOL isContainer; @property (nonatomic, assign, readonly) int index; @property (nonatomic, copy, readonly) NSString *_Nonnull page; @@ -51,10 +51,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) int zLevel; @property (nonatomic, copy, readonly) NSString *_Nullable content; @property (nonatomic, copy, readonly) NSString *_Nonnull xpath; -@property (nonatomic, copy, readonly) NSString *_Nonnull xindex; +@property (nonatomic, copy, readonly) NSString *_Nonnull xcontent; @property (nonatomic, copy, readonly) NSString *_Nonnull nodeType; @property (nonatomic, copy, readonly) NSString *_Nullable parentXpath; -@property (nonatomic, copy, readonly) NSString *_Nullable parentXindex; +@property (nonatomic, copy, readonly) NSString *_Nullable parentXcontent; @property (nonatomic, assign, readonly) BOOL isContainer; @property (nonatomic, assign, readonly) int index; @property (nonatomic, copy, readonly) NSString *_Nonnull page; @@ -63,10 +63,10 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingWebCircleElementBuilder * (^)(int value))setZLevel; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setContent; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setXpath; -- (GrowingWebCircleElementBuilder * (^)(NSString *value))setXindex; +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setXcontent; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setNodeType; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXpath; -- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXindex; +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXcontent; - (GrowingWebCircleElementBuilder * (^)(BOOL value))setIsContainer; - (GrowingWebCircleElementBuilder * (^)(int value))setIndex; - (GrowingWebCircleElementBuilder * (^)(NSString *value))setPage; diff --git a/Modules/WebCircle/GrowingWebCircleElement.m b/Modules/WebCircle/GrowingWebCircleElement.m index f23b1a222..781091981 100644 --- a/Modules/WebCircle/GrowingWebCircleElement.m +++ b/Modules/WebCircle/GrowingWebCircleElement.m @@ -32,12 +32,12 @@ - (instancetype)initWithBuilder:(GrowingWebCircleElementBuilder *)builder { _zLevel = builder.zLevel; _content = builder.content; _xpath = builder.xpath; - _xindex = builder.xindex; + _xcontent = builder.xcontent; _nodeType = builder.nodeType; _isContainer = builder.isContainer; _index = builder.index; _parentXpath = builder.parentXpath; - _parentXindex = builder.parentXindex; + _parentXcontent = builder.parentXcontent; _page = builder.page; _domain = [GrowingDeviceInfo currentDeviceInfo].bundleID; } @@ -54,12 +54,12 @@ - (NSDictionary *)toDictionary { dataDict[@"zLevel"] = @(self.zLevel); dataDict[@"content"] = self.content; dataDict[@"xpath"] = self.xpath; - dataDict[@"xindex"] = self.xindex; + dataDict[@"xcontent"] = self.xcontent; dataDict[@"nodeType"] = self.nodeType; dataDict[@"isContainer"] = @(self.isContainer); dataDict[@"index"] = self.index >= 0 ? @(self.index) : nil; dataDict[@"parentXPath"] = self.parentXpath; - dataDict[@"parentXIndex"] = self.parentXindex; + dataDict[@"parentXContent"] = self.parentXcontent; dataDict[@"page"] = self.page; dataDict[@"domain"] = self.domain; return [dataDict copy]; @@ -97,9 +97,9 @@ @implementation GrowingWebCircleElementBuilder }; } -- (GrowingWebCircleElementBuilder * (^)(NSString *value))setXindex { +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setXcontent { return ^(NSString *value) { - self->_xindex = value; + self->_xcontent = value; return self; }; } @@ -118,9 +118,9 @@ @implementation GrowingWebCircleElementBuilder }; } -- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXindex { +- (GrowingWebCircleElementBuilder * (^)(NSString *value))setParentXcontent { return ^(NSString *value) { - self->_parentXindex = value; + self->_parentXcontent = value; return self; }; } diff --git a/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index d6c23a828..5e47fd7f2 100644 --- a/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -88,7 +88,6 @@ - (GrowingPBEventV3Dto *)toProtobuf { dto.textValue = stringBlock(@"textValue"); dto.xpath = stringBlock(@"xpath"); dto.xcontent = stringBlock(@"xcontent"); - dto.xindex = stringBlock(@"xindex"); dto.index = int32Block(@"index"); dto.query = stringBlock(@"query"); dto.hyperlink = stringBlock(@"hyperlink"); diff --git a/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m index 17bfc3fa9..a1e3dc449 100644 --- a/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m +++ b/Services/Protobuf/Catagory/GrowingPBEventV3Dto+GrowingHelper.m @@ -132,9 +132,6 @@ - (id)growingHelper_jsonObject { if (self.xcontent.length > 0) { [dic setObject:self.xcontent forKey:@"xcontent"]; } - if (self.xindex.length > 0) { - [dic setObject:self.xindex forKey:@"xindex"]; - } if (self.index > 0) { [dic setObject:@(self.index) forKey:@"index"]; } @@ -221,7 +218,6 @@ + (nullable instancetype)growingHelper_parseFromJsonObject:(NSDictionary *)jsonO dto.textValue = jsonObject[@"textValue"]; dto.xpath = jsonObject[@"xpath"]; dto.xcontent = jsonObject[@"xcontent"]; - dto.xindex = jsonObject[@"xindex"]; dto.index = ((NSNumber *)jsonObject[@"index"]).intValue; dto.query = jsonObject[@"query"]; dto.hyperlink = jsonObject[@"hyperlink"]; diff --git a/Services/Protobuf/Proto/GrowingEvent.pbobjc.h b/Services/Protobuf/Proto/GrowingEvent.pbobjc.h index 7f61a44da..a4de7307e 100644 --- a/Services/Protobuf/Proto/GrowingEvent.pbobjc.h +++ b/Services/Protobuf/Proto/GrowingEvent.pbobjc.h @@ -133,7 +133,6 @@ typedef GPB_ENUM(GrowingPBEventV3Dto_FieldNumber) { GrowingPBEventV3Dto_FieldNumber_SendTime = 54, GrowingPBEventV3Dto_FieldNumber_UserKey = 55, GrowingPBEventV3Dto_FieldNumber_Xcontent = 56, - GrowingPBEventV3Dto_FieldNumber_Xindex = 57, }; GPB_FINAL @interface GrowingPBEventV3Dto : GPBMessage @@ -247,8 +246,6 @@ GPB_FINAL @interface GrowingPBEventV3Dto : GPBMessage @property(nonatomic, readwrite, copy, null_resettable) NSString *xcontent; -@property(nonatomic, readwrite, copy, null_resettable) NSString *xindex; - @end /** diff --git a/Services/Protobuf/Proto/GrowingEvent.pbobjc.m b/Services/Protobuf/Proto/GrowingEvent.pbobjc.m index d9a2da6ba..c6ce3efb9 100644 --- a/Services/Protobuf/Proto/GrowingEvent.pbobjc.m +++ b/Services/Protobuf/Proto/GrowingEvent.pbobjc.m @@ -168,7 +168,6 @@ @implementation GrowingPBEventV3Dto @dynamic sendTime; @dynamic userKey; @dynamic xcontent; -@dynamic xindex; typedef struct GrowingPBEventV3Dto__storage_ { uint32_t _has_storage_[2]; @@ -219,7 +218,6 @@ @implementation GrowingPBEventV3Dto NSString *projectKey; NSString *userKey; NSString *xcontent; - NSString *xindex; int64_t timestamp; double latitude; double longitude; @@ -692,15 +690,6 @@ + (GPBDescriptor *)descriptor { .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), .dataType = GPBDataTypeString, }, - { - .name = "xindex", - .dataTypeSpecific.clazz = Nil, - .number = GrowingPBEventV3Dto_FieldNumber_Xindex, - .hasIndex = 49, - .offset = (uint32_t)offsetof(GrowingPBEventV3Dto__storage_, xindex), - .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldClearHasIvarOnZero), - .dataType = GPBDataTypeString, - }, }; GPBDescriptor *localDescriptor = [GPBDescriptor allocDescriptorForClass:GPBObjCClass(GrowingPBEventV3Dto) diff --git a/Services/Protobuf/Proto/event_v3.proto b/Services/Protobuf/Proto/event_v3.proto index 8bd54b64e..bbdb0591c 100644 --- a/Services/Protobuf/Proto/event_v3.proto +++ b/Services/Protobuf/Proto/event_v3.proto @@ -62,7 +62,6 @@ message EventV3Dto { int64 send_time = 54; string user_key = 55; string xcontent = 56; - string xindex = 57; } message ResourceItem { diff --git a/Services/SwiftProtobuf/SwiftProtobuf.swift b/Services/SwiftProtobuf/SwiftProtobuf.swift index c9011b9a6..55f1c735a 100644 --- a/Services/SwiftProtobuf/SwiftProtobuf.swift +++ b/Services/SwiftProtobuf/SwiftProtobuf.swift @@ -143,7 +143,6 @@ extension GrowingBaseEvent { dto.textValue = textValue() dto.xpath = xpath() dto.xcontent = xcontent() - dto.xindex = xindex() dto.index = index() dto.query = query() dto.hyperlink = hyperlink() @@ -254,15 +253,6 @@ extension GrowingBaseEvent { return "" } - fileprivate func xindex() -> String { - let selector = Selector(("xindex")) - if self.responds(to: selector) { - let imp: IMP = method_getImplementation(class_getInstanceMethod(type(of: self), selector)!) - return unsafeBitCast(imp, to: (@convention(c)(GrowingBaseEvent, Selector) -> String?).self)(self, selector) ?? "" - } - return "" - } - fileprivate func index() -> Int32 { let selector = Selector(("index")) if self.responds(to: selector) { diff --git a/Services/SwiftProtobuf/event_v3.pb.swift b/Services/SwiftProtobuf/event_v3.pb.swift index fccfef6e7..90b66de16 100644 --- a/Services/SwiftProtobuf/event_v3.pb.swift +++ b/Services/SwiftProtobuf/event_v3.pb.swift @@ -365,11 +365,6 @@ struct Io_Growing_Tunnel_Protocol_EventV3Dto { set {_uniqueStorage()._xcontent = newValue} } - var xindex: String { - get {return _storage._xindex} - set {_uniqueStorage()._xindex = newValue} - } - var unknownFields = SwiftProtobuf.UnknownStorage() init() {} @@ -487,7 +482,6 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro 54: .standard(proto: "send_time"), 55: .standard(proto: "user_key"), 56: .same(proto: "xcontent"), - 57: .same(proto: "xindex"), ] fileprivate class _StorageClass { @@ -542,7 +536,6 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro var _sendTime: Int64 = 0 var _userKey: String = String() var _xcontent: String = String() - var _xindex: String = String() static let defaultInstance = _StorageClass() @@ -600,7 +593,6 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro _sendTime = source._sendTime _userKey = source._userKey _xcontent = source._xcontent - _xindex = source._xindex } } @@ -670,7 +662,6 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro case 54: try { try decoder.decodeSingularInt64Field(value: &_storage._sendTime) }() case 55: try { try decoder.decodeSingularStringField(value: &_storage._userKey) }() case 56: try { try decoder.decodeSingularStringField(value: &_storage._xcontent) }() - case 57: try { try decoder.decodeSingularStringField(value: &_storage._xindex) }() default: break } } @@ -836,9 +827,6 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro if !_storage._xcontent.isEmpty { try visitor.visitSingularStringField(value: _storage._xcontent, fieldNumber: 56) } - if !_storage._xindex.isEmpty { - try visitor.visitSingularStringField(value: _storage._xindex, fieldNumber: 57) - } } try unknownFields.traverse(visitor: &visitor) } @@ -899,7 +887,6 @@ extension Io_Growing_Tunnel_Protocol_EventV3Dto: SwiftProtobuf.Message, SwiftPro if _storage._sendTime != rhs_storage._sendTime {return false} if _storage._userKey != rhs_storage._userKey {return false} if _storage._xcontent != rhs_storage._xcontent {return false} - if _storage._xindex != rhs_storage._xindex {return false} return true } if !storagesAreEqual {return false} From 05a65e2664546a7cb208a720c7aaed47dd8b8c25 Mon Sep 17 00:00:00 2001 From: runner Date: Wed, 9 Aug 2023 09:08:35 +0000 Subject: [PATCH 058/126] style: code format --- .../GrowingNode/GrowingViewChangeProvider.m | 15 ++++++++------- .../GrowingNode/GrowingViewClickProvider.m | 13 +++++++------ Modules/WebCircle/GrowingWebCircle.m | 5 +++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index a2623f272..45c32c062 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -33,7 +33,7 @@ + (void)viewOnChange:(UIView *)view { GIOLogDebug(@"viewOnChange %@ is donotTrack", view); return; } - + GrowingPage *page = [GrowingPageManager.sharedInstance findPageByView:view]; GrowingPage *autotrackPage = [GrowingPageManager.sharedInstance findAutotrackPageByPage:page]; GrowingViewNode *node = [GrowingNodeHelper getViewNode:view]; @@ -41,12 +41,13 @@ + (void)viewOnChange:(UIView *)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(@"") + .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) + .setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent]) + .setIndex(node.index) + .setTextValue(node.viewContent); if (autotrackPage) { builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes); diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index 274b3090c..9d8f2e1d0 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -41,12 +41,13 @@ + (void)viewOnClick:(UIView *)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(@"") + .setXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.xpath]) + .setXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.xcontent]) + .setIndex(node.index) + .setTextValue(node.viewContent); if (autotrackPage) { builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes); diff --git a/Modules/WebCircle/GrowingWebCircle.m b/Modules/WebCircle/GrowingWebCircle.m index ca9a441fd..2f78a3813 100644 --- a/Modules/WebCircle/GrowingWebCircle.m +++ b/Modules/WebCircle/GrowingWebCircle.m @@ -156,8 +156,9 @@ - (NSMutableDictionary *)dictFromNode:(GrowingViewNode *)node { .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 = + builder.setParentXpath([NSString stringWithFormat:@"%@/%@", pagexpath, node.clickableParentXpath]) + .setParentXcontent([NSString stringWithFormat:@"%@/%@", pagexcontent, node.clickableParentXcontent]); } GrowingWebCircleElement *element = builder.build; From c4908859352768dea3214798af0f123f97d93f37 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 17:19:10 +0800 Subject: [PATCH 059/126] ci: update sonar yml --- .github/workflows/SonarCloud.yml | 64 +++++++++++++++++++ .../Events/GrowingHybridViewElementEvent.h | 1 + 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/SonarCloud.yml diff --git a/.github/workflows/SonarCloud.yml b/.github/workflows/SonarCloud.yml new file mode 100644 index 000000000..ee0e5b35b --- /dev/null +++ b/.github/workflows/SonarCloud.yml @@ -0,0 +1,64 @@ +name: SonarCloud +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build + runs-on: macos-latest + env: + DERIVED_DATA: $HOME/.DerivedData + XCTEST_WORKSPACE: GrowingAnalytics.xcworkspace + XCTEST_SCHEME: GrowingAnalyticsTests + XCTEST_TESTPLAN: GrowingAnalyticsTests + XCTEST_DESTINATION: "platform=iOS Simulator,name=iPhone 13" + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: sonarsource/sonarcloud-github-c-cpp@v2 + + - name: Cache cocoapods + uses: actions/cache@v3 + with: + path: Pods + key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} + restore-keys: | + ${{ runner.os }}-pods- + + - name: Pod Install + run: pod install + + - name: Run build-wrapper # https://sonarsource.atlassian.net/browse/CPP-3987 + run: | + mkdir -p ${{ env.DERIVED_DATA }} + xcodebuild test -workspace ${{ env.XCTEST_WORKSPACE }} \ + -scheme ${{ env.XCTEST_SCHEME }} \ + -testPlan ${{ env.XCTEST_TESTPLAN }} \ + -destination "${{ env.XCTEST_DESTINATION }}" \ + -enableCodeCoverage YES \ + -derivedDataPath ${{ env.DERIVED_DATA }} \ + OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path \${{ env.DERIVED_DATA }}/compilation-database" + + - name: Parse xcresult to Sonar coverage xml + run: | + brew tap a7ex/homebrew-formulae + brew install xcresultparser + xcresultparser -c -o xml ${{ env.DERIVED_DATA }}/Logs/Test/*.xcresult/ > ${{ env.DERIVED_DATA }}/generic-coverage.xml + + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner \ + -Dsonar.cfamily.build-wrapper-output="${{ env.DERIVED_DATA }}/compilation-database" \ + -Dsonar.coverageReportPaths="${{ env.DERIVED_DATA }}/generic-coverage.xml" + +# https://github.com/sonarsource-cfamily-examples/macos-xcode-coverage-gh-actions-sc/blob/main/.github/workflows/build.yml +# https://github.com/SonarSource/sonarcloud-github-c-cpp diff --git a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h index a387aa402..39454d7b3 100644 --- a/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h +++ b/Modules/Hybrid/Events/GrowingHybridViewElementEvent.h @@ -44,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN - (GrowingHybridViewElementBuilder * (^)(NSString *value))setPath; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setTextValue; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setXpath; +- (GrowingHybridViewElementBuilder * (^)(NSString *value))setXcontent; - (GrowingHybridViewElementBuilder * (^)(int value))setIndex; - (GrowingHybridViewElementBuilder * (^)(NSString *value))setDomain; - (GrowingHybridViewElementBuilder * (^)(NSDictionary *value))setAttributes; From f27efd1737ff81d862b668fc1fa312b32fb83139 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 19:25:54 +0800 Subject: [PATCH 060/126] ci: update sonar yml --- .github/workflows/SonarCloud.yml | 2 +- codecov.yml | 2 +- sonar-project.properties | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/SonarCloud.yml b/.github/workflows/SonarCloud.yml index ee0e5b35b..515d03eca 100644 --- a/.github/workflows/SonarCloud.yml +++ b/.github/workflows/SonarCloud.yml @@ -43,7 +43,7 @@ jobs: -destination "${{ env.XCTEST_DESTINATION }}" \ -enableCodeCoverage YES \ -derivedDataPath ${{ env.DERIVED_DATA }} \ - OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path \${{ env.DERIVED_DATA }}/compilation-database" + OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path ${{ env.DERIVED_DATA }}/compilation-database" - name: Parse xcresult to Sonar coverage xml run: | diff --git a/codecov.yml b/codecov.yml index 2cb515882..bbc75838b 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,8 +3,8 @@ codecov: ignore: - "Example" - "GrowingTrackerCore/Thirdparty" - - "Modules/Protobuf/Proto/*.pbobjc.m" - "Modules/Flutter" + - "Services/Protobuf/Proto/*.pbobjc.m" - "Services/Compression/LZ4" - "Services/Database/FMDB" - "Services/WebSocket" diff --git a/sonar-project.properties b/sonar-project.properties index 5c702600a..e63dc66f2 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,13 +3,11 @@ sonar.projectName = growingio-sdk-ios-autotracker sonar.projectKey = growingio_growingio-sdk-ios-autotracker sonar.cfamily.threads = 3 -sonar.cfamily.cache.enabled = true -sonar.cfamily.cache.path = .cache sonar.sources = . sonar.exclusions = Example/**,\ GrowingTrackerCore/Thirdparty/**,\ - Modules/Protobuf/Proto/*.pbobjc.m,\ Modules/Flutter/**,\ + Services/Protobuf/Proto/*.pbobjc.m,\ Services/Compression/LZ4/**,\ Services/Database/FMDB/**,\ Services/WebSocket/**, \ From a2b822b1e85c68414b0ecd23f428b84e295cd155 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 19:56:48 +0800 Subject: [PATCH 061/126] build: update generate_xcframework.sh --- Example/Example-macOS/AppDelegate.swift | 5 ----- .../Event/Tools/GrowingPersistenceDataProvider.h | 2 +- scripts/generate_xcframework.sh | 9 ++------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Example/Example-macOS/AppDelegate.swift b/Example/Example-macOS/AppDelegate.swift index 5a13cd960..f75f8e6a4 100644 --- a/Example/Example-macOS/AppDelegate.swift +++ b/Example/Example-macOS/AppDelegate.swift @@ -19,12 +19,7 @@ import Cocoa - -#if canImport(GrowingAnalytics_cdp) -import GrowingAnalytics_cdp -#elseif canImport(GrowingAnalytics) import GrowingAnalytics -#endif @main class AppDelegate: NSObject, NSApplicationDelegate { diff --git a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h index 75cbaeaed..8dfd36432 100644 --- a/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h +++ b/GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setLoginUserKey:(NSString *_Nullable)loginUserKey; - (nullable NSString *)loginUserKey; -/// 设置NSString,NSNumber(cdp、upgrade) +/// 设置NSString,NSNumber(upgrade) - (void)setString:(NSString *)value forKey:(NSString *)key; - (NSString *)getStringforKey:(NSString *)key; diff --git a/scripts/generate_xcframework.sh b/scripts/generate_xcframework.sh index 3d9ba93b1..0677195b7 100644 --- a/scripts/generate_xcframework.sh +++ b/scripts/generate_xcframework.sh @@ -42,10 +42,10 @@ MODULES=() APMMODULES=() chooseModules() { if [ $MAIN_BUNDLE == 'GrowingAutotracker' ]; then - modules=("Advert" "Protobuf" "APMUIMonitor" "APMCrashMonitor" "Done" "Quit") + modules=("Advert" "APMUIMonitor" "APMCrashMonitor" "Done" "Quit") chooseModulesWith ${modules[*]} elif [ $MAIN_BUNDLE == 'GrowingTracker' ]; then - modules=("Hybrid" "Advert" "Protobuf" "APMUIMonitor" "APMCrashMonitor" "Done" "Quit") + modules=("Hybrid" "Advert" "APMUIMonitor" "APMCrashMonitor" "Done" "Quit") chooseModulesWith ${modules[*]} fi } @@ -63,11 +63,6 @@ chooseModulesWith() { MODULES+=("Advert") fi ;; - "Protobuf") - if [[ ! ${MODULES[*]} =~ "Protobuf" ]]; then - MODULES+=("Protobuf") - fi - ;; "APMUIMonitor") if [[ ! ${MODULES[*]} =~ "APM" ]]; then MODULES+=("APM") From 927ce68fa25d5c585d57f60eedef959d2ee22499 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 20:26:54 +0800 Subject: [PATCH 062/126] chore: update minimum deployment target to iOS 10.0 --- GrowingAnalytics.podspec | 2 +- Podfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GrowingAnalytics.podspec b/GrowingAnalytics.podspec index 2f3227962..82b503421 100644 --- a/GrowingAnalytics.podspec +++ b/GrowingAnalytics.podspec @@ -147,7 +147,7 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和 end s.subspec 'ImpressionTrack' do |imptrack| - imptrack.ios.deployment_target = '9.0' + imptrack.ios.deployment_target = '10.0' imptrack.source_files = 'Modules/ImpressionTrack/**/*{.h,.m,.c,.cpp,.mm}' imptrack.public_header_files = 'Modules/ImpressionTrack/Public/*.h' imptrack.dependency 'GrowingAnalytics/AutotrackerCore', s.version.to_s diff --git a/Podfile.lock b/Podfile.lock index c4853306f..11d85bf4e 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -150,7 +150,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: d8bac28422b170858d3d5523a06170d55dd2148a + GrowingAnalytics: 87434c0b7311aa8a09ff20e4ae86bd033db3d04d GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 9c0d6e41c9678397dbaa3304b1738a2867b023ae GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 From fb09d445404375c6212a082749686e41b4e3012f Mon Sep 17 00:00:00 2001 From: YoloMao Date: Wed, 9 Aug 2023 21:05:19 +0800 Subject: [PATCH 063/126] fix: growingUniqueTag logic --- .../Category/UICollectionView+GrowingNode.m | 4 --- .../Category/UITableView+GrowingNode.m | 4 --- .../GrowingNode/Category/UIView+GrowingNode.m | 5 --- .../GrowingNode/GrowingNodeHelper.m | 10 ++++-- .../GrowingNode/GrowingViewNode.m | 34 +++++++------------ 5 files changed, 21 insertions(+), 36 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m index 12c000744..02b5a9a5c 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UICollectionView+GrowingNode.m @@ -56,10 +56,6 @@ - (NSIndexPath *)growingNodeIndexPath { } - (NSString *)growingNodeSubPath { - if (self.growingUniqueTag.length > 0) { - return self.growingUniqueTag; - } - NSIndexPath *indexpath = [self growingNodeIndexPath]; if (indexpath) { return [NSString stringWithFormat:@"Section/%@", NSStringFromClass(self.class)]; diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m index 126e64f84..ed0cd5f80 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UITableView+GrowingNode.m @@ -72,10 +72,6 @@ - (NSIndexPath *)growingNodeIndexPath { } - (NSString *)growingNodeSubPath { - if (self.growingUniqueTag.length > 0) { - return self.growingUniqueTag; - } - NSIndexPath *indexpath = [self growingNodeIndexPath]; if (indexpath) { return [NSString stringWithFormat:@"Section/%@", NSStringFromClass(self.class)]; diff --git a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m index 2ca33e50d..6387bfc8a 100644 --- a/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m +++ b/GrowingAutotrackerCore/GrowingNode/Category/UIView+GrowingNode.m @@ -54,11 +54,6 @@ - (NSInteger)growingNodeKeyIndex { } - (NSString *)growingNodeSubPath { - // 如果手动标识了该view,返回标识 - if (self.growingUniqueTag.length > 0) { - return self.growingUniqueTag; - } - return NSStringFromClass(self.class); } diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m index cc93331eb..5ee504e85 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.m @@ -41,7 +41,6 @@ + (void)recalculateXpath:(UIView *)view continue; } - [viewPathArray addObject:node.growingNodeSubPath]; [originxcontentArray addObject:node.growingNodeSubIndex]; if (isSimilar) { [xcontentArray addObject:node.growingNodeSubSimilarIndex]; @@ -50,7 +49,14 @@ + (void)recalculateXpath:(UIView *)view [xcontentArray addObject:node.growingNodeSubIndex]; } - node = node.growingNodeParent; + NSString *uniqueTag = ((UIView *)node).growingUniqueTag; + if (uniqueTag && uniqueTag.length > 0) { + [viewPathArray addObject:uniqueTag]; + node = nil; + } else { + [viewPathArray addObject:node.growingNodeSubPath]; + node = node.growingNodeParent; + } } NSString * (^toStringBlock)(NSArray *) = ^(NSArray *array) { diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m index 603c162fc..73cee8081 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewNode.m @@ -73,24 +73,6 @@ + (GrowingViewNodeBuilder *)builder { } - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { - NSString *subpath = view.growingNodeSubPath; - // 如果节点path不存在,说明被过滤了,除了view之外,全部copy父级属性 - if (!subpath) { - return GrowingViewNode.builder.setView(view) - .setIndex(self.index) - .setXpath(self.xpath) - .setXcontent(self.xcontent) - .setOriginXcontent(self.originxcontent) - .setClickableParentXpath(self.clickableParentXpath) - .setClickableParentXcontent(self.clickableParentXcontent) - .setHasListParent(self.hasListParent) - .setViewContent(self.viewContent) - .setPosition(self.position) - .setNodeType(self.nodeType) - .setNeedRecalculate(recalculate) - .build; - } - BOOL haslistParent = self.hasListParent || [self.view isKindOfClass:[UITableView class]] || [self.view isKindOfClass:[UICollectionView class]]; // 是否是相似元素 @@ -104,15 +86,25 @@ - (GrowingViewNode *)appendNode:(UIView *)view isRecalculate:(BOOL)recalculate { index = self.index; } + NSString *uniqueTag = view.growingUniqueTag; + NSString *xpath = uniqueTag && uniqueTag.length > 0 + ? [NSString stringWithFormat:@"/%@", uniqueTag] + : [self.xpath stringByAppendingFormat:@"/%@", view.growingNodeSubPath]; + NSString *xcontent = uniqueTag && uniqueTag.length > 0 + ? [NSString stringWithFormat:@"/%@", view.growingNodeSubSimilarIndex] + : [self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubSimilarIndex]; + NSString *originxcontent = uniqueTag && uniqueTag.length > 0 + ? [NSString stringWithFormat:@"/%@", view.growingNodeSubIndex] + : [self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubIndex]; NSString *parentXpath = self.view.growingNodeUserInteraction ? self.xpath : self.clickableParentXpath; NSString *parentXcontent = self.view.growingNodeUserInteraction ? self.xcontent : self.clickableParentXcontent; NSString *content = view.growingNodeContent; return GrowingViewNode.builder.setView(view) .setIndex((int)index) - .setXpath([self.xpath stringByAppendingFormat:@"/%@", view.growingNodeSubPath]) - .setXcontent([self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubSimilarIndex]) - .setOriginXcontent([self.originxcontent stringByAppendingFormat:@"/%@", view.growingNodeSubIndex]) + .setXpath(xpath) + .setXcontent(xcontent) + .setOriginXcontent(originxcontent) .setClickableParentXpath(parentXpath) .setClickableParentXcontent(parentXcontent) .setHasListParent(haslistParent) From 8f23c03c17073342dbc3564153c703e5395e33a7 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 10 Aug 2023 11:38:48 +0800 Subject: [PATCH 064/126] ci: update sonar yml --- .github/workflows/SonarCloud.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/SonarCloud.yml b/.github/workflows/SonarCloud.yml index 515d03eca..ae2348df4 100644 --- a/.github/workflows/SonarCloud.yml +++ b/.github/workflows/SonarCloud.yml @@ -44,6 +44,9 @@ jobs: -enableCodeCoverage YES \ -derivedDataPath ${{ env.DERIVED_DATA }} \ OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path ${{ env.DERIVED_DATA }}/compilation-database" + pushd ${{ env.DERIVED_DATA }}/compilation-database + sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ./build-wrapper-dump.json + popd - name: Parse xcresult to Sonar coverage xml run: | From 08a5de2ac0dd5a7621c17a85de39529971df8015 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 10 Aug 2023 14:15:49 +0800 Subject: [PATCH 065/126] ci: update sonar yml --- .github/workflows/SonarCloud.yml | 6 ++---- GrowingTrackerCore/Event/GrowingEventManager.m | 3 +++ sonar-project.properties | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/SonarCloud.yml b/.github/workflows/SonarCloud.yml index ae2348df4..1907c61f4 100644 --- a/.github/workflows/SonarCloud.yml +++ b/.github/workflows/SonarCloud.yml @@ -45,7 +45,7 @@ jobs: -derivedDataPath ${{ env.DERIVED_DATA }} \ OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path ${{ env.DERIVED_DATA }}/compilation-database" pushd ${{ env.DERIVED_DATA }}/compilation-database - sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ./build-wrapper-dump.json + sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ../../compile_commands.json popd - name: Parse xcresult to Sonar coverage xml @@ -59,9 +59,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | - sonar-scanner \ - -Dsonar.cfamily.build-wrapper-output="${{ env.DERIVED_DATA }}/compilation-database" \ - -Dsonar.coverageReportPaths="${{ env.DERIVED_DATA }}/generic-coverage.xml" + sonar-scanner -Dsonar.coverageReportPaths="${{ env.DERIVED_DATA }}/generic-coverage.xml" # https://github.com/sonarsource-cfamily-examples/macos-xcode-coverage-gh-actions-sc/blob/main/.github/workflows/build.yml # https://github.com/SonarSource/sonarcloud-github-c-cpp diff --git a/GrowingTrackerCore/Event/GrowingEventManager.m b/GrowingTrackerCore/Event/GrowingEventManager.m index 092aeb243..2f9c720d5 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.m +++ b/GrowingTrackerCore/Event/GrowingEventManager.m @@ -326,6 +326,9 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { [jsonObjects addObject:jsonObject]; } } + if (jsonObjects.count == 0) { + return; + } rawEvents = [dbClass buildRawEventsFromJsonObjects:jsonObjects]; } diff --git a/sonar-project.properties b/sonar-project.properties index e63dc66f2..ae782cf37 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,6 +3,7 @@ sonar.projectName = growingio-sdk-ios-autotracker sonar.projectKey = growingio_growingio-sdk-ios-autotracker sonar.cfamily.threads = 3 +sonar.cfamily.compile-commands=compile_commands.json sonar.sources = . sonar.exclusions = Example/**,\ GrowingTrackerCore/Thirdparty/**,\ From 4de0d1db4c84631c3e4f74b473dba3c8b9a59eb9 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 10 Aug 2023 14:47:45 +0800 Subject: [PATCH 066/126] ci: update sonar yml --- .github/workflows/SonarCloud.yml | 6 ++++-- sonar-project.properties | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/SonarCloud.yml b/.github/workflows/SonarCloud.yml index 1907c61f4..44d242831 100644 --- a/.github/workflows/SonarCloud.yml +++ b/.github/workflows/SonarCloud.yml @@ -45,7 +45,7 @@ jobs: -derivedDataPath ${{ env.DERIVED_DATA }} \ OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path ${{ env.DERIVED_DATA }}/compilation-database" pushd ${{ env.DERIVED_DATA }}/compilation-database - sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ../../compile_commands.json + sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ${{ env.DERIVED_DATA }}/compile_commands.json popd - name: Parse xcresult to Sonar coverage xml @@ -59,7 +59,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | - sonar-scanner -Dsonar.coverageReportPaths="${{ env.DERIVED_DATA }}/generic-coverage.xml" + sonar-scanner \ + -Dsonar.cfamily.compile-commands="${{ env.DERIVED_DATA }}/compile_commands.json" \ + -Dsonar.coverageReportPaths="${{ env.DERIVED_DATA }}/generic-coverage.xml" # https://github.com/sonarsource-cfamily-examples/macos-xcode-coverage-gh-actions-sc/blob/main/.github/workflows/build.yml # https://github.com/SonarSource/sonarcloud-github-c-cpp diff --git a/sonar-project.properties b/sonar-project.properties index ae782cf37..e63dc66f2 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,6 @@ sonar.projectName = growingio-sdk-ios-autotracker sonar.projectKey = growingio_growingio-sdk-ios-autotracker sonar.cfamily.threads = 3 -sonar.cfamily.compile-commands=compile_commands.json sonar.sources = . sonar.exclusions = Example/**,\ GrowingTrackerCore/Thirdparty/**,\ From 6b6f1d59daca0942b076b5e2cd6ae0c4006c4d3b Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 10 Aug 2023 15:31:43 +0800 Subject: [PATCH 067/126] ci: merge sonar into ci yml --- .github/workflows/SonarCloud.yml | 67 -------------------------------- codecov.yml | 3 +- sonar-project.properties | 1 + 3 files changed, 2 insertions(+), 69 deletions(-) delete mode 100644 .github/workflows/SonarCloud.yml diff --git a/.github/workflows/SonarCloud.yml b/.github/workflows/SonarCloud.yml deleted file mode 100644 index 44d242831..000000000 --- a/.github/workflows/SonarCloud.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: SonarCloud -on: - push: - branches: - - master - pull_request: - types: [opened, synchronize, reopened] -jobs: - build: - name: Build - runs-on: macos-latest - env: - DERIVED_DATA: $HOME/.DerivedData - XCTEST_WORKSPACE: GrowingAnalytics.xcworkspace - XCTEST_SCHEME: GrowingAnalyticsTests - XCTEST_TESTPLAN: GrowingAnalyticsTests - XCTEST_DESTINATION: "platform=iOS Simulator,name=iPhone 13" - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Install sonar-scanner and build-wrapper - uses: sonarsource/sonarcloud-github-c-cpp@v2 - - - name: Cache cocoapods - uses: actions/cache@v3 - with: - path: Pods - key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} - restore-keys: | - ${{ runner.os }}-pods- - - - name: Pod Install - run: pod install - - - name: Run build-wrapper # https://sonarsource.atlassian.net/browse/CPP-3987 - run: | - mkdir -p ${{ env.DERIVED_DATA }} - xcodebuild test -workspace ${{ env.XCTEST_WORKSPACE }} \ - -scheme ${{ env.XCTEST_SCHEME }} \ - -testPlan ${{ env.XCTEST_TESTPLAN }} \ - -destination "${{ env.XCTEST_DESTINATION }}" \ - -enableCodeCoverage YES \ - -derivedDataPath ${{ env.DERIVED_DATA }} \ - OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path ${{ env.DERIVED_DATA }}/compilation-database" - pushd ${{ env.DERIVED_DATA }}/compilation-database - sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ${{ env.DERIVED_DATA }}/compile_commands.json - popd - - - name: Parse xcresult to Sonar coverage xml - run: | - brew tap a7ex/homebrew-formulae - brew install xcresultparser - xcresultparser -c -o xml ${{ env.DERIVED_DATA }}/Logs/Test/*.xcresult/ > ${{ env.DERIVED_DATA }}/generic-coverage.xml - - - name: Run sonar-scanner - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - sonar-scanner \ - -Dsonar.cfamily.compile-commands="${{ env.DERIVED_DATA }}/compile_commands.json" \ - -Dsonar.coverageReportPaths="${{ env.DERIVED_DATA }}/generic-coverage.xml" - -# https://github.com/sonarsource-cfamily-examples/macos-xcode-coverage-gh-actions-sc/blob/main/.github/workflows/build.yml -# https://github.com/SonarSource/sonarcloud-github-c-cpp diff --git a/codecov.yml b/codecov.yml index bbc75838b..f45434c42 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,9 +1,8 @@ -codecov: - token: "ba961ca1-57a7-4a22-ad2e-5819eea559da" ignore: - "Example" - "GrowingTrackerCore/Thirdparty" - "Modules/Flutter" + - "Services/SwiftProtobuf" - "Services/Protobuf/Proto/*.pbobjc.m" - "Services/Compression/LZ4" - "Services/Database/FMDB" diff --git a/sonar-project.properties b/sonar-project.properties index e63dc66f2..7dd2121e1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -7,6 +7,7 @@ sonar.sources = . sonar.exclusions = Example/**,\ GrowingTrackerCore/Thirdparty/**,\ Modules/Flutter/**,\ + Services/SwiftProtobuf/**,\ Services/Protobuf/Proto/*.pbobjc.m,\ Services/Compression/LZ4/**,\ Services/Database/FMDB/**,\ From 9908d9db035fb4b009ba254419261dced3ea36a1 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 10 Aug 2023 16:28:35 +0800 Subject: [PATCH 068/126] ci: update ci --- scripts/xccov-to-generic.sh | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/xccov-to-generic.sh diff --git a/scripts/xccov-to-generic.sh b/scripts/xccov-to-generic.sh new file mode 100644 index 000000000..9daccaf78 --- /dev/null +++ b/scripts/xccov-to-generic.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +set -euo pipefail + +function convert_file { + local xccovarchive_file="$1" + local file_name="$2" + local xccov_options="$3" + echo " " + xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" | \ + sed -n ' + s/^ *\([0-9][0-9]*\): 0.*$/ /p; + s/^ *\([0-9][0-9]*\): [1-9].*$/ /p + ' + echo ' ' +} + +function xccov_to_generic { + echo '' + for xccovarchive_file in "$@"; do + if [[ ! -d $xccovarchive_file ]] + then + echo "Coverage FILE NOT FOUND AT PATH: $xccovarchive_file" 1>&2; + exit 1 + fi + + if [ $sdk_version -gt 10 ]; then # Apply optimization + xccovarchive_file=$(optimize_format) + fi + + local xccov_options="" + if [[ $xccovarchive_file == *".xcresult"* ]]; then + xccov_options="--archive" + fi + xcrun xccov view $xccov_options --file-list "$xccovarchive_file" | while read -r file_name; do + convert_file "$xccovarchive_file" "$file_name" "$xccov_options" + done + done + echo '' +} + +function check_sdk_version { + sdk_major_version=`xcrun --show-sdk-version | cut -d . -f 1` + + if [ $? -ne 0 ]; then + echo 'Failed to execute xcrun show-sdk-version' 1>&2 + exit -1 + fi + echo $sdk_major_version +} + +function cleanup_tmp_files { + rm -rf tmp.json + rm -rf tmp.xccovarchive +} + +# Optimize coverage files conversion time by exporting to a clean xcodearchive directory +# Credits to silverhammermba on issue #68 for the suggestion +function optimize_format { + cleanup_tmp_files + xcrun xcresulttool get --format json --path "$xccovarchive_file" > tmp.json + if [ $? -ne 0 ]; then + echo 'Failed to execute xcrun xcresulttool get' 1>&2 + exit -1 + fi + + # local reference=$(jq -r '.actions._values[2].actionResult.coverage.archiveRef.id._value' tmp.json) + local reference=$(jq -r '.actions._values[]|[.actionResult.coverage.archiveRef.id],._values' tmp.json | grep value | cut -d : -f 2 | cut -d \" -f 2) + if [ $? -ne 0 ]; then + echo 'Failed to execute jq (https://stedolan.github.io/jq/)' 1>&2 + exit -1 + fi + # $reference can be a list of IDs (from a merged .xcresult bundle of multiple test plans) + for test_ref in $reference; do + xcrun xcresulttool export --type directory --path "$xccovarchive_file" --id "$test_ref" --output-path tmp.xccovarchive + if [ $? -ne 0 ]; then + echo "Failed to execute xcrun xcresulttool export for reference ${test_ref}" 1>&2 + exit -1 + fi + done + echo "tmp.xccovarchive" +} + +sdk_version=$(check_sdk_version) +if [ $? -ne 0 ]; then + exit -1 +fi + +xccov_to_generic "$@" +cleanup_tmp_files \ No newline at end of file From 42ea29e8ca4d96c4075ba92bc2da38921fd7083e Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 10 Aug 2023 17:44:34 +0800 Subject: [PATCH 069/126] ci: update ci --- scripts/xccov-to-generic.sh | 89 ------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 scripts/xccov-to-generic.sh diff --git a/scripts/xccov-to-generic.sh b/scripts/xccov-to-generic.sh deleted file mode 100644 index 9daccaf78..000000000 --- a/scripts/xccov-to-generic.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -function convert_file { - local xccovarchive_file="$1" - local file_name="$2" - local xccov_options="$3" - echo " " - xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" | \ - sed -n ' - s/^ *\([0-9][0-9]*\): 0.*$/ /p; - s/^ *\([0-9][0-9]*\): [1-9].*$/ /p - ' - echo ' ' -} - -function xccov_to_generic { - echo '' - for xccovarchive_file in "$@"; do - if [[ ! -d $xccovarchive_file ]] - then - echo "Coverage FILE NOT FOUND AT PATH: $xccovarchive_file" 1>&2; - exit 1 - fi - - if [ $sdk_version -gt 10 ]; then # Apply optimization - xccovarchive_file=$(optimize_format) - fi - - local xccov_options="" - if [[ $xccovarchive_file == *".xcresult"* ]]; then - xccov_options="--archive" - fi - xcrun xccov view $xccov_options --file-list "$xccovarchive_file" | while read -r file_name; do - convert_file "$xccovarchive_file" "$file_name" "$xccov_options" - done - done - echo '' -} - -function check_sdk_version { - sdk_major_version=`xcrun --show-sdk-version | cut -d . -f 1` - - if [ $? -ne 0 ]; then - echo 'Failed to execute xcrun show-sdk-version' 1>&2 - exit -1 - fi - echo $sdk_major_version -} - -function cleanup_tmp_files { - rm -rf tmp.json - rm -rf tmp.xccovarchive -} - -# Optimize coverage files conversion time by exporting to a clean xcodearchive directory -# Credits to silverhammermba on issue #68 for the suggestion -function optimize_format { - cleanup_tmp_files - xcrun xcresulttool get --format json --path "$xccovarchive_file" > tmp.json - if [ $? -ne 0 ]; then - echo 'Failed to execute xcrun xcresulttool get' 1>&2 - exit -1 - fi - - # local reference=$(jq -r '.actions._values[2].actionResult.coverage.archiveRef.id._value' tmp.json) - local reference=$(jq -r '.actions._values[]|[.actionResult.coverage.archiveRef.id],._values' tmp.json | grep value | cut -d : -f 2 | cut -d \" -f 2) - if [ $? -ne 0 ]; then - echo 'Failed to execute jq (https://stedolan.github.io/jq/)' 1>&2 - exit -1 - fi - # $reference can be a list of IDs (from a merged .xcresult bundle of multiple test plans) - for test_ref in $reference; do - xcrun xcresulttool export --type directory --path "$xccovarchive_file" --id "$test_ref" --output-path tmp.xccovarchive - if [ $? -ne 0 ]; then - echo "Failed to execute xcrun xcresulttool export for reference ${test_ref}" 1>&2 - exit -1 - fi - done - echo "tmp.xccovarchive" -} - -sdk_version=$(check_sdk_version) -if [ $? -ne 0 ]; then - exit -1 -fi - -xccov_to_generic "$@" -cleanup_tmp_files \ No newline at end of file From b5bcd1c9ddee732c1e972a46dea997107014cd2e Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 11 Aug 2023 15:02:26 +0800 Subject: [PATCH 070/126] =?UTF-8?q?fix:=203to4=20=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E4=B8=8D=E5=85=BC=E5=AE=B9=E7=9A=84=20v3=20=E6=97=A0=E5=9F=8B?= =?UTF-8?q?=E7=82=B9=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../A0GrowingAnalyticsTest.m | 352 +++++++++--------- .../NSNotificationCenterAutotrackTest.m | 92 ++--- .../Autotrack/UICollectionViewAutotrackTest.m | 73 ++-- .../UISegmentedControlAutotrackTest.m | 12 +- .../Autotrack/UITableViewAutotrackTest.m | 56 +-- .../GrowingNodeTests/NodeTest.m | 4 +- .../GrowingAnalyticsStartTests.m | 67 ++-- .../DeepLinkTests/DeepLinkTest.m | 14 +- .../DeepLinkTests/DeepLinkiOS13UISceneTest.m | 14 +- .../DeepLinkTests/Helper/DeepLinkTestHelper.h | 1 - .../DeepLinkTests/Helper/DeepLinkTestHelper.m | 36 +- .../Helper/GrowingDeepLinkHandler+XCTest.m | 16 +- .../Helper/InvocationHelper.h | 1 - .../Helper/InvocationHelper.m | 9 +- .../Helper/ManualTrackHelper.m | 45 +-- .../Helper/MockEventQueue.m | 96 +++-- .../Autotrack/UIApplicationAutotrackTest.m | 68 ++-- .../UITapGestureRecognizerAutotrackTest.m | 18 +- .../Event/A1ViewClickEventsTest.m | 161 ++++---- .../Event/A2ViewChangeEventsTest.m | 28 +- .../HybridTests/HybridTest_HostApp.m | 100 ++--- .../OtherTests/GrowingKeyChainTest.m | 2 +- .../ModulesTests/AdvertTests/AdvertTest.m | 13 +- .../HybridTests/HybridEventTest.m | 42 ++- .../ModulesTests/HybridTests/HybridTest.m | 54 +-- .../MobileDebuggerTests/MobileDebuggerTest.m | 19 +- .../ProtobufTests/ProtobufDatabaseTest.m | 108 +++--- .../ProtobufTests/ProtobufEventsTest.m | 249 ++++++------- .../ProtobufTests/ProtobufPersistenceTest.m | 33 +- .../ProtobufTests/ProtobufRequestHeaderTest.m | 23 +- .../WebCircleTests/WebCircleTest.m | 12 +- .../CompressionTests/CompressionTest.m | 4 +- .../DatabaseTests/JSONDatabaseTest.m | 73 ++-- .../DatabaseTests/JSONPersistenceTest.m | 7 +- .../EncryptionTests/EncryptionTest.m | 4 +- .../CoreTests/GrowingAnnotationTest.m | 3 +- .../DatabaseTests/DatabaseTest.m | 31 +- .../DeepLinkTests/DeepLinkTest.m | 2 - .../EventTests/DataTrafficTest.m | 1 - .../TrackerCoreTests/EventTests/EventTest.m | 82 ++-- .../FileStorageTests/FileStorageTest.m | 7 +- .../TrackerCoreTests/GrowingWindowTest.m | 6 +- .../GrowingFoundationHelpersTest.m | 9 +- .../HelpersTests/GrowingUIKitHelpersTest.m | 3 +- .../HookTests/GrowingULAppLifeCycleTest.m | 28 +- .../ManagerTests/GrowingSessionTest.m | 29 +- .../MenuTests/GrowingAlertTest.m | 10 +- .../MenuTests/GrowingStatusBarTest.m | 7 +- .../SwizzleTests/GrowingSwizzleTest.m | 7 +- .../ThreadTests/GrowingDispatchManagerTest.m | 44 ++- .../UtilsTests/DeviceInfoTest.m | 1 - .../UtilsTests/DynamicProxyTest.m | 5 +- GrowingAnalytics.podspec | 2 +- .../Database/GrowingEventDatabase.h | 5 +- .../Database/GrowingEventDatabase.m | 15 +- .../Event/GrowingEventChannel.m | 7 +- .../Event/GrowingEventManager.h | 8 - .../Event/GrowingEventManager.m | 64 ++-- GrowingTrackerCore/GrowingRealTracker.m | 4 +- .../Public/GrowingEventDatabaseService.h | 5 - .../Public/GrowingEventPersistenceProtocol.h | 4 +- Modules/Advert/GrowingAdvertising.m | 8 - Podfile.lock | 112 +++--- Services/Database/GrowingEventFMDatabase.m | 77 ++-- Services/JSON/GrowingEventJSONDatabase.m | 6 +- Services/JSON/GrowingEventJSONPersistence.h | 1 + Services/JSON/GrowingEventJSONPersistence.m | 7 +- .../Protobuf/GrowingEventProtobufDatabase.m | 6 +- .../GrowingEventProtobufPersistence.h | 1 + .../GrowingEventProtobufPersistence.m | 5 +- 70 files changed, 1264 insertions(+), 1254 deletions(-) diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m index bbf97d7f5..855cbfdd5 100644 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m +++ b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m @@ -8,22 +8,22 @@ #import #import "GrowingAutotracker.h" -#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" -#import "GrowingTrackerCore/Event/GrowingEventManager.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Thread/GrowingThread.h" -#import "MockEventQueue.h" -#import "InvocationHelper.h" -#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" #import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" +#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" +#import "GrowingTrackerCore/Event/GrowingEventManager.h" #import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" -#import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" #import "GrowingTrackerCore/Event/GrowingTrackEventType.h" -#import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" -#import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" +#import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" #import "GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" +#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" +#import "GrowingTrackerCore/Thread/GrowingThread.h" +#import "InvocationHelper.h" +#import "MockEventQueue.h" -static NSString * const kGrowingEventDuration = @"event_duration"; +static NSString *const kGrowingEventDuration = @"event_duration"; @interface A0GrowingAnalyticsTest : XCTestCase @@ -37,7 +37,7 @@ @implementation A0GrowingAnalyticsTest + (void)setUp { [[GrowingPersistenceDataProvider sharedInstance] setLoginUserId:nil]; [[GrowingPersistenceDataProvider sharedInstance] setLoginUserKey:nil]; - + GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; configuration.dataSourceId = @"test"; configuration.idMappingEnabled = YES; @@ -67,29 +67,33 @@ - (void)testSetUserId { [[GrowingAutotracker sharedInstance] cleanLoginUserId]; NSString *userId = @"123456789"; [[GrowingAutotracker sharedInstance] setLoginUserId:userId]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, userId); - } waitUntilDone:YES]; - + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, userId); + } + waitUntilDone:YES]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; XCTAssertEqual(events.count, 0); } - (void)testClearUserId { [[GrowingAutotracker sharedInstance] cleanLoginUserId]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, nil); - } waitUntilDone:YES]; + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([GrowingSession currentSession].loginUserId, nil); + } + waitUntilDone:YES]; } - (void)testSetUserIdAndUserKeyTest { [[GrowingAutotracker sharedInstance] cleanLoginUserId]; - + XCTestExpectation *expectation = [self expectationWithDescription:@"setUserIdAndUserKey Test failed : timeout"]; expectation.expectedFulfillmentCount = 2; - + NSString *userId = @"123456789"; [[GrowingAutotracker sharedInstance] setLoginUserId:userId userKey:@"number"]; [GrowingDispatchManager dispatchInGrowingThread:^{ @@ -97,7 +101,7 @@ - (void)testSetUserIdAndUserKeyTest { XCTAssertEqualObjects([GrowingSession currentSession].loginUserKey, @"number"); [expectation fulfill]; }]; - + userId = @"223344"; [[GrowingAutotracker sharedInstance] setLoginUserId:userId]; [GrowingDispatchManager dispatchInGrowingThread:^{ @@ -110,14 +114,15 @@ - (void)testSetUserIdAndUserKeyTest { - (void)testSetLoginUserAttributes { { - [[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@"key" : @"value"}]; - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; + [[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@"key": @"value"}]; + NSArray *events = + [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; XCTAssertEqual(events.count, 1); - + GrowingLoginUserAttributesEvent *event = (GrowingLoginUserAttributesEvent *)events.firstObject; XCTAssertEqualObjects(event.attributes[@"key"], @"value"); } - + { [MockEventQueue.sharedQueue cleanQueue]; #pragma clang diagnostic push @@ -125,10 +130,11 @@ - (void)testSetLoginUserAttributes { #pragma clang diagnostic ignored "-Wobjc-literal-conversion" XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:nil]); XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@"value"]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@1 : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@"key" : @1}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@1: @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] setLoginUserAttributes:@{@"key": @1}]); #pragma clang diagnostic pop - NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; + NSArray *events = + [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; XCTAssertEqual(events.count, 0); } } @@ -138,12 +144,12 @@ - (void)testTrackCustomEvent { [[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName"]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertEqualObjects(event.attributes[@"key"], nil); } - + { [MockEventQueue.sharedQueue cleanQueue]; #pragma clang diagnostic push @@ -160,35 +166,33 @@ - (void)testTrackCustomEvent { - (void)testTrackCustomEventWithAttributes { { - [[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" - withAttributes:@{@"key" : @"value"}]; + [[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); } - + { [MockEventQueue.sharedQueue cleanQueue]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wincompatible-pointer-types" #pragma clang diagnostic ignored "-Wobjc-literal-conversion" - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:nil - withAttributes:@{@"key" : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"" - withAttributes:@{@"key" : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@1 - withAttributes:@{@"key" : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" - withAttributes:nil]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:nil withAttributes:@{@"key": @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"" withAttributes:@{@"key": @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@1 withAttributes:@{@"key": @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" withAttributes:nil]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" withAttributes:@"value"]); XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" - withAttributes:@"value"]); + withAttributes:@{ + @1: @"value" + }]); XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" - withAttributes:@{@1 : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackCustomEvent:@"eventName" - withAttributes:@{@"key" : @1}]); + withAttributes:@{ + @"key": @1 + }]); #pragma clang diagnostic pop NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); @@ -200,16 +204,16 @@ - (void)testTrackTimer { NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; usleep(1000); [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertEqualObjects(event.attributes[@"key"], nil); XCTAssertNotNil(event.attributes[kGrowingEventDuration]); } - + { // wrong eventName [MockEventQueue.sharedQueue cleanQueue]; @@ -235,7 +239,7 @@ - (void)testTrackTimer { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); } - + { // wrong timerId [MockEventQueue.sharedQueue cleanQueue]; @@ -244,10 +248,10 @@ - (void)testTrackTimer { [[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName"]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); - + [[GrowingAutotracker sharedInstance] clearTrackTimer]; } - + { // remove timer [MockEventQueue.sharedQueue cleanQueue]; @@ -258,7 +262,7 @@ - (void)testTrackTimer { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); } - + { // clear all timers [MockEventQueue.sharedQueue cleanQueue]; @@ -269,7 +273,7 @@ - (void)testTrackTimer { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); } - + { // pause [MockEventQueue.sharedQueue cleanQueue]; @@ -279,24 +283,24 @@ - (void)testTrackTimer { [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertLessThan(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 1.0); } - + { // pause timer that not exist XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerPause:@"eventName"]); - + // pause twice NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerPause:timerId]); - + [[GrowingAutotracker sharedInstance] clearTrackTimer]; } - + { // pause + resume [MockEventQueue.sharedQueue cleanQueue]; @@ -307,46 +311,48 @@ - (void)testTrackTimer { [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.6); // sleep 不准 + XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, + 0.6); // sleep 不准 } - + { // resume timer that not exist XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerResume:@"eventName"]); - + // resume twice NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; [[GrowingAutotracker sharedInstance] trackTimerResume:timerId]; XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerResume:timerId]); - + [[GrowingAutotracker sharedInstance] clearTrackTimer]; } - + { // timer all pause & all resume [MockEventQueue.sharedQueue cleanQueue]; - + NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - + [GrowingSession.currentSession performSelector:@selector(applicationDidEnterBackground)]; NSNumber *sessionInterval = [GrowingSession.currentSession safePerformSelector:@selector(sessionInterval)]; sleep((int)(sessionInterval.longLongValue / 1000LL) + 1); - + NSString *oldSessionId = GrowingSession.currentSession.sessionId; [GrowingSession.currentSession performSelector:@selector(applicationDidBecomeActive)]; - - sleep(1); // 2 > duration > 1 + + sleep(1); // 2 > duration > 1 [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); - XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.6); // sleep 不准 + XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, + 0.6); // sleep 不准 // 不会算上前后台切换的时间 XCTAssertLessThan(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 2.0); } @@ -356,67 +362,67 @@ - (void)testTrackTimerWithAttributes { { NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; usleep(1000); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key" : @"value"}]; - + [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); XCTAssertNotNil(event.attributes[kGrowingEventDuration]); } - + { // wrong timerId [MockEventQueue.sharedQueue cleanQueue]; [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; usleep(1000); - [[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@{@"key" : @"value"}]; + [[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); - + [[GrowingAutotracker sharedInstance] clearTrackTimer]; } - + { // remove timer [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; usleep(1000); [[GrowingAutotracker sharedInstance] removeTimer:timerId]; - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key" : @"value"}]; + [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); } - + { // clear all timers [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; usleep(1000); [[GrowingAutotracker sharedInstance] clearTrackTimer]; - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key" : @"value"}]; + [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); } - + { // pause [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; sleep(1); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key" : @"value"}]; + [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); XCTAssertLessThan(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 1.0); } - + { // pause + resume [MockEventQueue.sharedQueue cleanQueue]; @@ -424,35 +430,32 @@ - (void)testTrackTimerWithAttributes { [[GrowingAutotracker sharedInstance] trackTimerPause:timerId]; [[GrowingAutotracker sharedInstance] trackTimerResume:timerId]; sleep(1); - [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key" : @"value"}]; + [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, 0.6); // sleep 不准 + XCTAssertGreaterThanOrEqual(((NSString *)event.attributes[kGrowingEventDuration]).floatValue, + 0.6); // sleep 不准 } - + { [MockEventQueue.sharedQueue cleanQueue]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wincompatible-pointer-types" #pragma clang diagnostic ignored "-Wobjc-literal-conversion" - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:nil - withAttributes:@{@"key" : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"" - withAttributes:@{@"key" : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@1 - withAttributes:@{@"key" : @"value"}]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" - withAttributes:nil]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" - withAttributes:@"value"]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" - withAttributes:@{@1 : @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:nil withAttributes:@{@"key": @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"" withAttributes:@{@"key": @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@1 withAttributes:@{@"key": @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:nil]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@"value"]); XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" - withAttributes:@{@"key" : @1}]); + withAttributes:@{ + @1: @"value" + }]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@{@"key": @1}]); #pragma clang diagnostic pop NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); @@ -467,29 +470,30 @@ - (void)testTrackTimerWithAttributesBuilder { [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@"key2"]; [builder setArray:@[@1, @2, @3] forKey:@"key3"]; [builder setArray:@[@[@"1"], @[@"2"], @[@"3"]] forKey:@"key4"]; - [builder setArray:@[@{@"value":@"key"}, @{@"value":@"key"}, @{@"value":@"key"}] forKey:@"key5"]; + [builder setArray:@[@{@"value": @"key"}, @{@"value": @"key"}, @{@"value": @"key"}] forKey:@"key5"]; [builder setArray:@[NSObject.new, NSObject.new, NSObject.new] forKey:@"key6"]; [builder setArray:@[NSNull.new, NSNull.new, NSNull.new] forKey:@"key7"]; [builder setArray:@[@"value1", @"value2", @"value3"] forKey:@""]; [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:builder.build]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventName, @"eventName"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); XCTAssertEqualObjects(event.attributes[@"key2"], @"value1||value2||value3"); XCTAssertEqualObjects(event.attributes[@"key3"], @"1||2||3"); XCTAssertEqualObjects(event.attributes[@"key4"], @"(\n 1\n)||(\n 2\n)||(\n 3\n)"); - XCTAssertEqualObjects(event.attributes[@"key5"], @"{\n value = key;\n}" - @"||{\n value = key;\n}" - @"||{\n value = key;\n}"); + XCTAssertEqualObjects(event.attributes[@"key5"], + @"{\n value = key;\n}" + @"||{\n value = key;\n}" + @"||{\n value = key;\n}"); XCTAssertNotNil(event.attributes[@"key6"]); XCTAssertEqualObjects(event.attributes[@"key7"], @"||||"); XCTAssertEqualObjects(event.attributes[@""], @"value1||value2||value3"); XCTAssertNotNil(event.attributes[kGrowingEventDuration]); } - + { [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; @@ -504,7 +508,7 @@ - (void)testTrackTimerWithAttributesBuilder { XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@"" withAttributes:builder.build]); XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:@1 withAttributes:builder.build]); XCTAssertNoThrow([[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:nil]); - + { GrowingAttributesBuilder *builder = GrowingAttributesBuilder.new; [builder setString:nil forKey:@"key"]; @@ -568,58 +572,64 @@ - (void)testSetLocation { double latitude = 31.111111111; double longitude = 32.2222222222; [[GrowingAutotracker sharedInstance] setLocation:latitude longitude:longitude]; - + XCTestExpectation *expectation = [self expectationWithDescription:@"testCleanLocation Test failed : timeout"]; expectation.expectedFulfillmentCount = 2; - + [GrowingDispatchManager dispatchInGrowingThread:^{ XCTAssertEqual([GrowingSession currentSession].latitude, latitude); XCTAssertEqual([GrowingSession currentSession].longitude, longitude); - + [expectation fulfill]; }]; [[GrowingAutotracker sharedInstance] cleanLocation]; - + [GrowingDispatchManager dispatchInGrowingThread:^{ XCTAssertEqual([GrowingSession currentSession].latitude, 0); XCTAssertEqual([GrowingSession currentSession].longitude, 0); - + [expectation fulfill]; }]; - + [self waitForExpectationsWithTimeout:10.0f handler:nil]; } - (void)testSetDataCollectionEnabled { NSString *eventName = @"name"; [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:NO]; - + [[GrowingAutotracker sharedInstance] trackCustomEvent:eventName]; - [GrowingDispatchManager dispatchInGrowingThread:^{ - NSArray *events = MockEventQueue.sharedQueue.allEvent; - XCTAssertEqual(events.count, 0); - } waitUntilDone:YES]; - + [GrowingDispatchManager + dispatchInGrowingThread:^{ + NSArray *events = MockEventQueue.sharedQueue.allEvent; + XCTAssertEqual(events.count, 0); + } + waitUntilDone:YES]; + [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:YES]; - [GrowingDispatchManager dispatchInGrowingThread:^{ - NSArray *events = MockEventQueue.sharedQueue.allEvent; - XCTAssertEqual(events.count, 1); // VISIT - - GrowingBaseEvent *event = [MockEventQueue.sharedQueue lastEventFor:GrowingEventTypeVisit]; - XCTAssertTrue([event isKindOfClass:[GrowingVisitEvent class]]); - } waitUntilDone:YES]; - + [GrowingDispatchManager + dispatchInGrowingThread:^{ + NSArray *events = MockEventQueue.sharedQueue.allEvent; + XCTAssertEqual(events.count, 1); // VISIT + + GrowingBaseEvent *event = [MockEventQueue.sharedQueue lastEventFor:GrowingEventTypeVisit]; + XCTAssertTrue([event isKindOfClass:[GrowingVisitEvent class]]); + } + waitUntilDone:YES]; + [[GrowingAutotracker sharedInstance] trackCustomEvent:eventName]; - [GrowingDispatchManager dispatchInGrowingThread:^{ - NSArray *events = MockEventQueue.sharedQueue.allEvent; - XCTAssertEqual(events.count, 2); // VISIT + CUSTOM - - GrowingBaseEvent *event = [MockEventQueue.sharedQueue lastEventFor:GrowingEventTypeCustom]; - XCTAssertTrue([event isKindOfClass:[GrowingCustomEvent class]]); - GrowingCustomEvent *customEvent = (GrowingCustomEvent *)event; - XCTAssertEqualObjects(customEvent.eventName, eventName); - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + NSArray *events = MockEventQueue.sharedQueue.allEvent; + XCTAssertEqual(events.count, 2); // VISIT + CUSTOM + + GrowingBaseEvent *event = [MockEventQueue.sharedQueue lastEventFor:GrowingEventTypeCustom]; + XCTAssertTrue([event isKindOfClass:[GrowingCustomEvent class]]); + GrowingCustomEvent *customEvent = (GrowingCustomEvent *)event; + XCTAssertEqualObjects(customEvent.eventName, eventName); + } + waitUntilDone:YES]; } #pragma mark - GrowingAutoTracker API Test @@ -627,14 +637,15 @@ - (void)testSetDataCollectionEnabled { - (void)testAutotrackPageWithoutAttributesNotTrackTest { UIViewController *controller = [[UIViewController alloc] init]; [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest"]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithoutAttributesNotTrackTest Test failed : timeout"]; + + XCTestExpectation *expectation = + [self expectationWithDescription:@"testAutotrackPageWithoutAttributesNotTrackTest Test failed : timeout"]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 0); [expectation fulfill]; }); - + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } @@ -642,12 +653,13 @@ - (void)testAutotrackPageWithoutAttributesTest { UIViewController *controller = [[UIViewController alloc] init]; [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest"]; [controller viewDidAppear:NO]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithoutAttributesTest Test failed : timeout"]; + + XCTestExpectation *expectation = + [self expectationWithDescription:@"testAutotrackPageWithoutAttributesTest Test failed : timeout"]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); - + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); XCTAssertEqualObjects(event.pageName, @"XCTest"); @@ -660,34 +672,36 @@ - (void)testAutotrackPageWithoutAttributesTest { [expectation fulfill]; }); - + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } - (void)testAutotrackPageWithAttributesNotTrackTest { UIViewController *controller = [[UIViewController alloc] init]; - [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @"value"}]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithAttributesNotTrackTest Test failed : timeout"]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key": @"value"}]; + + XCTestExpectation *expectation = + [self expectationWithDescription:@"testAutotrackPageWithAttributesNotTrackTest Test failed : timeout"]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 0); [expectation fulfill]; }); - + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } - (void)testAutotrackPageWithAttributesTest { UIViewController *controller = [[UIViewController alloc] init]; - [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @"value"}]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key": @"value"}]; [controller viewDidAppear:NO]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithAttributesTest Test failed : timeout"]; + + XCTestExpectation *expectation = + [self expectationWithDescription:@"testAutotrackPageWithAttributesTest Test failed : timeout"]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); - + GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); XCTAssertEqualObjects(event.pageName, @"XCTest"); @@ -700,7 +714,7 @@ - (void)testAutotrackPageWithAttributesTest { [expectation fulfill]; }); - + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } @@ -714,15 +728,16 @@ - (void)testAutotrackPageWithInvalidAliasTest { [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@1]; #pragma clang diagnostic pop [controller viewDidAppear:NO]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithInvalidAliasTest Test failed : timeout"]; + + XCTestExpectation *expectation = + [self expectationWithDescription:@"testAutotrackPageWithInvalidAliasTest Test failed : timeout"]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 0); [expectation fulfill]; }); - + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } @@ -733,19 +748,20 @@ - (void)testAutotrackPageWithInvalidAttributesTest { #pragma clang diagnostic ignored "-Wobjc-literal-conversion" [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:nil]; [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@"value"]; - [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@1 : @"value"}]; - [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @1}]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@1: @"value"}]; + [[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key": @1}]; #pragma clang diagnostic pop [controller viewDidAppear:NO]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"testAutotrackPageWithInvalidAttributesTest Test failed : timeout"]; + + XCTestExpectation *expectation = + [self expectationWithDescription:@"testAutotrackPageWithInvalidAttributesTest Test failed : timeout"]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 0); [expectation fulfill]; }); - + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } @@ -754,7 +770,9 @@ - (void)testAutotrackPageInNotMainThreadTest { UIViewController *controller = [[UIViewController alloc] init]; dispatch_sync(dispatch_get_global_queue(0, 0), ^{ XCTAssertNoThrow([[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest"]); - XCTAssertNoThrow([[GrowingAutotracker sharedInstance] autotrackPage:controller alias:@"XCTest" attributes:@{@"key" : @"value"}]); + XCTAssertNoThrow([[GrowingAutotracker sharedInstance] autotrackPage:controller + alias:@"XCTest" + attributes:@{@"key": @"value"}]); }); } } diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m index 996533386..5fa50c5f8 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/NSNotificationCenterAutotrackTest.m @@ -17,35 +17,35 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingServiceManager.h" -#import "GrowingEventDatabaseService.h" -#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingAutotrackerCore/Autotrack/NSNotificationCenter+GrowingAutotracker.h" -#import "MockEventQueue.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "GrowingEventDatabaseService.h" +#import "GrowingServiceManager.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" #import "InvocationHelper.h" -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "MockEventQueue.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" // 可配置growingNodeDonotTrack,从而配置可否生成VIEW_CHANGE,以供测试 -#define AutotrackXCTestClassDefine(cls) \ -@interface Autotrack##cls##_XCTest : cls \ -@property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; \ -@end \ -@implementation Autotrack##cls##_XCTest \ -@end \ -@implementation Autotrack##cls##_XCTest (DonotTrack) \ -- (BOOL)growingNodeDonotTrack { return self.growingNodeDonotTrack_XCTest; } \ -@end +#define AutotrackXCTestClassDefine(cls) \ + @interface Autotrack \ + ##cls##_XCTest : cls @property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; \ + @end \ + @implementation Autotrack \ + ##cls##_XCTest @end \ + @implementation Autotrack \ + ##cls##_XCTest(DonotTrack) - (BOOL)growingNodeDonotTrack { \ + return self.growingNodeDonotTrack_XCTest; \ + } \ + @end -AutotrackXCTestClassDefine(UITextField) -AutotrackXCTestClassDefine(UITextView) +AutotrackXCTestClassDefine(UITextField) AutotrackXCTestClassDefine(UITextView) -@interface NSNotificationCenterAutotrackTest : XCTestCase + @interface NSNotificationCenterAutotrackTest : XCTestCase @end @@ -59,7 +59,7 @@ + (void)setUp { // 避免不执行readPropertyInTrackThread config.dataCollectionEnabled = YES; GrowingConfigurationManager.sharedInstance.trackConfiguration = config; - + // 避免insertEventToDatabase异常 [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) implClass:GrowingEventProtobufDatabase.class]; @@ -86,39 +86,39 @@ - (void)testNSNotificationCenterAutotrack { // 正常改变text,发送VIEW_CHANGE [MockEventQueue.sharedQueue cleanQueue]; [NSNotificationCenter.defaultCenter postNotificationName:UITextFieldTextDidEndEditingNotification - object:textField - userInfo:@{}]; - + object:textField + userInfo:@{}]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 1); } - + { // secureTextEntry为YES,不发送VIEW_CHANGE textField.secureTextEntry = YES; - + [MockEventQueue.sharedQueue cleanQueue]; [NSNotificationCenter.defaultCenter postNotificationName:UITextFieldTextDidEndEditingNotification - object:textField - userInfo:@{}]; + object:textField + userInfo:@{}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 0); - + textField.secureTextEntry = NO; } - + { // growingNodeDonotTrack为YES,不发送VIEW_CHANGE textField.growingNodeDonotTrack_XCTest = YES; - + [MockEventQueue.sharedQueue cleanQueue]; [NSNotificationCenter.defaultCenter postNotificationName:UITextFieldTextDidEndEditingNotification - object:textField - userInfo:@{}]; + object:textField + userInfo:@{}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 0); } - + AutotrackUITextView_XCTest *textView = AutotrackUITextView_XCTest.new; textView.text = @"newText"; [textView safePerformSelector:@selector(setGrowingHookOldText:) arguments:@"oldText", nil]; @@ -126,35 +126,35 @@ - (void)testNSNotificationCenterAutotrack { // 正常改变text,发送VIEW_CHANGE [MockEventQueue.sharedQueue cleanQueue]; [NSNotificationCenter.defaultCenter postNotificationName:UITextFieldTextDidEndEditingNotification - object:textView - userInfo:@{}]; - + object:textView + userInfo:@{}]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 1); } - + { // secureTextEntry为YES,不发送VIEW_CHANGE textView.secureTextEntry = YES; - + [MockEventQueue.sharedQueue cleanQueue]; [NSNotificationCenter.defaultCenter postNotificationName:UITextFieldTextDidEndEditingNotification - object:textView - userInfo:@{}]; + object:textView + userInfo:@{}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 0); - + textView.secureTextEntry = NO; } - + { // growingNodeDonotTrack为YES,不发送VIEW_CHANGE textView.growingNodeDonotTrack_XCTest = YES; - + [MockEventQueue.sharedQueue cleanQueue]; [NSNotificationCenter.defaultCenter postNotificationName:UITextFieldTextDidEndEditingNotification - object:textView - userInfo:@{}]; + object:textView + userInfo:@{}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 0); } diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m index 479a672cd..83d3f7218 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UICollectionViewAutotrackTest.m @@ -17,26 +17,25 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingServiceManager.h" -#import "GrowingEventDatabaseService.h" -#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingAutotrackerCore/Autotrack/UICollectionView+GrowingAutotracker.h" -#import "MockEventQueue.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "GrowingEventDatabaseService.h" +#import "GrowingServiceManager.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" #import "InvocationHelper.h" -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "MockEventQueue.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" // 可配置growingNodeDonotTrack,从而配置可否生成VIEW_CLICK,以供测试 // ------------------------------------------------------------------------------- // UICollectionViewCell @interface AutotrackUICollectionViewCell_XCTest : UICollectionViewCell -@property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; +@property (nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; @end @@ -55,7 +54,7 @@ - (BOOL)growingNodeDonotTrack { // UICollectionView @interface AutotrackUICollectionView_XCTest : UICollectionView -@property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; +@property (nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; @end @@ -80,15 +79,15 @@ @interface AutotrackUICollectionView_Delegate_XCTest : NSObject -@property (nonatomic, weak) id target; +@property (nonatomic, weak) id target; -- (instancetype)initWithTarget:(id )target; +- (instancetype)initWithTarget:(id)target; @end @interface UICollectionViewAutotrackTest : XCTestCase -@property (nonatomic, strong) id delegate; +@property (nonatomic, strong) id delegate; @end @@ -102,7 +101,7 @@ + (void)setUp { // 避免不执行readPropertyInTrackThread config.dataCollectionEnabled = YES; GrowingConfigurationManager.sharedInstance.trackConfiguration = config; - + // 避免insertEventToDatabase异常 [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) implClass:GrowingEventProtobufDatabase.class]; @@ -121,13 +120,13 @@ - (void)tearDown { } - (void)test01UICollectionViewAutotrack { - AutotrackUICollectionView_XCTest *collectionView = [[AutotrackUICollectionView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100) - collectionViewLayout:UICollectionViewLayout.new]; + AutotrackUICollectionView_XCTest *collectionView = + [[AutotrackUICollectionView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100) + collectionViewLayout:UICollectionViewLayout.new]; collectionView.delegate = self; - - [collectionView.delegate collectionView:collectionView - didSelectItemAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; - + + [collectionView.delegate collectionView:collectionView didSelectItemAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); } @@ -136,20 +135,20 @@ - (void)test01UICollectionViewAutotrack { static BOOL kRealDelegateDidCalled = NO; - (void)test02UICollectionViewRealDelegate { // 普通 delegate 对象,仅实现了 UICollectionViewDelegate 方法 - AutotrackUICollectionView_XCTest *collectionView = [[AutotrackUICollectionView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100) - collectionViewLayout:UICollectionViewLayout.new]; + AutotrackUICollectionView_XCTest *collectionView = + [[AutotrackUICollectionView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100) + collectionViewLayout:UICollectionViewLayout.new]; self.delegate = [[AutotrackUICollectionView_Delegate_XCTest alloc] init]; collectionView.delegate = self.delegate; - + kDelegateDidCalled = NO; kRealDelegateDidCalled = NO; - [collectionView.delegate collectionView:collectionView - didSelectItemAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; - + [collectionView.delegate collectionView:collectionView didSelectItemAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; + // 触发了无埋点点击事件 NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); - + // 触发了 AutotrackUICollectionView_Delegate_XCTest didSelectItemAtIndexPath XCTAssertTrue(kRealDelegateDidCalled); } @@ -157,24 +156,24 @@ - (void)test02UICollectionViewRealDelegate { - (void)test03UICollectionViewRealDelegate_2 { // 特殊 delegate 对象,实现了 UICollectionViewDelegate 方法,并重写了 class 方法 // 模拟动态子类 - AutotrackUICollectionView_XCTest *collectionView = [[AutotrackUICollectionView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100) - collectionViewLayout:UICollectionViewLayout.new]; + AutotrackUICollectionView_XCTest *collectionView = + [[AutotrackUICollectionView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100) + collectionViewLayout:UICollectionViewLayout.new]; self.delegate = [[AutotrackUICollectionView_Delegate_2_XCTest alloc] initWithTarget:self]; collectionView.delegate = self.delegate; - + kDelegateDidCalled = NO; kRealDelegateDidCalled = NO; - [collectionView.delegate collectionView:collectionView - didSelectItemAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; - + [collectionView.delegate collectionView:collectionView didSelectItemAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; + // 触发了无埋点点击事件 NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; // 因为上面 test01UICollectionViewAutotrack 也对 self 进行了 hook,所以如果一起执行这里会等于 2 XCTAssertGreaterThanOrEqual(events.count, 1); - + // 触发了 UICollectionViewAutotrackTest didSelectItemAtIndexPath XCTAssertTrue(kDelegateDidCalled); - + // 触发了 AutotrackUICollectionView_Delegate_2_XCTest didSelectItemAtIndexPath XCTAssertTrue(kRealDelegateDidCalled); } @@ -203,7 +202,7 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa @implementation AutotrackUICollectionView_Delegate_2_XCTest -- (instancetype)initWithTarget:(id )target { +- (instancetype)initWithTarget:(id)target { if (self = [super init]) { _target = target; } @@ -216,7 +215,7 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa if (self.target && [self.target respondsToSelector:@selector(collectionView:didSelectItemAtIndexPath:)]) { [self.target collectionView:collectionView didSelectItemAtIndexPath:indexPath]; } - + kRealDelegateDidCalled = YES; NSLog(@"AutotrackUICollectionView_Delegate_XCTest didSelectItemAtIndexPath"); } diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UISegmentedControlAutotrackTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UISegmentedControlAutotrackTest.m index 52571a62c..b105c773b 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UISegmentedControlAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UISegmentedControlAutotrackTest.m @@ -17,12 +17,11 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "InvocationHelper.h" -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" #import "GrowingAutotrackerCore/Autotrack/UISegmentedControl+GrowingAutotracker.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "InvocationHelper.h" @interface UISegmentedControlAutotrackTest : XCTestCase @@ -47,7 +46,7 @@ - (void)testUISegmentedControlAutotrack { Class cls = NSClassFromString(@"GrowingUISegmentedControlObserver"); id sharedInstance = [cls safePerformSelector:@selector(sharedInstance)]; XCTAssertNotNil(sharedInstance); - + // initWithFrame: { UISegmentedControl *control = [[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; @@ -59,10 +58,11 @@ - (void)testUISegmentedControlAutotrack { UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"1", @"2"]]; XCTAssertTrue([control.allTargets containsObject:sharedInstance]); } - + // 多次 init { - UISegmentedControl *control = [[[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] initWithFrame:CGRectMake(0, 0, 100, 100)]; + UISegmentedControl *control = [[[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] + initWithFrame:CGRectMake(0, 0, 100, 100)]; XCTAssertTrue([control.allTargets containsObject:sharedInstance]); } } diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m index db88cc41e..2993904f1 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/Autotrack/UITableViewAutotrackTest.m @@ -17,26 +17,25 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingServiceManager.h" -#import "GrowingEventDatabaseService.h" -#import "Services/Protobuf/GrowingEventProtobufDatabase.h" #import "GrowingAutotrackerCore/Autotrack/UITableView+GrowingAutotracker.h" -#import "MockEventQueue.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "GrowingEventDatabaseService.h" +#import "GrowingServiceManager.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" #import "InvocationHelper.h" -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "MockEventQueue.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" // 可配置growingNodeDonotTrack,从而配置可否生成VIEW_CLICK,以供测试 // ------------------------------------------------------------------------------- // UITableViewCell @interface AutotrackUITableViewCell_XCTest : UITableViewCell -@property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; +@property (nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; @end @@ -55,7 +54,7 @@ - (BOOL)growingNodeDonotTrack { // UITableView @interface AutotrackUITableView_XCTest : UITableView -@property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; +@property (nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; @end @@ -80,15 +79,15 @@ @interface AutotrackUITableView_Delegate_XCTest : NSObject @interface AutotrackUITableView_Delegate_2_XCTest : NSObject -@property (nonatomic, weak) id target; +@property (nonatomic, weak) id target; -- (instancetype)initWithTarget:(id )target; +- (instancetype)initWithTarget:(id)target; @end @interface UITableViewAutotrackTest : XCTestCase -@property (nonatomic, strong) id delegate; +@property (nonatomic, strong) id delegate; @end @@ -102,7 +101,7 @@ + (void)setUp { // 避免不执行readPropertyInTrackThread config.dataCollectionEnabled = YES; GrowingConfigurationManager.sharedInstance.trackConfiguration = config; - + // 避免insertEventToDatabase异常 [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) implClass:GrowingEventProtobufDatabase.class]; @@ -121,11 +120,12 @@ - (void)tearDown { } - (void)test01UITableViewAutotrack { - AutotrackUITableView_XCTest *tableView = [[AutotrackUITableView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + AutotrackUITableView_XCTest *tableView = + [[AutotrackUITableView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; tableView.delegate = self; - + [tableView.delegate tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); } @@ -134,18 +134,19 @@ - (void)test01UITableViewAutotrack { static BOOL kRealDelegateDidCalled = NO; - (void)test02UITableViewRealDelegate { // 普通 delegate 对象,仅实现了 UITableViewDelegate 方法 - AutotrackUITableView_XCTest *tableView = [[AutotrackUITableView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + AutotrackUITableView_XCTest *tableView = + [[AutotrackUITableView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; self.delegate = [AutotrackUITableView_Delegate_XCTest new]; tableView.delegate = self.delegate; - + kDelegateDidCalled = NO; kRealDelegateDidCalled = NO; [tableView.delegate tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; - + // 触发了无埋点点击事件 NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); - + // 触发了 AutotrackUITableView_Delegate_XCTest didSelectRowAtIndexPath XCTAssertTrue(kRealDelegateDidCalled); } @@ -153,22 +154,23 @@ - (void)test02UITableViewRealDelegate { - (void)test03UITableViewRealDelegate_2 { // 特殊 delegate 对象,实现了 UITableViewDelegate 方法,并重写了 class 方法 // 模拟动态子类 - AutotrackUITableView_XCTest *tableView = [[AutotrackUITableView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + AutotrackUITableView_XCTest *tableView = + [[AutotrackUITableView_XCTest alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; self.delegate = [[AutotrackUITableView_Delegate_2_XCTest alloc] initWithTarget:self]; tableView.delegate = self.delegate; - + kDelegateDidCalled = NO; kRealDelegateDidCalled = NO; [tableView.delegate tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathWithIndex:0]]; - + // 触发了无埋点点击事件 NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; // 因为上面 test01UITableViewAutotrack 也对 self 进行了 hook,所以如果一起执行这里会等于 2 XCTAssertGreaterThanOrEqual(events.count, 1); - + // 触发了 UITableViewAutotrackTest didSelectRowAtIndexPath XCTAssertTrue(kDelegateDidCalled); - + // 触发了 AutotrackUITableView_Delegate_2_XCTest didSelectRowAtIndexPath XCTAssertTrue(kRealDelegateDidCalled); } @@ -197,7 +199,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIn @implementation AutotrackUITableView_Delegate_2_XCTest -- (instancetype)initWithTarget:(id )target { +- (instancetype)initWithTarget:(id)target { if (self = [super init]) { _target = target; } diff --git a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m index d09ab9915..72e85192d 100644 --- a/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m +++ b/Example/GrowingAnalyticsTests/AutotrackerCoreTests/GrowingNodeTests/NodeTest.m @@ -33,10 +33,10 @@ - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. } --(void)testGrowingUIViewController { +- (void)testGrowingUIViewController { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" - UIViewController *vc1 = [[UIViewController alloc]init]; + UIViewController *vc1 = [[UIViewController alloc] init]; [vc1 performSelector:@selector(growingNodeParent)]; [vc1 performSelector:@selector(growingNodeKeyIndex)]; [vc1 performSelector:@selector(growingNodeSubPath)]; diff --git a/Example/GrowingAnalyticsTests/GrowingAnalyticsStartTests/GrowingAnalyticsStartTests.m b/Example/GrowingAnalyticsTests/GrowingAnalyticsStartTests/GrowingAnalyticsStartTests.m index 947884a56..6e87ca16b 100644 --- a/Example/GrowingAnalyticsTests/GrowingAnalyticsStartTests/GrowingAnalyticsStartTests.m +++ b/Example/GrowingAnalyticsTests/GrowingAnalyticsStartTests/GrowingAnalyticsStartTests.m @@ -17,17 +17,16 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" -#import "GrowingTrackerCore/GrowingRealTracker.h" #import "GrowingAutotrackConfiguration.h" +#import "GrowingAutotracker.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" #import "GrowingTrackConfiguration.h" +#import "GrowingTracker.h" +#import "GrowingTrackerCore/GrowingRealTracker.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" -#import "GrowingTracker.h" -#import "GrowingAutotracker.h" @interface GrowingAnalyticsStartTests : XCTestCase @@ -47,24 +46,24 @@ - (void)tearDown { #pragma clang diagnostic ignored "-Wnonnull" - (void)testGrowingTrackerStart { - XCTAssertThrowsSpecificNamed(GrowingTracker.sharedInstance, - NSException, - @"GrowingTracker未初始化"); - + XCTAssertThrowsSpecificNamed(GrowingTracker.sharedInstance, NSException, @"GrowingTracker未初始化"); + GrowingTrackConfiguration *config = [GrowingTrackConfiguration configurationWithProjectId:@"xctest"]; XCTAssertThrowsSpecificNamed([GrowingTracker startWithConfiguration:config launchOptions:nil], NSException, @"初始化异常"); - + config.dataSourceId = @"xctest"; [GrowingTracker startWithConfiguration:config launchOptions:nil]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertThrowsSpecificNamed([GrowingTracker startWithConfiguration:config launchOptions:nil], - NSException, - @"初始化异常"); - } waitUntilDone:YES]; - + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertThrowsSpecificNamed([GrowingTracker startWithConfiguration:config launchOptions:nil], + NSException, + @"初始化异常"); + } + waitUntilDone:YES]; + GrowingTrackConfiguration *config2 = [GrowingTrackConfiguration configurationWithProjectId:@""]; XCTAssertThrowsSpecificNamed([GrowingTracker startWithConfiguration:config2 launchOptions:nil], NSException, @@ -72,24 +71,24 @@ - (void)testGrowingTrackerStart { } - (void)testGrowingAutotrackerStart { - XCTAssertThrowsSpecificNamed(GrowingAutotracker.sharedInstance, - NSException, - @"GrowingAutotracker未初始化"); - + XCTAssertThrowsSpecificNamed(GrowingAutotracker.sharedInstance, NSException, @"GrowingAutotracker未初始化"); + GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"xctest"]; XCTAssertThrowsSpecificNamed([GrowingAutotracker startWithConfiguration:config launchOptions:nil], NSException, @"初始化异常"); - + config.dataSourceId = @"xctest"; [GrowingAutotracker startWithConfiguration:config launchOptions:nil]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertThrowsSpecificNamed([GrowingAutotracker startWithConfiguration:config launchOptions:nil], - NSException, - @"初始化异常"); - } waitUntilDone:YES]; - + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertThrowsSpecificNamed([GrowingAutotracker startWithConfiguration:config launchOptions:nil], + NSException, + @"初始化异常"); + } + waitUntilDone:YES]; + GrowingAutotrackConfiguration *config2 = [GrowingAutotrackConfiguration configurationWithProjectId:@""]; XCTAssertThrowsSpecificNamed([GrowingAutotracker startWithConfiguration:config2 launchOptions:nil], NSException, @@ -101,8 +100,9 @@ - (void)testGrowingAutotrackerStart { - (void)testDefaultConfiguration_Autotracker { GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; [GrowingRealAutotracker trackerWithConfiguration:config launchOptions:nil]; - - GrowingAutotrackConfiguration *configuration = (GrowingAutotrackConfiguration *)GrowingConfigurationManager.sharedInstance.trackConfiguration; + + GrowingAutotrackConfiguration *configuration = + (GrowingAutotrackConfiguration *)GrowingConfigurationManager.sharedInstance.trackConfiguration; XCTAssertEqual(configuration.debugEnabled, NO); XCTAssertEqual(configuration.cellularDataLimit, 10); XCTAssertEqual(configuration.dataUploadInterval, 15); @@ -137,7 +137,8 @@ - (void)testSetConfiguration_Autotracker { config.dataSourceId = @"12345"; [GrowingRealAutotracker trackerWithConfiguration:config launchOptions:nil]; - GrowingAutotrackConfiguration *configuration = (GrowingAutotrackConfiguration *)GrowingConfigurationManager.sharedInstance.trackConfiguration; + GrowingAutotrackConfiguration *configuration = + (GrowingAutotrackConfiguration *)GrowingConfigurationManager.sharedInstance.trackConfiguration; XCTAssertEqual(configuration.debugEnabled, YES); XCTAssertEqual(configuration.cellularDataLimit, 5); XCTAssertEqual(configuration.dataUploadInterval, 10); @@ -157,7 +158,7 @@ - (void)testSetConfiguration_Autotracker { - (void)testDefaultConfiguration_Tracker { GrowingTrackConfiguration *config = [GrowingTrackConfiguration configurationWithProjectId:@"test"]; [GrowingRealTracker trackerWithConfiguration:config launchOptions:nil]; - + GrowingTrackConfiguration *configuration = GrowingConfigurationManager.sharedInstance.trackConfiguration; XCTAssertEqual(configuration.debugEnabled, NO); XCTAssertEqual(configuration.cellularDataLimit, 10); diff --git a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkTest.m b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkTest.m index cffb7d9f3..9b535046f 100644 --- a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkTest.m +++ b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkTest.m @@ -28,13 +28,15 @@ @implementation DeepLinkTest - (void)setUp { // Put setup code here. This method is called before the invocation of each test method in the class. - + // In UI tests it is usually best to stop immediately when a failure occurs. self.continueAfterFailure = NO; - // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. + // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test + // method. - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests + // before they run. The setUp method is a good place to do this. } - (void)tearDown { @@ -126,14 +128,14 @@ - (void)tearDown { // NSString *url = @"growing.deeplink://growingio/webservice?serviceType=circle" // @"&wsUrl=ws://uat-gdp.growingio.com/app/weDq7mpE/circle/f1bcb578cdc347fc872192b55d2bb764" // @"&xctest=DeepLinkTest"; -// +// // XCUIApplication *app = [[XCUIApplication alloc] init]; // [app launch]; // [app terminate]; -// +// // [DeepLinkTestHelper openFromSafari:url]; // XCTAssertTrue([app waitForState:XCUIApplicationStateRunningForeground timeout:15]); -// +// // // 不出现deepLinkCallback弹窗 // XCUIElement *testButton = app.buttons[@"XCTest"]; // XCTAssertFalse([testButton waitForExistenceWithTimeout:15]); diff --git a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkiOS13UISceneTest.m b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkiOS13UISceneTest.m index a1536701f..cc0365c5f 100644 --- a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkiOS13UISceneTest.m +++ b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/DeepLinkiOS13UISceneTest.m @@ -28,13 +28,15 @@ @implementation DeepLinkiOS13UISceneTest - (void)setUp { // Put setup code here. This method is called before the invocation of each test method in the class. - + // In UI tests it is usually best to stop immediately when a failure occurs. self.continueAfterFailure = NO; - // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. + // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test + // method. - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests + // before they run. The setUp method is a good place to do this. } - (void)tearDown { @@ -126,14 +128,14 @@ - (void)tearDown { // NSString *url = @"growing.deeplink://growingio/webservice?serviceType=circle" // @"&wsUrl=ws://uat-gdp.growingio.com/app/weDq7mpE/circle/f1bcb578cdc347fc872192b55d2bb764" // @"&xctest=DeepLinkTest"; -// +// // XCUIApplication *app = [[XCUIApplication alloc] init]; // [app launch]; // [app terminate]; -// +// // [DeepLinkTestHelper openFromSafari:url]; // XCTAssertTrue([app waitForState:XCUIApplicationStateRunningForeground timeout:15]); -// +// // // 不出现deepLinkCallback弹窗 // XCUIElement *testButton = app.buttons[@"XCTest"]; // XCTAssertFalse([testButton waitForExistenceWithTimeout:15]); diff --git a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.h b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.h index 01a62285a..34c55809f 100644 --- a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.h +++ b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.h @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import NS_ASSUME_NONNULL_BEGIN diff --git a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.m b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.m index 546f80089..016766286 100644 --- a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.m +++ b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/DeepLinkTestHelper.m @@ -26,14 +26,14 @@ @implementation DeepLinkTestHelper + (void)openSafariDeeplink:(NSString *)urlString terminateFirst:(BOOL)terminateFirst { XCUIApplication *app = [[XCUIApplication alloc] init]; [app launch]; - + if (terminateFirst) { [app terminate]; } - + [self openFromSafari:[NSString stringWithFormat:@"%@&xctest=DeepLinkTest", urlString]]; XCTAssertTrue([app waitForState:XCUIApplicationStateRunningForeground timeout:5]); - + XCUIElement *testButton = app.buttons[@"XCTest"]; XCTAssertTrue([testButton waitForExistenceWithTimeout:5]); [testButton tap]; @@ -43,17 +43,17 @@ + (void)openFromSafari:(NSString *)urlString { XCUIApplication *safari = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.mobilesafari"]; [safari launch]; XCTAssertTrue([safari waitForState:XCUIApplicationStateRunningForeground timeout:5]); - + XCUIElementQuery *buttonsQuery = [safari.buttons matchingIdentifier:@"Continue"]; - if (buttonsQuery.count> 0) { + if (buttonsQuery.count > 0) { XCUIElement *firstLaunchContinueButton = [buttonsQuery elementBoundByIndex:0]; if (firstLaunchContinueButton.exists) { [firstLaunchContinueButton tap]; } } - + [safari.textFields[@"TabBarItemTitle"] tap]; - + XCUIElementQuery *buttonsQuery2 = [safari.buttons matchingIdentifier:@"Continue"]; if (buttonsQuery2.count > 0) { XCUIElement *keyboardTutorialButton = [buttonsQuery2 elementBoundByIndex:0]; @@ -61,12 +61,12 @@ + (void)openFromSafari:(NSString *)urlString { [keyboardTutorialButton tap]; } } - + [safari typeText:urlString]; XCUIElement *goButton = safari.buttons[@"go"]; XCTAssertTrue([goButton waitForExistenceWithTimeout:2]); [goButton tap]; - + XCUIElement *confirmationButton = safari.buttons[@"Open"]; XCTAssertTrue([confirmationButton waitForExistenceWithTimeout:10]); [confirmationButton tap]; @@ -75,14 +75,14 @@ + (void)openFromSafari:(NSString *)urlString { + (void)openMessagesUniversalLink:(NSString *)urlString terminateFirst:(BOOL)terminateFirst { XCUIApplication *app = [[XCUIApplication alloc] init]; [app launch]; - + if (terminateFirst) { [app terminate]; } - + [self openFromMessages:[NSString stringWithFormat:@"%@&xctest=DeepLinkTest", urlString]]; XCTAssertTrue([app waitForState:XCUIApplicationStateRunningForeground timeout:5]); - + XCUIElement *testButton = app.buttons[@"XCTest"]; XCTAssertTrue([testButton waitForExistenceWithTimeout:5]); [testButton tap]; @@ -97,7 +97,7 @@ + (void)openFromMessages:(NSString *)urlString { if (continueButton.exists) { [continueButton tap]; } - + XCUIElement *okButton = messages.buttons[@"OK"]; if (okButton.exists) { [okButton tap]; @@ -107,24 +107,24 @@ + (void)openFromMessages:(NSString *)urlString { if (cancelButton.exists) { [cancelButton tap]; } - + XCUIElement *chat = [messages.cells firstMatch]; XCTAssertTrue([chat waitForExistenceWithTimeout:5]); [chat tap]; - + [messages.textFields[@"iMessage"] tap]; - + XCUIElement *keyboardTutorialButton = messages.buttons[@"Continue"]; if (keyboardTutorialButton.exists) { [keyboardTutorialButton tap]; } - + [messages typeText:[NSString stringWithFormat:@"Link: %@", urlString]]; XCUIElement *sendButton = messages.buttons[@"Send"]; if (sendButton.exists) { [sendButton tap]; } - + XCUIElement *bubble = [messages.links firstMatch]; XCTAssertTrue([bubble waitForExistenceWithTimeout:5]); sleep(5); diff --git a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/GrowingDeepLinkHandler+XCTest.m b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/GrowingDeepLinkHandler+XCTest.m index dca832895..a0b689b5f 100644 --- a/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/GrowingDeepLinkHandler+XCTest.m +++ b/Example/GrowingAnalyticsTests/GrowingAnalyticsUITests/DeepLinkTests/Helper/GrowingDeepLinkHandler+XCTest.m @@ -17,19 +17,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "GrowingDeepLinkHandler+XCTest.h" -#import "GrowingTrackerCore/DeepLink/GrowingDeepLinkHandler.h" #import #import +#import "GrowingDeepLinkHandler+XCTest.h" +#import "GrowingTrackerCore/DeepLink/GrowingDeepLinkHandler.h" @implementation GrowingDeepLinkHandler (XCTest) + (void)load { SEL originSelector = @selector(handlerUrl:); SEL swizzleSelector = @selector(XCTest_handlerUrl:); - + id handler = object_getClass(self); - + Method originMethod = class_getInstanceMethod(handler, originSelector); if (!originMethod) { return; @@ -46,7 +46,7 @@ + (void)load { swizzleSelector, class_getMethodImplementation(handler, swizzleSelector), method_getTypeEncoding(swizzleMethod)); - + method_exchangeImplementations(class_getInstanceMethod(handler, originSelector), class_getInstanceMethod(handler, swizzleSelector)); } @@ -57,12 +57,14 @@ + (BOOL)XCTest_handlerUrl:(NSURL *)url { UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"XCTest_handlerUrl" message:@"" preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"XCTest" style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"XCTest" + style:UIAlertActionStyleCancel + handler:nil]; [controller addAction:cancel]; [self.XCTest_keywindow.rootViewController presentViewController:controller animated:YES completion:nil]; }); } - + return [self XCTest_handlerUrl:url]; } diff --git a/Example/GrowingAnalyticsTests/Helper/InvocationHelper.h b/Example/GrowingAnalyticsTests/Helper/InvocationHelper.h index cc8c41506..f0a21a3a9 100644 --- a/Example/GrowingAnalyticsTests/Helper/InvocationHelper.h +++ b/Example/GrowingAnalyticsTests/Helper/InvocationHelper.h @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import NS_ASSUME_NONNULL_BEGIN diff --git a/Example/GrowingAnalyticsTests/Helper/InvocationHelper.m b/Example/GrowingAnalyticsTests/Helper/InvocationHelper.m index bd7eb4d49..354c507da 100644 --- a/Example/GrowingAnalyticsTests/Helper/InvocationHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/InvocationHelper.m @@ -127,8 +127,7 @@ + (void)invocationInvoke:(NSInvocation *)invocation target:(id)target selector:( NSUInteger argsCount = invocation.methodSignature.numberOfArguments - 2; for (NSUInteger i = 0; i < argsCount; ++i) { const char *argType = [invocation.methodSignature getArgumentTypeAtIndex:i + 2]; - if (argType[0] == _C_CONST) - argType++; + if (argType[0] == _C_CONST) argType++; if (argType[0] == '@') { // id and block ARG_GET_SET(id); } else if (strcmp(argType, @encode(Class)) == 0) { // Class @@ -159,9 +158,9 @@ + (void)invocationInvoke:(NSInvocation *)invocation target:(id)target selector:( ARG_GET_SET(int); } else if (strcmp(argType, @encode(unsigned int)) == 0) { ARG_GET_SET(unsigned int); - } else if (strcmp(argType, @encode(BOOL)) == 0 || strcmp(argType, @encode(bool)) == 0 - || strcmp(argType, @encode(char)) == 0 || strcmp(argType, @encode(unsigned char)) == 0 - || strcmp(argType, @encode(short)) == 0 || strcmp(argType, @encode(unsigned short)) == 0) { + } else if (strcmp(argType, @encode(BOOL)) == 0 || strcmp(argType, @encode(bool)) == 0 || + strcmp(argType, @encode(char)) == 0 || strcmp(argType, @encode(unsigned char)) == 0 || + strcmp(argType, @encode(short)) == 0 || strcmp(argType, @encode(unsigned short)) == 0) { ARG_GET_SET(int); } else { // struct union and array diff --git a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m index 37e99c8e0..4d218b4af 100644 --- a/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m +++ b/Example/GrowingAnalyticsTests/Helper/ManualTrackHelper.m @@ -116,7 +116,7 @@ + (BOOL)contextOptionalPropertyCheck:(NSDictionary *)event { return NO; } } - + return YES; } @@ -168,7 +168,7 @@ + (BOOL)emptyPropertyCheck:(NSDictionary *)event optional:(NSArray *)optional { } } } - + if (!thisEmptyKeyIsOptional) { allEmptyKeysAreOptional = NO; break; @@ -205,9 +205,9 @@ + (NSDictionary *)compareArray:(NSArray *)arr1 toAnother:(NSArray *)arr2 { NSArray *reduce = [arr1 filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"NOT (SELF in %@)", arr2]]; NSArray *incre = [arr2 filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"NOT (SELF in %@)", arr1]]; if (reduce.count == 0 && incre.count == 0) { - cmpres = @{@"chres" : @"same", @"reduce" : @"", @"incre" : @""}; + cmpres = @{@"chres": @"same", @"reduce": @"", @"incre": @""}; } else { - cmpres = @{@"chres" : @"different", @"reduce" : reduce, @"incre" : incre}; + cmpres = @{@"chres": @"different", @"reduce": reduce, @"incre": incre}; } return cmpres; } @@ -220,7 +220,7 @@ + (NSDictionary *)checkDictEmpty:(NSDictionary *)checkDict { for (NSString *key in checkDict) { id value = checkDict[key]; NSString *waitForCheckString = nil; - //添加对多重字典的支持 + // 添加对多重字典的支持 if ([value isKindOfClass:[NSDictionary class]]) { [self checkDictEmpty:value]; continue; @@ -242,9 +242,9 @@ + (NSDictionary *)checkDictEmpty:(NSDictionary *)checkDict { } if (emptykeys.count > 0) { - dechres = @{@"chres" : @"Failed", @"EmptyKeys" : emptykeys}; + dechres = @{@"chres": @"Failed", @"EmptyKeys": emptykeys}; } else { - dechres = @{@"chres" : @"Passed", @"EmptyKeys" : @""}; + dechres = @{@"chres": @"Passed", @"EmptyKeys": @""}; } return dechres; } @@ -252,34 +252,17 @@ + (NSDictionary *)checkDictEmpty:(NSDictionary *)checkDict { #pragma mark - Setter & Getter + (NSArray *)context { - NSArray *context = @[@"platform", - @"platformVersion", - @"deviceId", - @"sessionId", - @"eventType", - @"timestamp", - @"domain", - @"urlScheme", - @"appState", - @"eventSequenceId", - @"networkState", - @"screenHeight", - @"screenWidth", - @"deviceBrand", - @"deviceModel", - @"deviceType", - @"appVersion", - @"appName", - @"language", - @"sdkVersion"]; + NSArray *context = @[ + @"platform", @"platformVersion", @"deviceId", @"sessionId", @"eventType", + @"timestamp", @"domain", @"urlScheme", @"appState", @"eventSequenceId", + @"networkState", @"screenHeight", @"screenWidth", @"deviceBrand", @"deviceModel", + @"deviceType", @"appVersion", @"appName", @"language", @"sdkVersion" + ]; return context; } + (NSArray *)contextOptional { - NSArray *contextOptional = @[@"userId", - @"latitude", - @"longitude", - @"userKey"]; + NSArray *contextOptional = @[@"userId", @"latitude", @"longitude", @"userKey"]; return contextOptional; } diff --git a/Example/GrowingAnalyticsTests/Helper/MockEventQueue.m b/Example/GrowingAnalyticsTests/Helper/MockEventQueue.m index c76207bbf..52ba67bb7 100644 --- a/Example/GrowingAnalyticsTests/Helper/MockEventQueue.m +++ b/Example/GrowingAnalyticsTests/Helper/MockEventQueue.m @@ -7,8 +7,8 @@ // #import "MockEventQueue.h" -#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" +#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" @interface MockEventQueue () @@ -55,77 +55,91 @@ - (void)cleanQueue { - (NSArray *)eventsFor:(NSString *)eventType { NSMutableArray *events = [NSMutableArray array]; - [GrowingDispatchManager dispatchInGrowingThread:^{ - [self.eventQueue enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { - if ([event.eventType isEqualToString:eventType]) { - [events addObject:event]; - } - }]; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + [self.eventQueue enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { + if ([event.eventType isEqualToString:eventType]) { + [events addObject:event]; + } + }]; + } + waitUntilDone:YES]; return events.count > 0 ? events : nil; } - (GrowingBaseEvent *)lastEventFor:(NSString *)eventType { __block GrowingBaseEvent *last; - [GrowingDispatchManager dispatchInGrowingThread:^{ - NSArray *reverse = self.eventQueue.reverseObjectEnumerator.allObjects; - [reverse enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { - if ([event.eventType isEqualToString:eventType]) { - last = event; - *stop = YES; - } - }]; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + NSArray *reverse = self.eventQueue.reverseObjectEnumerator.allObjects; + [reverse enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { + if ([event.eventType isEqualToString:eventType]) { + last = event; + *stop = YES; + } + }]; + } + waitUntilDone:YES]; return last; } - (NSUInteger)eventCount { __block int count = 0; - [GrowingDispatchManager dispatchInGrowingThread:^{ - count = (int)self.eventQueue.count; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + count = (int)self.eventQueue.count; + } + waitUntilDone:YES]; return count; } - (NSMutableArray *)allEvent { __block NSMutableArray *allevent = nil; - [GrowingDispatchManager dispatchInGrowingThread:^{ - allevent = self.eventQueue; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + allevent = self.eventQueue; + } + waitUntilDone:YES]; return allevent; } - (NSUInteger)eventCountFor:(NSString *)eventType { __block NSUInteger eventCount = 0; - [GrowingDispatchManager dispatchInGrowingThread:^{ - [self.eventQueue enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { - if ([event.eventType isEqualToString:eventType]) { - eventCount++; - } - }]; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + [self.eventQueue enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { + if ([event.eventType isEqualToString:eventType]) { + eventCount++; + } + }]; + } + waitUntilDone:YES]; return eventCount; } - (GrowingBaseEvent *)eventAt:(NSUInteger)index { __block GrowingBaseEvent *event = nil; - [GrowingDispatchManager dispatchInGrowingThread:^{ - event = [self.eventQueue objectAtIndex:index]; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + event = [self.eventQueue objectAtIndex:index]; + } + waitUntilDone:YES]; return event; } - (GrowingBaseEvent *)eventAt:(NSUInteger)index forType:(NSString *)eventType { __block GrowingBaseEvent *eventForType = nil; - [GrowingDispatchManager dispatchInGrowingThread:^{ - [self.eventQueue enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { - if ([event.eventType isEqualToString:eventType]) { - eventForType = event; - *stop = YES; - } - }]; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + [self.eventQueue enumerateObjectsUsingBlock:^(GrowingBaseEvent *event, NSUInteger idx, BOOL *stop) { + if ([event.eventType isEqualToString:eventType]) { + eventForType = event; + *stop = YES; + } + }]; + } + waitUntilDone:YES]; return eventForType; } diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m index 0e3cda04f..03bdef615 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UIApplicationAutotrackTest.m @@ -17,40 +17,38 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingServiceManager.h" -#import "GrowingEventDatabaseService.h" #import "GrowingAutotrackerCore/Autotrack/UIApplication+GrowingAutotracker.h" -#import "MockEventQueue.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "GrowingEventDatabaseService.h" +#import "GrowingServiceManager.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" #import "InvocationHelper.h" -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" +#import "MockEventQueue.h" // 需要有HostApplication,不然UIApplication.sharedApplication为nil // 可配置growingNodeDonotTrack,从而配置可否生成VIEW_CLICK,以供测试 -#define AutotrackXCTestClassDefine(cls) \ -@interface Autotrack##cls##_XCTest : cls \ -@property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; \ -@end \ -@implementation Autotrack##cls##_XCTest \ -@end \ -@implementation Autotrack##cls##_XCTest (DonotTrack) \ -- (BOOL)growingNodeDonotTrack { return self.growingNodeDonotTrack_XCTest; } \ -@end - -AutotrackXCTestClassDefine(UITabBarItem) -AutotrackXCTestClassDefine(UIBarButtonItem) -AutotrackXCTestClassDefine(UISegmentedControl) -AutotrackXCTestClassDefine(UISwitch) -AutotrackXCTestClassDefine(UIStepper) -AutotrackXCTestClassDefine(UIPageControl) - -@interface UIApplicationAutotrackTest : XCTestCase +#define AutotrackXCTestClassDefine(cls) \ + @interface Autotrack \ + ##cls##_XCTest : cls @property(nonatomic, assign) BOOL growingNodeDonotTrack_XCTest; \ + @end \ + @implementation Autotrack \ + ##cls##_XCTest @end \ + @implementation Autotrack \ + ##cls##_XCTest(DonotTrack) - (BOOL)growingNodeDonotTrack { \ + return self.growingNodeDonotTrack_XCTest; \ + } \ + @end + +AutotrackXCTestClassDefine(UITabBarItem) AutotrackXCTestClassDefine(UIBarButtonItem) + AutotrackXCTestClassDefine(UISegmentedControl) AutotrackXCTestClassDefine(UISwitch) + AutotrackXCTestClassDefine(UIStepper) AutotrackXCTestClassDefine(UIPageControl) + + @interface UIApplicationAutotrackTest : XCTestCase @property (nonatomic, strong) UIEvent *event; @property (nonatomic, strong) AutotrackUITabBarItem_XCTest *tabBarItem; @@ -83,10 +81,7 @@ - (void)testUITabBarAction { self.switchT = AutotrackUISwitch_XCTest.new; self.switchT.growingNodeDonotTrack_XCTest = NO; - [UIApplication.sharedApplication sendAction:@selector(class) - to:UITabBar.new - from:self.switchT - forEvent:self.event]; + [UIApplication.sharedApplication sendAction:@selector(class) to:UITabBar.new from:self.switchT forEvent:self.event]; dispatch_block_t block = ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); @@ -127,7 +122,7 @@ - (void)testUITabBarItemAction { - (void)testUIBarButtonItemAction { self.barButtonItem = AutotrackUIBarButtonItem_XCTest.new; self.barButtonItem.growingNodeDonotTrack_XCTest = NO; - + [UIApplication.sharedApplication sendAction:@selector(barButtonItemAction:) to:self from:self.barButtonItem @@ -142,7 +137,7 @@ - (void)testUIBarButtonItemAction { - (void)testUISegmentedControlAction { self.segmentedControl = AutotrackUISegmentedControl_XCTest.new; self.segmentedControl.growingNodeDonotTrack_XCTest = NO; - + [UIApplication.sharedApplication sendAction:@selector(segmentedControlAction:) to:self from:self.segmentedControl @@ -157,11 +152,8 @@ - (void)testUISegmentedControlAction { - (void)testUISwitchAction { self.switchT = AutotrackUISwitch_XCTest.new; self.switchT.growingNodeDonotTrack_XCTest = NO; - - [UIApplication.sharedApplication sendAction:@selector(switchAction:) - to:self - from:self.switchT - forEvent:self.event]; + + [UIApplication.sharedApplication sendAction:@selector(switchAction:) to:self from:self.switchT forEvent:self.event]; dispatch_block_t block = ^{ NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); @@ -172,7 +164,7 @@ - (void)testUISwitchAction { - (void)testUIStepperAction { self.stepper = AutotrackUIStepper_XCTest.new; self.stepper.growingNodeDonotTrack_XCTest = NO; - + [UIApplication.sharedApplication sendAction:@selector(stepperAction:) to:self from:self.stepper @@ -187,7 +179,7 @@ - (void)testUIStepperAction { - (void)testUIPageControlAction { self.pageControl = AutotrackUIPageControl_XCTest.new; self.pageControl.growingNodeDonotTrack_XCTest = NO; - + [UIApplication.sharedApplication sendAction:@selector(pageControlAction:) to:self from:self.pageControl diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m index 074f48ea3..0108659b5 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m @@ -17,14 +17,13 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingAutotracker.h" -#import "MockEventQueue.h" -#import "ManualTrackHelper.h" -#import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "GrowingAutotrackerCore/Autotrack/UITapGestureRecognizer+GrowingAutotracker.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "ManualTrackHelper.h" +#import "MockEventQueue.h" // 使用"click请求"页面,测试-[UITapGestureRecognizer growing_initWithCoder:]函数 @@ -39,7 +38,7 @@ - (void)beforeAll { [GrowingAutotracker.sharedInstance setLoginUserId:@"xctest_userId" userKey:@"xctest_userKey"]; // latitude longitude [GrowingAutotracker.sharedInstance setLocation:30.12345 longitude:31.123456]; - + [[viewTester usingLabel:@"协议/接口"] tap]; [[viewTester usingLabel:@"CLICK请求"] tap]; [viewTester waitForTimeInterval:1]; @@ -54,17 +53,16 @@ - (void)setUp { } - (void)tearDown { - } - (void)testTapGestureHook { // initWithCoder: { [[viewTester usingLabel:@"singleTapView"] tap]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); - + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); @@ -79,10 +77,10 @@ - (void)testTapGestureHook { UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(class)]; [[viewTester usingLabel:@"doubleTapView"].view addGestureRecognizer:tap]; [[viewTester usingLabel:@"doubleTapView"] tap]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); - + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index dea38303b..420419a99 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -9,11 +9,11 @@ #import #import "GrowingAutotracker.h" -#import "MockEventQueue.h" -#import "ManualTrackHelper.h" -#import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "GrowingAutotrackerCore/GrowingNode/GrowingNodeHelper.h" #import "GrowingAutotrackerCore/Page/GrowingPageManager.h" +#import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "ManualTrackHelper.h" +#import "MockEventQueue.h" @interface A1ViewClickEventsTest : KIFTestCase @@ -37,20 +37,25 @@ - (void)tearDown { [[viewTester usingLabel:@"UI界面"] tap]; } -- (void)checkWebCirclePathWithView:(UIView *)view xpath:(NSString *)xpathForView xcontent:(NSString *)xcontentForView originxcontent:(NSString *)originxcontentForView { +- (void)checkWebCirclePathWithView:(UIView *)view + xpath:(NSString *)xpathForView + xcontent:(NSString *)xcontentForView + originxcontent:(NSString *)originxcontentForView { // 检查圈选的计算逻辑得出的xpath、xcontent是否正确 GrowingPage *page = [[GrowingPageManager sharedInstance] findPageByView:view]; NSDictionary *pathInfo = page.pathInfo; NSString *pagexpath = pathInfo[@"xpath"]; NSString *pagexcontent = pathInfo[@"xcontent"]; - [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]; - XCTAssertEqualObjects(xpathForView, xpath); - XCTAssertEqualObjects(xcontentForView, xcontent); - XCTAssertEqualObjects(originxcontentForView, originxcontent); - }]; + [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]; + XCTAssertEqualObjects(xpathForView, xpath); + XCTAssertEqualObjects(xcontentForView, xcontent); + XCTAssertEqualObjects(originxcontentForView, originxcontent); + }]; } - (void)test01AlertButtonClick { @@ -59,26 +64,30 @@ - (void)test01AlertButtonClick { [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"ShowAlert"] tap]; [viewTester waitForAnimationsToFinish]; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"取消"]; - NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/" - @"_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfac" - @"eActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"; + NSString *xpathForView = + @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/" + @"_UIAlertControllerInterfaceActionGroupView/UIView/_UIInterfaceActionRepresentationsSequenceView/_UIInterfac" + @"eActionSeparatableSequenceView/UIStackView/_UIInterfaceActionCustomViewRepresentationView/Button"; NSString *xcontentForView = @"/0/1/0/0/0/0/0/0/0/1/0"; NSString *originxcontentForView = @"/0/1/0/0/0/0/0/0/0/1/0"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; + [self checkWebCirclePathWithView:actor.view + xpath:xpathForView + xcontent:xcontentForView + originxcontent:originxcontentForView]; [actor tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertGreaterThanOrEqual(events.count, 2); - + { GrowingViewElementEvent *event = (GrowingViewElementEvent *)events[events.count - 1]; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"取消"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); @@ -91,10 +100,12 @@ - (void)test01AlertButtonClick { XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"path"], @""); XCTAssertEqualObjects(dic[@"textValue"], @"ShowAlert"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GIOLabelAttributeViewController/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/3"); } } @@ -102,7 +113,7 @@ - (void)test01AlertButtonClick { - (void)test02ClickDoNotTrack { [[viewTester usingLabel:@"AttributeLabel"] tap]; [viewTester waitForAnimationsToFinish]; - + [MockEventQueue.sharedQueue cleanQueue]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"GIODontTrackBtn"]; { @@ -112,32 +123,32 @@ - (void)test02ClickDoNotTrack { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 0); } - + [MockEventQueue.sharedQueue cleanQueue]; - + { actor.view.growingViewIgnorePolicy = GrowingIgnoreNone; [actor tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); - + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); } - + [MockEventQueue.sharedQueue cleanQueue]; - + { [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:NO]; [actor tap]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 0); - + [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:YES]; } } @@ -146,25 +157,29 @@ - (void)test03ButtonWithImageViewClick { // 单击ButtonWithImageView,检测click事件 [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"Food"]; - NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; + NSString *xpathForView = + @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; NSString *xcontentForView = @"/0/1/0/0/0/0"; NSString *originxcontentForView = @"/0/1/0/0/0/0"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; + [self checkWebCirclePathWithView:actor.view + xpath:xpathForView + xcontent:xcontentForView + originxcontent:originxcontentForView]; [actor tap]; [[viewTester usingLabel:@"好的"] tap]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 3); - + { GrowingViewElementEvent *event = (GrowingViewElementEvent *)events[events.count - 2]; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"textValue"], @"Food"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); @@ -175,15 +190,19 @@ - (void)test04UIViewButtonClick { // 单击UIViewButton,检测click事件 [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"Fire"]; - NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; + NSString *xpathForView = + @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"; NSString *xcontentForView = @"/0/1/0/0/0/1"; NSString *originxcontentForView = @"/0/1/0/0/0/1"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; + [self checkWebCirclePathWithView:actor.view + xpath:xpathForView + xcontent:xcontentForView + originxcontent:originxcontentForView]; [actor tap]; [[viewTester usingLabel:@"好的"] tap]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 3); @@ -193,7 +212,7 @@ - (void)test04UIViewButtonClick { XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"textValue"], @"Fire"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); @@ -205,12 +224,17 @@ - (void)test05UISegmentedControlClick { [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"SecondSegment"] tap]; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"ThirdSegment"]; - NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UISegmentedControl/UISegment"; + NSString *xpathForView = + @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UISegmentedControl/" + @"UISegment"; NSString *xcontentForView = @"/0/1/0/0/0/-"; NSString *originxcontentForView = @"/0/1/0/0/0/2"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; + [self checkWebCirclePathWithView:actor.view + xpath:xpathForView + xcontent:xcontentForView + originxcontent:originxcontentForView]; [actor tap]; [viewTester waitForAnimationsToFinish]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -222,7 +246,7 @@ - (void)test05UISegmentedControlClick { XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"textValue"], @"Third"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); XCTAssertEqualObjects(dic[@"index"], @(2)); @@ -234,7 +258,7 @@ - (void)test06ClickCustomContent { // 单击自定义content的UISegmentedControl,检测textValue [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; - + [MockEventQueue.sharedQueue cleanQueue]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"Fire"]; @@ -245,18 +269,20 @@ - (void)test06ClickCustomContent { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); - + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"textValue"], @"Water"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GIOSimpleUIElemtsViewController/UIView/UIView/UIButton"); XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/0/1"); } - + [[viewTester usingLabel:@"好的"] tap]; } @@ -264,12 +290,17 @@ - (void)test07UITableViewHeaderFooterViewButtonClick { // 单击UITableViewHeaderFooterView上的Button,检测click事件 [[viewTester usingLabel:@"协议/接口"] tap]; [viewTester waitForAnimationsToFinish]; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"header1"]; - NSString *xpathForView = @"/UITabBarController/UINavigationController/GIOMeasurementProtocolTableViewController/UITableView/UITableViewHeaderFooterView/UIButton"; + NSString *xpathForView = + @"/UITabBarController/UINavigationController/GIOMeasurementProtocolTableViewController/UITableView/" + @"UITableViewHeaderFooterView/UIButton"; NSString *xcontentForView = @"/0/0/0/0/1/0"; NSString *originxcontentForView = @"/0/0/0/0/1/0"; - [self checkWebCirclePathWithView:actor.view xpath:xpathForView xcontent:xcontentForView originxcontent:originxcontentForView]; + [self checkWebCirclePathWithView:actor.view + xpath:xpathForView + xcontent:xcontentForView + originxcontent:originxcontentForView]; [actor tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; @@ -281,7 +312,7 @@ - (void)test07UITableViewHeaderFooterViewButtonClick { XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"textValue"], @"header1"); XCTAssertEqualObjects(dic[@"xpath"], xpathForView); XCTAssertEqualObjects(dic[@"xcontent"], xcontentForView); @@ -291,16 +322,16 @@ - (void)test07UITableViewHeaderFooterViewButtonClick { - (void)test08IgnoreViewClass { [[viewTester usingLabel:@"IgnoreViewClass"] tap]; [viewTester waitForAnimationsToFinish]; - + [[viewTester usingLabel:@"ignoreViewClass"] tap]; [viewTester waitForAnimationsToFinish]; - + [MockEventQueue.sharedQueue cleanQueue]; [[viewTester usingLabel:@"IgnoreButton1"] tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 0); - + [[viewTester usingLabel:@"IgnoreButton2"] tap]; [[viewTester usingLabel:@"IgnoreButton3"] tap]; [[viewTester usingLabel:@"NotIgnoreButton4"] tap]; @@ -311,19 +342,21 @@ - (void)test08IgnoreViewClass { XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"textValue"], @"IgnoreButton2"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingIgnoreButton2"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingIgnoreButton2"); XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/0"); } - (void)test09IgnoreViewClasses { [[viewTester usingLabel:@"IgnoreViewClass"] tap]; [viewTester waitForAnimationsToFinish]; - + [[viewTester usingLabel:@"ignoreViewClasses"] tap]; [viewTester waitForAnimationsToFinish]; - + [MockEventQueue.sharedQueue cleanQueue]; [[viewTester usingLabel:@"IgnoreButton1"] tap]; @@ -331,7 +364,7 @@ - (void)test09IgnoreViewClasses { [[viewTester usingLabel:@"IgnoreButton3"] tap]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 0); - + [[viewTester usingLabel:@"NotIgnoreButton4"] tap]; events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); @@ -340,9 +373,11 @@ - (void)test09IgnoreViewClasses { XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"textValue"], @"NotIgnoreButton4"); - XCTAssertEqualObjects(dic[@"xpath"], @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingNotIgnoreButton4"); + XCTAssertEqualObjects( + dic[@"xpath"], + @"/UITabBarController/UINavigationController/GrowingIgnoreViewViewController/UIView/GrowingNotIgnoreButton4"); XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/0"); } diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m index adf0042a5..5edaf3d11 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m @@ -9,9 +9,9 @@ #import #import "GrowingAutotracker.h" -#import "MockEventQueue.h" -#import "ManualTrackHelper.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" +#import "ManualTrackHelper.h" +#import "MockEventQueue.h" @interface A2ViewChangeEventsTest : KIFTestCase @@ -37,16 +37,16 @@ - (void)test01TextFields { [[viewTester usingLabel:@"fisrtTF"] tap]; [[viewTester usingFirstResponder] enterText:@"Good"]; [[viewTester usingFirstResponder].view resignFirstResponder]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 1); - + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewChange); XCTAssertTrue([ManualTrackHelper viewChangeEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + [[viewTester usingLabel:@"UI界面"] tap]; } @@ -54,7 +54,7 @@ - (void)test02TextFieldsIgnore { [[viewTester usingLabel:@"UI界面"] tap]; [[viewTester usingLabel:@"Text Fields"] tap]; [viewTester waitForAnimationsToFinish]; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"fisrtTF"]; { actor.view.growingViewIgnorePolicy = GrowingIgnoreSelf; @@ -65,7 +65,7 @@ - (void)test02TextFieldsIgnore { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 0); } - + { actor.view.growingViewIgnorePolicy = GrowingIgnoreNone; [actor tap]; @@ -74,7 +74,7 @@ - (void)test02TextFieldsIgnore { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 1); - + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewChange); @@ -90,14 +90,14 @@ - (void)test03DataPicker { [[viewTester usingLabel:@"VIEW_CHANGE请求"] tap]; [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"dataPickerOper"] tap]; - + NSArray *date = @[@"June", @"10", @"2019"]; [viewTester selectDatePickerValue:date]; [viewTester tapScreenAtPoint:CGPointMake(100, 100)]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 0); - + [[viewTester usingLabel:@"协议/接口"] tap]; } @@ -105,7 +105,7 @@ - (void)test04Slider { [[viewTester usingLabel:@"UI界面"] tap]; [[viewTester usingLabel:@"Simple UI Elements"] tap]; [viewTester waitForAnimationsToFinish]; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"defaultSlider"]; { actor.view.growingViewIgnorePolicy = GrowingIgnoreSelf; @@ -114,14 +114,14 @@ - (void)test04Slider { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 0); } - + { actor.view.growingViewIgnorePolicy = GrowingIgnoreNone; [actor setSliderValue:50.0f]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 1); - + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewChange); diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m index 23b234ee4..2c3c42cb6 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m @@ -20,17 +20,17 @@ #import #import #import "GrowingAutotracker.h" -#import "MockEventQueue.h" -#import "GrowingTrackerCore/Event/GrowingTrackEventType.h" -#import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" #import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" +#import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" +#import "GrowingTrackerCore/Event/GrowingTrackEventType.h" +#import "GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h" +#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" +#import "ManualTrackHelper.h" +#import "MockEventQueue.h" +#import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" #import "Modules/Hybrid/Events/GrowingHybridEventType.h" -#import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" #import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" -#import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" -#import "ManualTrackHelper.h" -#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" -#import "GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h" +#import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" #import "Modules/Hybrid/GrowingHybridBridgeProvider.h" #import "Modules/Hybrid/GrowingWebViewDomChangedDelegate.h" @@ -45,7 +45,7 @@ - (void)beforeAll { [GrowingAutotracker.sharedInstance setLoginUserId:@"xctest_userId" userKey:@"xctest_userKey"]; // latitude longitude [GrowingAutotracker.sharedInstance setLocation:30.12345 longitude:31.123456]; - + [[viewTester usingLabel:@"UI界面"] tap]; [[viewTester usingLabel:@"Hybrid"] tap]; [viewTester waitForTimeInterval:10]; @@ -70,13 +70,13 @@ - (void)test02SendMockCustomEvent { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingHybridCustomEvent *event = (GrowingHybridCustomEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeCustom); XCTAssertTrue([ManualTrackHelper customEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); @@ -90,13 +90,13 @@ - (void)test03SendMockCustomEventWithAttributes { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingHybridCustomEvent *event = (GrowingHybridCustomEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeCustom); XCTAssertTrue([ManualTrackHelper customEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); XCTAssertEqualObjects(dic[@"query"], @"a=1&b=2"); @@ -110,13 +110,13 @@ - (void)test04SendMockLoginUserAttributesEvent { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; XCTAssertEqual(events.count, 1); - + GrowingLoginUserAttributesEvent *event = (GrowingLoginUserAttributesEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeLoginUserAttributes); XCTAssertTrue([ManualTrackHelper loginUserAttributesEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"attributes"][@"key1"], @"value1"); XCTAssertEqualObjects(dic[@"attributes"][@"key2"], @"value2"); } @@ -128,13 +128,13 @@ - (void)test06SendMockPageEvent { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); - + GrowingHybridPageEvent *event = (GrowingHybridPageEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); XCTAssertEqualObjects(dic[@"title"], @"Hybrid测试页面"); @@ -147,13 +147,13 @@ - (void)test07SendMockPageEventWithQuery { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); - + GrowingHybridPageEvent *event = (GrowingHybridPageEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); XCTAssertEqualObjects(dic[@"title"], @"Hybrid测试页面"); @@ -167,13 +167,13 @@ - (void)test08SendMockPageEventWithAttributes { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); - + GrowingHybridPageEvent *event = (GrowingHybridPageEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); XCTAssertEqualObjects(dic[@"title"], @"Hybrid测试页面"); @@ -189,13 +189,13 @@ - (void)test09SendMockViewClickEvent { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); - + GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); XCTAssertEqualObjects(dic[@"xpath"], @"/div/button"); @@ -211,13 +211,13 @@ - (void)test10SendMockViewChangeEvent { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 1); - + GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)events.firstObject; NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewChange); XCTAssertTrue([ManualTrackHelper viewChangeEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - + XCTAssertEqualObjects(dic[@"domain"], @"test-browser.growingio.com"); XCTAssertEqualObjects(dic[@"path"], @"/push/web.html"); XCTAssertEqualObjects(dic[@"xpath"], @"/div/form/input"); @@ -250,47 +250,59 @@ - (void)test12MockSetUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockSetUserId('xctest_userId_hybrid')"]; [viewTester waitForTimeInterval:1]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @"xctest_userId_hybrid"); - } waitUntilDone:YES]; + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], + @"xctest_userId_hybrid"); + } + waitUntilDone:YES]; } - (void)test13MockClearUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockClearUserId()"]; [viewTester waitForTimeInterval:1]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @""); - } waitUntilDone:YES]; + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @""); + } + waitUntilDone:YES]; } - (void)test14MockSetUserIdAndUserKey { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; - [self webView:actor.view evaluateJavaScript:@"mockSetUserIdAndUserKey('xctest_userId_hybrid2', 'xctest_userKey_hybrid2')"]; + [self webView:actor.view + evaluateJavaScript:@"mockSetUserIdAndUserKey('xctest_userId_hybrid2', 'xctest_userKey_hybrid2')"]; [viewTester waitForTimeInterval:1]; - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @"xctest_userId_hybrid2"); - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], @"xctest_userKey_hybrid2"); - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], + @"xctest_userId_hybrid2"); + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], + @"xctest_userKey_hybrid2"); + } + waitUntilDone:YES]; } - (void)test15MockClearUserIdAndUserKey { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockClearUserIdAndUserKey()"]; [viewTester waitForTimeInterval:1]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @""); - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], @""); - } waitUntilDone:YES]; + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @""); + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], @""); + } + waitUntilDone:YES]; } static int XCTest_didDomChanged = 0; - (void)test16MockDomChanged { [GrowingHybridBridgeProvider sharedInstance].domChangedDelegate = self; - + KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockDomChanged()"]; [viewTester waitForTimeInterval:1]; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/OtherTests/GrowingKeyChainTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/OtherTests/GrowingKeyChainTest.m index eb7877d25..cb33da402 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/OtherTests/GrowingKeyChainTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/OtherTests/GrowingKeyChainTest.m @@ -40,7 +40,7 @@ - (void)testGrowingKeyChainWrapper { NSString *obj = [GrowingKeyChainWrapper keyChainObjectForKey:@"KeyChainTestKey"]; XCTAssertTrue([obj isEqualToString:@"KeyChainTest"]); - + #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" [GrowingKeyChainWrapper performSelector:@selector(removeKeyChainObjectForKey:) withObject:@"KeyChainTestKey"]; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/AdvertTests/AdvertTest.m b/Example/GrowingAnalyticsTests/ModulesTests/AdvertTests/AdvertTest.m index 6d78378ea..692e4a687 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/AdvertTests/AdvertTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/AdvertTests/AdvertTest.m @@ -17,11 +17,10 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingAutotracker.h" #import "GrowingAdvertising.h" +#import "GrowingAutotracker.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" @@ -41,7 +40,6 @@ - (void)setUp { } - (void)tearDown { - } - (void)test00SendActivateEvent { @@ -49,7 +47,7 @@ - (void)test00SendActivateEvent { configuration.dataSourceId = @"test"; configuration.urlScheme = @"growing.530c8231345c492d"; [GrowingAutotracker startWithConfiguration:configuration launchOptions:nil]; - + XCTestExpectation *expectation = [self expectationWithDescription:@"SendActivateEvent Test failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // 给 webView 一点时间 @@ -65,11 +63,12 @@ - (void)test01SetDataCollectionEnabled { // 恢复为未发送激活事件 [GrowingAdUtils setActivateWrote:NO]; [GrowingAdUtils setActivateSent:NO]; - + [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:NO]; [[GrowingAutotracker sharedInstance] setDataCollectionEnabled:YES]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"SetDataCollectionEnabled Test failed : timeout"]; + + XCTestExpectation *expectation = + [self expectationWithDescription:@"SetDataCollectionEnabled Test failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // 给 webView 一点时间 NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeActivate]; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m index b6699dc74..9b9e99e46 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridEventTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" @@ -39,11 +38,13 @@ - (void)tearDown { } - (void)testGrowingHybridCustomEvent { - GrowingHybridCustomEvent *event = (GrowingHybridCustomEvent *)GrowingHybridCustomEvent.builder.setPath(@"/hybrid/test") - .setQuery(@"testquery") - .setEventName(@"testEventName") - .setAttributes(@{@"test":@"value"}).build; - + GrowingHybridCustomEvent *event = + (GrowingHybridCustomEvent *)GrowingHybridCustomEvent.builder.setPath(@"/hybrid/test") + .setQuery(@"testquery") + .setEventName(@"testEventName") + .setAttributes(@{@"test": @"value"}) + .build; + XCTAssertEqual(event.path, @"/hybrid/test"); XCTAssertEqual(event.query, @"testquery"); XCTAssertEqual(event.eventName, @"testEventName"); @@ -52,22 +53,22 @@ - (void)testGrowingHybridCustomEvent { } - (void)testGrowingHybridPageEvent { - GrowingHybridPageEvent *event = (GrowingHybridPageEvent *)GrowingHybridPageEvent.builder - .setQuery(@"testquery") - .setProtocolType(@"testProtocol") - .setAttributes(@{@"test":@"value"}).build; - + GrowingHybridPageEvent *event = (GrowingHybridPageEvent *)GrowingHybridPageEvent.builder.setQuery(@"testquery") + .setProtocolType(@"testProtocol") + .setAttributes(@{@"test": @"value"}) + .build; + XCTAssertEqual(event.query, @"testquery"); XCTAssertEqual(event.protocolType, @"testProtocol"); XCTAssertEqualObjects(event.attributes[@"test"], @"value"); } - (void)testGrowingPageCustomEvent { - GrowingPageCustomEvent *event = (GrowingPageCustomEvent *)GrowingPageCustomEvent.builder - .setPath(@"path") - .setEventName(@"testEventName") - .setAttributes(@{@"test":@"value"}).build; - + GrowingPageCustomEvent *event = (GrowingPageCustomEvent *)GrowingPageCustomEvent.builder.setPath(@"path") + .setEventName(@"testEventName") + .setAttributes(@{@"test": @"value"}) + .build; + XCTAssertEqualObjects(event.path, @"path"); XCTAssertEqualObjects(event.eventName, @"testEventName"); NSString *value = (NSString *)event.attributes[@"test"]; @@ -75,10 +76,11 @@ - (void)testGrowingPageCustomEvent { } - (void)testGrowingHybridViewElementEvent { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)GrowingHybridViewElementEvent.builder - .setHyperlink(@"testHyperlink") - .setQuery(@"testquery").build; - + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent *)GrowingHybridViewElementEvent.builder.setHyperlink(@"testHyperlink") + .setQuery(@"testquery") + .build; + XCTAssertEqual(event.query, @"testquery"); XCTAssertEqual(event.hyperlink, @"testHyperlink"); } diff --git a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m index 6e80af6d3..561372c97 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/HybridTests/HybridTest.m @@ -17,20 +17,19 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import -#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" -#import "Modules/Hybrid/GrowingHybridBridgeProvider.h" +#import "GrowingEventDatabaseService.h" +#import "GrowingServiceManager.h" +#import "GrowingTrackerCore/Event/GrowingEventGenerator.h" #import "GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h" -#import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Event/GrowingEventGenerator.h" -#import "GrowingServiceManager.h" -#import "GrowingEventDatabaseService.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" +#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" +#import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" +#import "Modules/Hybrid/GrowingHybridBridgeProvider.h" #import "Services/Protobuf/GrowingEventProtobufDatabase.h" @interface GrowingHybridBridgeProvider (XCTest) @@ -53,7 +52,7 @@ @implementation HybridTest - (void)setUp { self.provider = GrowingHybridBridgeProvider.sharedInstance; - + [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) implClass:GrowingEventProtobufDatabase.class]; [GrowingSession startSession]; @@ -67,7 +66,7 @@ - (void)testGrowingHybridBridgeProvider { GrowingBaseBuilder *builder = GrowingHybridPageEvent.builder.setQuery(@"QUERY") .setPath(@"KEY_PATH") - .setAttributes(@{@"test" : @"value"}) + .setAttributes(@{@"test": @"value"}) .setDomain(@"domain") .setUserId(@"testUserId") .setPlatform(@"testPlatform") @@ -82,9 +81,10 @@ - (void)testGrowingHybridBridgeProvider { [self.provider handleJavascriptBridgeMessage:@"{@'messageType':@'messagedata'}"]; [self.provider dispatchWebViewDomChanged]; WKWebView *_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; - [self.provider getDomTreeForWebView:_webView completionHandler:^(NSDictionary *_Nullable dom, NSError *_Nullable error) { - NSLog(@"test"); - }]; + [self.provider getDomTreeForWebView:_webView + completionHandler:^(NSDictionary *_Nullable dom, NSError *_Nullable error) { + NSLog(@"test"); + }]; NSString *jsonString = @"{\"messageType\":\"dispatchEvent\",\"data\":\"{\"eventType\":\"PAGE\",\"protocolType\":\"http\",\"deviceId\":" @"\"4a6e5b29-3a32-42f6-abc0-5bf81beecff9\",\"sessionId\":\"485de03a-7188-49a3-bae2-d915bf17847d\"," @@ -93,7 +93,7 @@ - (void)testGrowingHybridBridgeProvider { @"uat.html\",\"platform\":\"web\",\"screenHeight\":844,\"screenWidth\":390,\"sdkVersion\":\"3.3.0\"," @"\"language\":\"en-us\",\"title\":\"SDKAutoCheck\",\"globalSequenceId\":2,\"eventSequenceId\":1}\"}"; [self.provider parseEventJsonString:jsonString]; - + NSDictionary *dict = (NSDictionary *)[jsonString growingHelper_jsonObject]; builder = [self.provider transformViewElementBuilder:dict]; XCTAssertNotNil(builder); @@ -104,21 +104,25 @@ - (void)testSetNativeUserIdAndUserKey { @"{\"messageType\":\"setNativeUserIdAndUserKey\",\"data\":\"{\\\"userId\\\":\\\"zhangsan2\\\",\\\"userKey\\\":" @"\\\"邮箱\\\"}\"}"; [self.provider handleJavascriptBridgeMessage:dict]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @"zhangsan2"); - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], @"邮箱"); - } waitUntilDone:YES]; + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @"zhangsan2"); + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], @"邮箱"); + } + waitUntilDone:YES]; } - (void)testClearNativeUserIdAndUserKey { - NSDictionary *dict = @{@"messageType" : @"clearNativeUserIdAndUserKey", @"data" : @""}; + NSDictionary *dict = @{@"messageType": @"clearNativeUserIdAndUserKey", @"data": @""}; [self.provider handleJavascriptBridgeMessage:[dict growingHelper_jsonString]]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @""); - XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], @""); - } waitUntilDone:YES]; + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @""); + XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserKey], @""); + } + waitUntilDone:YES]; } @end diff --git a/Example/GrowingAnalyticsTests/ModulesTests/MobileDebuggerTests/MobileDebuggerTest.m b/Example/GrowingAnalyticsTests/ModulesTests/MobileDebuggerTests/MobileDebuggerTest.m index 1af86334f..eee7cef88 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/MobileDebuggerTests/MobileDebuggerTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/MobileDebuggerTests/MobileDebuggerTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingAutotrackConfiguration.h" @@ -71,16 +70,16 @@ - (void)growingApplicationEventSendEvent:(UIEvent *)event; #pragma mark - websocket delegate -- (void)webSocketDidOpen:(id )webSocket; +- (void)webSocketDidOpen:(id)webSocket; -- (void)webSocket:(id )webSocket didReceiveMessage:(id)message; +- (void)webSocket:(id)webSocket didReceiveMessage:(id)message; -- (void)webSocket:(id )webSocket - didCloseWithCode:(NSInteger)code - reason:(NSString *)reason - wasClean:(BOOL)wasClean; +- (void)webSocket:(id)webSocket + didCloseWithCode:(NSInteger)code + reason:(NSString *)reason + wasClean:(BOOL)wasClean; -- (void)webSocket:(id )webSocket didFailWithError:(NSError *)error; +- (void)webSocket:(id)webSocket didFailWithError:(NSError *)error; @end @@ -101,8 +100,8 @@ - (void)tearDown { - (void)testGrowingMobileDebugger { NSURL *url = [NSURL URLWithString: - @"growing.3612b67ce562c755://growingio/webservice?serviceType=debugger&wsUrl=wss://" - @"gta0.growingio.com/app/0wDaZmQ1/circle/ec7f5925458f458b8ae6f3901cacaa92"]; + @"growing.3612b67ce562c755://growingio/webservice?serviceType=debugger&wsUrl=wss://" + @"gta0.growingio.com/app/0wDaZmQ1/circle/ec7f5925458f458b8ae6f3901cacaa92"]; GrowingMobileDebugger *mobileDebugger = [[GrowingMobileDebugger alloc] init]; [mobileDebugger start]; [mobileDebugger stop]; diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m index 349bc3a98..c38b5f19a 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufDatabaseTest.m @@ -17,12 +17,11 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "Services/Protobuf/GrowingEventProtobufPersistence.h" -#import "Services/Protobuf/GrowingEventProtobufDatabase.h" -#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" +#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" #import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" @interface ProtobufDatabaseTest : XCTestCase @@ -38,9 +37,9 @@ - (void)setUp { NSString *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).firstObject; NSURL *pathURL = [NSURL fileURLWithPath:path]; NSString *dirName = [NSString stringWithFormat:@"%@/%@%@", - @"com.growingio.core" /* kGrowingResidentDirName */, - @"com.growingio." /* kGrowingDirCommonPrefix */, - @"event/XCTest.sqlite"]; + @"com.growingio.core" /* kGrowingResidentDirName */, + @"com.growingio." /* kGrowingDirCommonPrefix */, + @"event/XCTest.sqlite"]; self.path = [pathURL URLByAppendingPathComponent:dirName].path; } @@ -65,19 +64,19 @@ - (void)testDatabaseInstanceMethods { // clean expired event if need XCTAssertEqual(database.cleanExpiredEventIfNeeded, YES); - + // clear all events XCTAssertEqual(database.clearAllEvents, YES); - + NSInteger count = database.countOfEvents; - + // insert single event GrowingEventProtobufPersistence *event = self.customEventPersistence; XCTAssertEqual([database insertEvent:event], YES); - + NSInteger count2 = database.countOfEvents; XCTAssertNotEqual(count, count2); - + // delete single event XCTAssertEqual([database deleteEvent:event.eventUUID], YES); @@ -85,30 +84,28 @@ - (void)testDatabaseInstanceMethods { NSMutableArray *keys = [NSMutableArray array]; NSInteger insertCount = 3; for (int i = 0; i < insertCount; i++) { - GrowingEventProtobufPersistence *e = self.visitEventPersistence; // GrowingEventSendPolicyInstant + GrowingEventProtobufPersistence *e = self.visitEventPersistence; // GrowingEventSendPolicyInstant [events addObject:e]; [keys addObject:e.eventUUID]; } // clear all events XCTAssertEqual(database.clearAllEvents, YES); - + // insert events XCTAssertEqual([database insertEvents:events], YES); - - NSArray *array = [database getEventsByCount:insertCount]; - XCTAssertEqual(array.count, insertCount); NSArray *array2 = [database getEventsByCount:insertCount policy:GrowingEventSendPolicyInstant]; XCTAssertEqual(array2.count, insertCount); // delete events XCTAssertEqual([database deleteEvents:keys], YES); - + // last error NSString *errorPath = @"errorPath"; NSError *error = nil; - GrowingEventProtobufDatabase *errorDatabase = [GrowingEventProtobufDatabase databaseWithPath:errorPath error:&error]; + GrowingEventProtobufDatabase *errorDatabase = [GrowingEventProtobufDatabase databaseWithPath:errorPath + error:&error]; if (error) { // 这里使用一个错误/无权限路径来实现 Database 初始化异常 // 使用模拟器运行,实测不会因错误/无权限路径导致初始化异常,error 为 nil,不会进到这一步 @@ -122,43 +119,45 @@ - (void)testDatabaseEventIO { // clear all events XCTAssertEqual(database.clearAllEvents, YES); - - GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder - .setEventName(@"custom") - .setAttributes(@{@"key" : @"value"}) - .setPlatform(@"platform") - .setPlatformVersion(@"20") - .setDeviceId([NSUUID UUID].UUIDString) - .setUserId(@"userId") - .setSessionId([NSUUID UUID].UUIDString) - .setTimestamp(1638857558209) - .setDomain(@"com.bundle.id") - .setUrlScheme(@"growing.xxxxxx") - .setAppState(GrowingAppStateForeground) - .setEventSequenceId(999) - .setNetworkState(@"5G") - .setScreenHeight(1334) - .setScreenWidth(750) - .setDeviceBrand(@"device brand") - .setDeviceModel(@"device model") - .setDeviceType(@"device type") - .setAppVersion(@"3.0.0") - .setAppName(@"Example") - .setLanguage(@"zh-Hans-CN") - .setLatitude(30.11) - .setLongitude(32.22) - .setSdkVersion(@"3.3.3") - .setUserKey(@"iPhone") - .setDataSourceId(@"1234567890") - .build); + + GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder.setEventName(@"custom") + .setAttributes(@{@"key": @"value"}) + .setPlatform(@"platform") + .setPlatformVersion(@"20") + .setDeviceId([NSUUID UUID].UUIDString) + .setUserId(@"userId") + .setSessionId([NSUUID UUID].UUIDString) + .setTimestamp(1638857558209) + .setDomain(@"com.bundle.id") + .setUrlScheme(@"growing.xxxxxx") + .setAppState(GrowingAppStateForeground) + .setEventSequenceId(999) + .setNetworkState(@"5G") + .setScreenHeight(1334) + .setScreenWidth(750) + .setDeviceBrand(@"device brand") + .setDeviceModel(@"device model") + .setDeviceType(@"device type") + .setAppVersion(@"3.0.0") + .setAppName(@"Example") + .setLanguage(@"zh-Hans-CN") + .setLatitude(30.11) + .setLongitude(32.22) + .setSdkVersion(@"3.3.3") + .setUserKey(@"iPhone") + .setDataSourceId(@"1234567890") + .build); NSString *uuid = [NSUUID UUID].UUIDString; GrowingEventProtobufPersistence *persistenceIn = [GrowingEventProtobufPersistence persistenceEventWithEvent:event uuid:uuid]; // insert XCTAssertEqual([database insertEvent:persistenceIn], YES); - + NSInteger insertCount = 1; - NSArray *array = [database getEventsByCount:5]; // 避免多线程情况下,刚好还有其他事件产生入库,这里数值设定大一点 + NSArray *array = [database + getEventsByCount:5 + policy:GrowingEventSendPolicyInstant | GrowingEventSendPolicyMobileData | + GrowingEventSendPolicyWiFi]; // 避免多线程情况下,刚好还有其他事件产生入库,这里数值设定大一点 XCTAssertGreaterThanOrEqual(array.count, insertCount); GrowingEventProtobufPersistence *persistenceOut; @@ -179,7 +178,8 @@ - (void)testDatabaseEventIO { XCTAssertEqual(event.timestamp, protobuf.timestamp); XCTAssertEqualObjects(event.domain ?: @"", protobuf.domain); XCTAssertEqualObjects(event.urlScheme ?: @"", protobuf.URLScheme); - XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), protobuf.appState); + XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), + protobuf.appState); XCTAssertEqual(event.eventSequenceId, protobuf.eventSequenceId); // 3.2.0 XCTAssertEqualObjects(event.networkState ?: @"", protobuf.networkState); @@ -207,14 +207,12 @@ - (void)testDatabaseEventIO { - (GrowingEventProtobufPersistence *)customEventPersistence { GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder.build); - return [GrowingEventProtobufPersistence persistenceEventWithEvent:event - uuid:[NSUUID UUID].UUIDString]; + return [GrowingEventProtobufPersistence persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; } - (GrowingEventProtobufPersistence *)visitEventPersistence { GrowingVisitEvent *event = (GrowingVisitEvent *)(GrowingVisitEvent.builder.build); - return [GrowingEventProtobufPersistence persistenceEventWithEvent:event - uuid:[NSUUID UUID].UUIDString]; + return [GrowingEventProtobufPersistence persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; } @end diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m index 3fe3f05da..196eea464 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m @@ -17,23 +17,22 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "Services/Protobuf/GrowingEventProtobufPersistence.h" -#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" -#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" -#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h" -#import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" -#import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" -#import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" -#import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" -#import "GrowingTrackerCore/Event/GrowingAppCloseEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" -#import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" -#import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" +#import "GrowingTrackerCore/Event/GrowingAppCloseEvent.h" +#import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" +#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" +#import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" +#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" +#import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" +#import "Modules/Hybrid/Events/GrowingHybridCustomEvent.h" #import "Modules/Hybrid/Events/GrowingHybridEventType.h" +#import "Modules/Hybrid/Events/GrowingHybridPageEvent.h" +#import "Modules/Hybrid/Events/GrowingHybridViewElementEvent.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" @interface ProtobufEventsTest : XCTestCase @@ -52,11 +51,9 @@ - (void)tearDown { - (void)testEventConvertToPB_Visit { // GrowingVisitEvent { - GrowingVisitEvent *event = (GrowingVisitEvent *)(GrowingVisitEvent.builder - .setIdfa(@"idfa") - .setIdfv(@"idfv") - .setExtraSdk(@{@"key": @"value"}) - .build); + GrowingVisitEvent *event = + (GrowingVisitEvent + *)(GrowingVisitEvent.builder.setIdfa(@"idfa").setIdfv(@"idfv").setExtraSdk(@{@"key": @"value"}).build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeVisit, event.eventType); @@ -75,16 +72,16 @@ - (void)testEventConvertToPB_Visit { XCTAssertEqualObjects(event.idfv ?: @"", protobuf.idfv); XCTAssertEqualObjects(event.extraSdk ?: @{}, protobuf.extraSdk); } - + // GrowingHybridViewElementEvent - Useless { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeVisit) - .setPath(@"path") - .setXpath(@"xpath") - .setIndex(1) - .setQuery(@"query") - .build); + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder.setEventType(GrowingEventTypeVisit) + .setPath(@"path") + .setXpath(@"xpath") + .setIndex(1) + .setQuery(@"query") + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeVisit, event.eventType); @@ -99,10 +96,9 @@ - (void)testEventConvertToPB_Visit { - (void)testEventConvertToPB_Custom { // GrowingCustomEvent { - GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder - .setEventName(@"custom") - .setAttributes(@{@"key": @"value"}) - .build); + GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder.setEventName(@"custom") + .setAttributes(@{@"key": @"value"}) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeCustom, event.eventType); @@ -122,11 +118,11 @@ - (void)testEventConvertToPB_Custom { // GrowingPageCustomEvent { - GrowingPageCustomEvent *event = (GrowingPageCustomEvent *)(GrowingPageCustomEvent.builder - .setEventName(@"custom") - .setPath(@"path") - .setAttributes(@{@"key": @"value"}) - .build); + GrowingPageCustomEvent *event = + (GrowingPageCustomEvent *)(GrowingPageCustomEvent.builder.setEventName(@"custom") + .setPath(@"path") + .setAttributes(@{@"key": @"value"}) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeCustom, event.eventType); @@ -148,12 +144,12 @@ - (void)testEventConvertToPB_Custom { // GrowingHybridCustomEvent { - GrowingHybridCustomEvent *event = (GrowingHybridCustomEvent *)(GrowingHybridCustomEvent.builder - .setEventName(@"custom") - .setPath(@"path") - .setAttributes(@{@"key": @"value"}) - .setQuery(@"query") - .build); + GrowingHybridCustomEvent *event = + (GrowingHybridCustomEvent *)(GrowingHybridCustomEvent.builder.setEventName(@"custom") + .setPath(@"path") + .setAttributes(@{@"key": @"value"}) + .setQuery(@"query") + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeCustom, event.eventType); @@ -179,9 +175,9 @@ - (void)testEventConvertToPB_Custom { - (void)testEventConvertToPB_VisitorAttributes { // GrowingVisitorAttributesEvent { - GrowingVisitorAttributesEvent *event = (GrowingVisitorAttributesEvent *)(GrowingVisitorAttributesEvent.builder - .setAttributes(@{@"key": @"value"}) - .build); + GrowingVisitorAttributesEvent *event = + (GrowingVisitorAttributesEvent *)(GrowingVisitorAttributesEvent.builder.setAttributes(@{@"key": @"value"}) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeVisitorAttributes, event.eventType); @@ -189,7 +185,8 @@ - (void)testEventConvertToPB_VisitorAttributes { XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); } { - GrowingVisitorAttributesEvent *event = (GrowingVisitorAttributesEvent *)(GrowingVisitorAttributesEvent.builder.build); + GrowingVisitorAttributesEvent *event = + (GrowingVisitorAttributesEvent *)(GrowingVisitorAttributesEvent.builder.build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeVisitorAttributes, event.eventType); @@ -201,9 +198,9 @@ - (void)testEventConvertToPB_VisitorAttributes { - (void)testEventConvertToPB_LoginUserAttributes { // GrowingLoginUserAttributesEvent { - GrowingLoginUserAttributesEvent *event = (GrowingLoginUserAttributesEvent *)(GrowingLoginUserAttributesEvent.builder - .setAttributes(@{@"key": @"value"}) - .build); + GrowingLoginUserAttributesEvent *event = + (GrowingLoginUserAttributesEvent + *)(GrowingLoginUserAttributesEvent.builder.setAttributes(@{@"key": @"value"}).build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeLoginUserAttributes, event.eventType); @@ -211,7 +208,8 @@ - (void)testEventConvertToPB_LoginUserAttributes { XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); } { - GrowingLoginUserAttributesEvent *event = (GrowingLoginUserAttributesEvent *)(GrowingLoginUserAttributesEvent.builder.build); + GrowingLoginUserAttributesEvent *event = + (GrowingLoginUserAttributesEvent *)(GrowingLoginUserAttributesEvent.builder.build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeLoginUserAttributes, event.eventType); @@ -223,9 +221,9 @@ - (void)testEventConvertToPB_LoginUserAttributes { - (void)testEventConvertToPB_ConversionVariable { // GrowingConversionVariableEvent { - GrowingConversionVariableEvent *event = (GrowingConversionVariableEvent *)(GrowingConversionVariableEvent.builder - .setAttributes(@{@"key": @"value"}) - .build); + GrowingConversionVariableEvent *event = + (GrowingConversionVariableEvent *)(GrowingConversionVariableEvent.builder.setAttributes(@{@"key": @"value"}) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeConversionVariables, event.eventType); @@ -233,7 +231,8 @@ - (void)testEventConvertToPB_ConversionVariable { XCTAssertEqualObjects(event.attributes ?: @{}, protobuf.attributes); } { - GrowingConversionVariableEvent *event = (GrowingConversionVariableEvent *)(GrowingConversionVariableEvent.builder.build); + GrowingConversionVariableEvent *event = + (GrowingConversionVariableEvent *)(GrowingConversionVariableEvent.builder.build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeConversionVariables, event.eventType); @@ -256,13 +255,12 @@ - (void)testEventConvertToPB_AppClose { - (void)testEventConvertToPB_Page { // GrowingPageEvent { - GrowingPageEvent *event = (GrowingPageEvent *)(GrowingPageEvent.builder - .setPath(@"path") - .setOrientation(@"PORTRAIT") - .setTitle(@"title") - .setReferralPage(@"referralPage") - .setAttributes(@{@"key" : @"value"}) - .build); + GrowingPageEvent *event = (GrowingPageEvent *)(GrowingPageEvent.builder.setPath(@"path") + .setOrientation(@"PORTRAIT") + .setTitle(@"title") + .setReferralPage(@"referralPage") + .setAttributes(@{@"key": @"value"}) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypePage, event.eventType); @@ -288,15 +286,14 @@ - (void)testEventConvertToPB_Page { // GrowingHybridPageEvent { - GrowingHybridPageEvent *event = (GrowingHybridPageEvent *)(GrowingHybridPageEvent.builder - .setPath(@"path") - .setOrientation(@"PORTRAIT") - .setTitle(@"title") - .setReferralPage(@"referralPage") - .setQuery(@"query") - .setProtocolType(@"https") - .setAttributes(@{@"key" : @"value"}) - .build); + GrowingHybridPageEvent *event = (GrowingHybridPageEvent *)(GrowingHybridPageEvent.builder.setPath(@"path") + .setOrientation(@"PORTRAIT") + .setTitle(@"title") + .setReferralPage(@"referralPage") + .setQuery(@"query") + .setProtocolType(@"https") + .setAttributes(@{@"key": @"value"}) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypePage, event.eventType); @@ -328,13 +325,13 @@ - (void)testEventConvertToPB_Page { - (void)testEventConvertToPB_ViewClick { // GrowingViewElementEvent { - GrowingViewElementEvent *event = (GrowingViewElementEvent *)(GrowingViewElementEvent.builder - .setEventType(GrowingEventTypeViewClick) - .setPath(@"path") - .setTextValue(@"textvalue") - .setXpath(@"xpath") - .setIndex(1) - .build); + GrowingViewElementEvent *event = + (GrowingViewElementEvent *)(GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick) + .setPath(@"path") + .setTextValue(@"textvalue") + .setXpath(@"xpath") + .setIndex(1) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); @@ -345,9 +342,8 @@ - (void)testEventConvertToPB_ViewClick { XCTAssertEqual(event.index, protobuf.index); } { - GrowingViewElementEvent *event = (GrowingViewElementEvent *)(GrowingViewElementEvent.builder - .setEventType(GrowingEventTypeViewClick) - .build); + GrowingViewElementEvent *event = + (GrowingViewElementEvent *)(GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewClick).build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); @@ -360,15 +356,16 @@ - (void)testEventConvertToPB_ViewClick { // GrowingHybridViewElementEvent { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeViewClick) - .setPath(@"path") - .setTextValue(@"textvalue") - .setXpath(@"xpath") - .setIndex(1) - .setHyperlink(@"hyperlink") - .setQuery(@"query") - .build); + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder + .setEventType(GrowingEventTypeViewClick) + .setPath(@"path") + .setTextValue(@"textvalue") + .setXpath(@"xpath") + .setIndex(1) + .setHyperlink(@"hyperlink") + .setQuery(@"query") + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); @@ -381,9 +378,9 @@ - (void)testEventConvertToPB_ViewClick { XCTAssertEqualObjects(event.query ?: @"", protobuf.query); } { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeViewClick) - .build); + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent + *)(GrowingHybridViewElementEvent.builder.setEventType(GrowingEventTypeViewClick).build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewClick, event.eventType); @@ -400,13 +397,13 @@ - (void)testEventConvertToPB_ViewClick { - (void)testEventConvertToPB_ViewChange { // GrowingViewElementEvent { - GrowingViewElementEvent *event = (GrowingViewElementEvent *)(GrowingViewElementEvent.builder - .setEventType(GrowingEventTypeViewChange) - .setPath(@"path") - .setTextValue(@"textvalue") - .setXpath(@"xpath") - .setIndex(1) - .build); + GrowingViewElementEvent *event = + (GrowingViewElementEvent *)(GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange) + .setPath(@"path") + .setTextValue(@"textvalue") + .setXpath(@"xpath") + .setIndex(1) + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); @@ -417,9 +414,8 @@ - (void)testEventConvertToPB_ViewChange { XCTAssertEqual(event.index, protobuf.index); } { - GrowingViewElementEvent *event = (GrowingViewElementEvent *)(GrowingViewElementEvent.builder - .setEventType(GrowingEventTypeViewChange) - .build); + GrowingViewElementEvent *event = + (GrowingViewElementEvent *)(GrowingViewElementEvent.builder.setEventType(GrowingEventTypeViewChange).build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); @@ -432,15 +428,16 @@ - (void)testEventConvertToPB_ViewChange { // GrowingHybridViewElementEvent { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeViewChange) - .setPath(@"path") - .setTextValue(@"textvalue") - .setXpath(@"xpath") - .setIndex(1) - .setHyperlink(@"hyperlink") - .setQuery(@"query") - .build); + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder + .setEventType(GrowingEventTypeViewChange) + .setPath(@"path") + .setTextValue(@"textvalue") + .setXpath(@"xpath") + .setIndex(1) + .setHyperlink(@"hyperlink") + .setQuery(@"query") + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); @@ -453,9 +450,9 @@ - (void)testEventConvertToPB_ViewChange { XCTAssertEqualObjects(event.query ?: @"", protobuf.query); } { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeViewChange) - .build); + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent + *)(GrowingHybridViewElementEvent.builder.setEventType(GrowingEventTypeViewChange).build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeViewChange, event.eventType); @@ -472,13 +469,14 @@ - (void)testEventConvertToPB_ViewChange { - (void)testEventConvertToPB_FormSubmit { // GrowingHybridViewElementEvent { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeFormSubmit) - .setPath(@"path") - .setXpath(@"xpath") - .setIndex(1) - .setQuery(@"query") - .build); + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder + .setEventType(GrowingEventTypeFormSubmit) + .setPath(@"path") + .setXpath(@"xpath") + .setIndex(1) + .setQuery(@"query") + .build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); @@ -489,9 +487,9 @@ - (void)testEventConvertToPB_FormSubmit { XCTAssertEqualObjects(event.query ?: @"", protobuf.query); } { - GrowingHybridViewElementEvent *event = (GrowingHybridViewElementEvent *)(GrowingHybridViewElementEvent.builder - .setEventType(GrowingEventTypeFormSubmit) - .build); + GrowingHybridViewElementEvent *event = + (GrowingHybridViewElementEvent + *)(GrowingHybridViewElementEvent.builder.setEventType(GrowingEventTypeFormSubmit).build); GrowingPBEventV3Dto *protobuf = [self protobufFromEvent:event]; [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypeFormSubmit, event.eventType); @@ -504,8 +502,8 @@ - (void)testEventConvertToPB_FormSubmit { } - (GrowingPBEventV3Dto *)protobufFromEvent:(GrowingBaseEvent *)event { - GrowingEventProtobufPersistence *p = [GrowingEventProtobufPersistence persistenceEventWithEvent:event - uuid:[NSUUID UUID].UUIDString]; + GrowingEventProtobufPersistence *p = + [GrowingEventProtobufPersistence persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; return [GrowingPBEventV3Dto parseFromData:p.data error:nil]; } @@ -518,7 +516,8 @@ - (void)contrastOfDefaultParamter:(GrowingBaseEvent *)event protobuf:(GrowingPBE XCTAssertEqual(event.timestamp, protobuf.timestamp); XCTAssertEqualObjects(event.domain ?: @"", protobuf.domain); XCTAssertEqualObjects(event.urlScheme ?: @"", protobuf.URLScheme); - XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), protobuf.appState); + XCTAssertEqualObjects((event.appState == GrowingAppStateForeground ? @"FOREGROUND" : @"BACKGROUND"), + protobuf.appState); XCTAssertEqual(event.eventSequenceId, protobuf.eventSequenceId); XCTAssertEqualObjects(event.extraParams[@"dataSourceId"] ?: @"", protobuf.dataSourceId); // 3.2.0 diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m index 6ad40f408..1cc59ad2e 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufPersistenceTest.m @@ -17,12 +17,11 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "Services/Protobuf/GrowingEventProtobufPersistence.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" -#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" #import "Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.h" +#import "Services/Protobuf/GrowingEventProtobufPersistence.h" +#import "Services/Protobuf/Proto/GrowingEvent.pbobjc.h" @interface ProtobufPersistenceTest : XCTestCase @@ -34,10 +33,8 @@ @implementation ProtobufPersistenceTest - (void)setUp { // Put setup code here. This method is called before the invocation of each test method in the class. - self.event = (GrowingCustomEvent *)(GrowingCustomEvent.builder - .setEventName(@"custom") - .setAttributes(@{@"key": @"value"}) - .build); + self.event = (GrowingCustomEvent + *)(GrowingCustomEvent.builder.setEventName(@"custom").setAttributes(@{@"key": @"value"}).build); } - (void)tearDown { @@ -50,7 +47,8 @@ - (void)testPersistenceInit { GrowingEventProtobufPersistence *p = [[GrowingEventProtobufPersistence alloc] initWithUUID:uuid eventType:self.event.eventType data:protobuf.data - policy:self.event.sendPolicy]; + policy:self.event.sendPolicy + sdkVersion:self.event.sdkVersion]; XCTAssertNotNil(p); XCTAssertEqualObjects(p.eventUUID, uuid); XCTAssertEqualObjects(p.eventType, self.event.eventType); @@ -60,7 +58,8 @@ - (void)testPersistenceInit { - (void)testPersistenceWithEvent { NSString *uuid = [NSUUID UUID].UUIDString; - GrowingEventProtobufPersistence *p = [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event uuid:uuid]; + GrowingEventProtobufPersistence *p = [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event + uuid:uuid]; XCTAssertNotNil(p); XCTAssertEqualObjects(p.eventUUID, uuid); XCTAssertEqualObjects(p.eventType, self.event.eventType); @@ -69,12 +68,12 @@ - (void)testPersistenceWithEvent { } - (void)testBuildRawEventsFromEvents { - GrowingEventProtobufPersistence *p1 = [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event - uuid:[NSUUID UUID].UUIDString]; - GrowingEventProtobufPersistence *p2 = [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event - uuid:[NSUUID UUID].UUIDString]; - GrowingEventProtobufPersistence *p3 = [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event - uuid:[NSUUID UUID].UUIDString]; + GrowingEventProtobufPersistence *p1 = + [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event uuid:[NSUUID UUID].UUIDString]; + GrowingEventProtobufPersistence *p2 = + [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event uuid:[NSUUID UUID].UUIDString]; + GrowingEventProtobufPersistence *p3 = + [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event uuid:[NSUUID UUID].UUIDString]; NSData *data = [GrowingEventProtobufPersistence buildRawEventsFromEvents:@[p1, p2, p3]]; XCTAssertNotNil(data); GrowingPBEventV3List *list = [GrowingPBEventV3List parseFromData:data error:nil]; @@ -87,8 +86,8 @@ - (void)testBuildRawEventsFromEvents { } - (void)testPersistenceToJSONObject { - GrowingEventProtobufPersistence *p = [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event - uuid:[NSUUID UUID].UUIDString]; + GrowingEventProtobufPersistence *p = + [GrowingEventProtobufPersistence persistenceEventWithEvent:self.event uuid:[NSUUID UUID].UUIDString]; XCTAssertNotNil(p); id jsonObject = p.toJSONObject; XCTAssertNotNil(jsonObject); diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m index 2fc3c1d9f..e69fd1561 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufRequestHeaderTest.m @@ -17,13 +17,12 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" #import "GrowingAutotrackConfiguration.h" +#import "GrowingAutotrackerCore/GrowingRealAutotracker.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "Modules/DefaultServices/GrowingEventRequestProtobufAdapter.h" #import "Modules/DefaultServices/GrowingEventRequestJSONAdapter.h" +#import "Modules/DefaultServices/GrowingEventRequestProtobufAdapter.h" @interface ProtobufRequestHeaderTest : XCTestCase @@ -43,15 +42,16 @@ - (void)test01RequestHeaderProtobufFirst { GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; config.useProtobuf = YES; [GrowingRealAutotracker trackerWithConfiguration:config launchOptions:nil]; - + GrowingEventRequestProtobufAdapter *adapter = [GrowingEventRequestProtobufAdapter adapterWithRequest:nil]; GrowingEventRequestJSONAdapter *adapter2 = [GrowingEventRequestJSONAdapter adapterWithRequest:nil]; XCTAssertLessThan(adapter2.priority, adapter.priority); - - NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.growingio.com"]]; + + NSMutableURLRequest *request = + [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.growingio.com"]]; request = [adapter2 adaptedURLRequest:request]; request = [adapter adaptedURLRequest:request]; - + NSDictionary *allHTTPHeaderFields = request.allHTTPHeaderFields; for (NSString *key in allHTTPHeaderFields.allKeys) { if ([key isEqualToString:@"Content-Type"]) { @@ -66,15 +66,16 @@ - (void)test02RequestHeaderJSONFirst { GrowingAutotrackConfiguration *config = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; config.useProtobuf = NO; [GrowingRealAutotracker trackerWithConfiguration:config launchOptions:nil]; - + GrowingEventRequestProtobufAdapter *adapter = [GrowingEventRequestProtobufAdapter adapterWithRequest:nil]; GrowingEventRequestJSONAdapter *adapter2 = [GrowingEventRequestJSONAdapter adapterWithRequest:nil]; XCTAssertLessThan(adapter.priority, adapter2.priority); - - NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.growingio.com"]]; + + NSMutableURLRequest *request = + [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.growingio.com"]]; request = [adapter adaptedURLRequest:request]; request = [adapter2 adaptedURLRequest:request]; - + NSDictionary *allHTTPHeaderFields = request.allHTTPHeaderFields; for (NSString *key in allHTTPHeaderFields.allKeys) { if ([key isEqualToString:@"Content-Type"]) { diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index 8bc04a363..eef883f9f 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -219,13 +219,13 @@ - (void)test07Hybrid { [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; // 尝试通过tapPoint点击到html中的button [viewTester tapScreenAtPoint:CGPointMake(100, 200)]; - + XCTestExpectation *expectation = [self expectationWithDescription:@"WebCircle Test failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSString *message = MockWebSocket.sharedInstance.lastMessage; NSMutableDictionary *dic = [[message growingHelper_jsonObject] mutableCopy]; [self webCircleSocketParamsCheck:dic]; - + // webView圈选数据 NSArray *elements = dic[@"elements"]; XCTAssertNotNil(elements); @@ -234,12 +234,12 @@ - (void)test07Hybrid { XCTAssertNotNil(element[@"webView"]); } } - + [expectation fulfill]; }); [self waitForExpectationsWithTimeout:5.0f handler:nil]; - + [[viewTester usingLabel:@"UI界面"] tap]; } @@ -260,7 +260,7 @@ - (void)webCircleSocketParamsCheck:(NSDictionary *)dic { XCTAssertNotNil(dic[@"snapshotKey"]); XCTAssertNotNil(dic[@"scale"]); XCTAssertNotNil(dic[@"screenshot"]); - + NSArray *elements = dic[@"elements"]; XCTAssertNotNil(elements); for (NSDictionary *element in elements) { @@ -276,7 +276,7 @@ - (void)webCircleSocketParamsCheck:(NSDictionary *)dic { XCTAssertNotNil(element[@"page"]); XCTAssertNotNil(element[@"isContainer"]); } - + NSArray *pages = dic[@"pages"]; XCTAssertNotNil(pages); for (NSDictionary *page in pages) { diff --git a/Example/GrowingAnalyticsTests/ServicesTests/CompressionTests/CompressionTest.m b/Example/GrowingAnalyticsTests/ServicesTests/CompressionTests/CompressionTest.m index bfb749c6f..0de50fc7b 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/CompressionTests/CompressionTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/CompressionTests/CompressionTest.m @@ -19,9 +19,9 @@ #import -#import "Services/Compression/GrowingDataCompression.h" #import "GrowingTrackerCore/Event/GrowingVisitEvent.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" +#import "Services/Compression/GrowingDataCompression.h" @interface CompressionTest : XCTestCase @@ -34,7 +34,7 @@ @implementation CompressionTest - (void)setUp { self.dict = GrowingVisitEvent.builder.setIdfa(@"testIdfa") .setIdfv(@"testIdfv") - .setExtraSdk(@{@"testkey" : @"value"}) + .setExtraSdk(@{@"testkey": @"value"}) .setNetworkState(@"testNetworkState") .setScreenHeight(1920) .setScreenWidth(1280) diff --git a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m index 42872de11..7e7f5f06e 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONDatabaseTest.m @@ -19,12 +19,12 @@ #import +#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" +#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" +#import "GrowingTrackerCore/FileStorage/GrowingFileStorage.h" #import "InvocationHelper.h" #import "Services/JSON/GrowingEventJSONDatabase.h" #import "Services/JSON/GrowingEventJSONPersistence.h" -#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" -#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" -#import "GrowingTrackerCore/FileStorage/GrowingFileStorage.h" @interface JSONDatabaseTest : XCTestCase @@ -90,9 +90,6 @@ - (void)testDatabaseInstanceMethods { // insert events XCTAssertEqual([database insertEvents:events], YES); - NSArray *array = [database getEventsByCount:insertCount]; - XCTAssertEqual(array.count, insertCount); - NSArray *array2 = [database getEventsByCount:insertCount policy:GrowingEventSendPolicyInstant]; XCTAssertEqual(array2.count, insertCount); @@ -117,34 +114,33 @@ - (void)testDatabaseEventIO { // clear all events XCTAssertEqual(database.clearAllEvents, YES); - GrowingCustomEvent *event = - (GrowingCustomEvent *)(GrowingCustomEvent.builder.setEventName(@"custom") - .setAttributes(@{@"key": @"value"}) - .setPlatform(@"platform") - .setPlatformVersion(@"20") - .setDeviceId([NSUUID UUID].UUIDString) - .setUserId(@"userId") - .setSessionId([NSUUID UUID].UUIDString) - .setTimestamp(1638857558209) - .setDomain(@"com.bundle.id") - .setUrlScheme(@"growing.xxxxxx") - .setAppState(GrowingAppStateForeground) - .setEventSequenceId(999) - .setNetworkState(@"5G") - .setScreenHeight(1334) - .setScreenWidth(750) - .setDeviceBrand(@"device brand") - .setDeviceModel(@"device model") - .setDeviceType(@"device type") - .setAppVersion(@"3.0.0") - .setAppName(@"Example") - .setLanguage(@"zh-Hans-CN") - .setLatitude(30.11) - .setLongitude(32.22) - .setSdkVersion(@"3.3.3") - .setUserKey(@"iPhone") - .setDataSourceId(@"1234567890") - .build); + GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder.setEventName(@"custom") + .setAttributes(@{@"key": @"value"}) + .setPlatform(@"platform") + .setPlatformVersion(@"20") + .setDeviceId([NSUUID UUID].UUIDString) + .setUserId(@"userId") + .setSessionId([NSUUID UUID].UUIDString) + .setTimestamp(1638857558209) + .setDomain(@"com.bundle.id") + .setUrlScheme(@"growing.xxxxxx") + .setAppState(GrowingAppStateForeground) + .setEventSequenceId(999) + .setNetworkState(@"5G") + .setScreenHeight(1334) + .setScreenWidth(750) + .setDeviceBrand(@"device brand") + .setDeviceModel(@"device model") + .setDeviceType(@"device type") + .setAppVersion(@"3.0.0") + .setAppName(@"Example") + .setLanguage(@"zh-Hans-CN") + .setLatitude(30.11) + .setLongitude(32.22) + .setSdkVersion(@"3.3.3") + .setUserKey(@"iPhone") + .setDataSourceId(@"1234567890") + .build); NSString *uuid = [NSUUID UUID].UUIDString; GrowingEventJSONPersistence *persistenceIn = [GrowingEventJSONPersistence persistenceEventWithEvent:event uuid:uuid]; @@ -152,7 +148,10 @@ - (void)testDatabaseEventIO { XCTAssertEqual([database insertEvent:persistenceIn], YES); NSInteger insertCount = 1; - NSArray *array = [database getEventsByCount:5]; // 避免多线程情况下,刚好还有其他事件产生入库,这里数值设定大一点 + NSArray *array = [database + getEventsByCount:5 + policy:GrowingEventSendPolicyInstant | GrowingEventSendPolicyMobileData | + GrowingEventSendPolicyWiFi]; // 避免多线程情况下,刚好还有其他事件产生入库,这里数值设定大一点 XCTAssertGreaterThanOrEqual(array.count, insertCount); GrowingEventJSONPersistence *persistenceOut; @@ -200,12 +199,12 @@ - (void)testDatabaseEventIO { } - (GrowingEventJSONPersistence *)customEventPersistence { - GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder.build); + GrowingCustomEvent *event = (GrowingCustomEvent *)(GrowingCustomEvent.builder.setSdkVersion(@"4.0.0").build); return [GrowingEventJSONPersistence persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; } - (GrowingEventJSONPersistence *)visitEventPersistence { - GrowingVisitEvent *event = (GrowingVisitEvent *)(GrowingVisitEvent.builder.build); + GrowingVisitEvent *event = (GrowingVisitEvent *)(GrowingVisitEvent.builder.setSdkVersion(@"4.0.0").build); return [GrowingEventJSONPersistence persistenceEventWithEvent:event uuid:[NSUUID UUID].UUIDString]; } diff --git a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m index da94db485..25bef285c 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/DatabaseTests/JSONPersistenceTest.m @@ -19,9 +19,9 @@ #import -#import "Services/JSON/GrowingEventJSONPersistence.h" #import "GrowingTrackerCore/Event/GrowingCustomEvent.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" +#import "Services/JSON/GrowingEventJSONPersistence.h" @interface JSONPersistenceTest : XCTestCase @@ -41,8 +41,9 @@ - (void)testPersistenceInit { GrowingEventJSONPersistence *p = [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:self.event.eventType - data:self.event.toDictionary.growingHelper_jsonString - policy:self.event.sendPolicy]; + data:self.event.toDictionary.growingHelper_jsonString + policy:self.event.sendPolicy + sdkVersion:self.event.sdkVersion]; XCTAssertNotNil(p); XCTAssertEqualObjects(p.eventUUID, uuid); XCTAssertEqualObjects(p.eventType, self.event.eventType); diff --git a/Example/GrowingAnalyticsTests/ServicesTests/EncryptionTests/EncryptionTest.m b/Example/GrowingAnalyticsTests/ServicesTests/EncryptionTests/EncryptionTest.m index e6a3ea3d1..8c0ac0b91 100644 --- a/Example/GrowingAnalyticsTests/ServicesTests/EncryptionTests/EncryptionTest.m +++ b/Example/GrowingAnalyticsTests/ServicesTests/EncryptionTests/EncryptionTest.m @@ -19,10 +19,10 @@ #import -#import "Services/Encryption/GrowingDataEncoder.h" #import "GrowingTrackerCore/Event/GrowingVisitEvent.h" #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingULTimeUtil.h" +#import "Services/Encryption/GrowingDataEncoder.h" @interface EncryptionTest : XCTestCase @@ -35,7 +35,7 @@ @implementation EncryptionTest - (void)setUp { self.dict = GrowingVisitEvent.builder.setIdfa(@"testIdfa") .setIdfv(@"testIdfv") - .setExtraSdk(@{@"testkey" : @"value"}) + .setExtraSdk(@{@"testkey": @"value"}) .setNetworkState(@"testNetworkState") .setScreenHeight(1920) .setScreenWidth(1280) diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/CoreTests/GrowingAnnotationTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/CoreTests/GrowingAnnotationTest.m index d242c5bef..683c3680b 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/CoreTests/GrowingAnnotationTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/CoreTests/GrowingAnnotationTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingAnnotationCore.h" @@ -42,7 +41,7 @@ - (void)tearDown { - (void)testAnnotationMethod { growing_section section = growingSectionDataModule(); - XCTAssertTrue(section.count != 0,"growing_section can`t be nil"); + XCTAssertTrue(section.count != 0, "growing_section can`t be nil"); BOOL isFindMod = NO; for (int i = 0; i < section.count; i++) { char *string = (char *)section.charAddress[i]; diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m index 06b3ff5b5..5284e02ff 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/DatabaseTests/DatabaseTest.m @@ -17,19 +17,18 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "InvocationHelper.h" -#import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/JSON/GrowingEventJSONDatabase.h" +#import "GrowingServiceManager.h" #import "GrowingTrackerCore/Database/GrowingEventDatabase.h" -#import "Services/JSON/GrowingEventJSONPersistence.h" +#import "GrowingTrackerCore/Event/GrowingTrackEventType.h" #import "GrowingTrackerCore/Event/GrowingVisitEvent.h" -#import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/FileStorage/GrowingFileStorage.h" -#import "GrowingTrackerCore/Event/GrowingTrackEventType.h" +#import "GrowingTrackerCore/Helpers/GrowingHelpers.h" +#import "InvocationHelper.h" +#import "Services/JSON/GrowingEventJSONDatabase.h" +#import "Services/JSON/GrowingEventJSONPersistence.h" @interface DatabaseTest : XCTestCase @@ -46,7 +45,8 @@ + (void)setUp { } - (void)setUp { - GrowingEventDatabase *database = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath] isProtobuf:NO]; + GrowingEventDatabase *database = [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getTimingDatabasePath] + isProtobuf:NO]; XCTAssertNotNil(database); self.database = database; @@ -81,10 +81,7 @@ - (void)testDatabase { { XCTAssertTrue([self.database clearAllItems]); XCTAssertEqual(self.database.countOfEvents, 0); - - NSArray *events = [self.database getEventsWithPackageNum:1]; - XCTAssertEqual(events.count, 0); - NSArray *events2 = [self.database getEventsWithPackageNum:1 policy:GrowingEventSendPolicyInstant]; + NSArray *events2 = [self.database getEventsByCount:1 policy:GrowingEventSendPolicyInstant]; XCTAssertEqual(events2.count, 0); } @@ -93,11 +90,12 @@ - (void)testDatabase { GrowingEventJSONPersistence *event = [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:GrowingEventTypeVisit - data:self.event.toDictionary.growingHelper_jsonString - policy:GrowingEventSendPolicyInstant]; + data:self.event.toDictionary.growingHelper_jsonString + policy:GrowingEventSendPolicyInstant + sdkVersion:self.event.sdkVersion]; XCTAssertNoThrow([self.database setEvent:event forKey:uuid]); XCTAssertEqual(self.database.countOfEvents, 1); - NSArray *events = [self.database getEventsWithPackageNum:1 policy:GrowingEventSendPolicyInstant]; + NSArray *events = [self.database getEventsByCount:1 policy:GrowingEventSendPolicyInstant]; XCTAssertEqual(events.count, 1); } @@ -107,7 +105,8 @@ - (void)testDatabase { [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:GrowingEventTypeVisit data:self.event.toDictionary.growingHelper_jsonString - policy:GrowingEventSendPolicyInstant]; + policy:GrowingEventSendPolicyInstant + sdkVersion:self.event.sdkVersion]; XCTAssertNoThrow([self.database buildRawEventsFromEvents:@[event]]); XCTAssertNoThrow([self.database persistenceEventWithEvent:self.event uuid:uuid]); } diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m index 9d1d65eba..45d37d73a 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/DeepLinkTests/DeepLinkTest.m @@ -28,11 +28,9 @@ @interface DeepLinkTest : XCTestCase @implementation DeepLinkTest - (void)setUp { - } - (void)tearDown { - } - (void)testDeepLinkhandlerUrl { diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/DataTrafficTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/DataTrafficTest.m index 13f120e08..b36ce262d 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/DataTrafficTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/DataTrafficTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingTrackerCore/Event/GrowingDataTraffic.h" diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m index 7b7e503f8..9f1443866 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m @@ -17,26 +17,25 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" -#import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Protobuf/GrowingEventProtobufDatabase.h" -#import "GrowingTrackerCore/Event/GrowingEventManager.h" -#import "MockEventQueue.h" -#import "ManualTrackHelper.h" +#import "GrowingServiceManager.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingAutotrackEventType.h" -#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" -#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" -#import "GrowingTrackerCore/Event/GrowingAppCloseEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" -#import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" +#import "GrowingTrackerCore/Event/GrowingAppCloseEvent.h" #import "GrowingTrackerCore/Event/GrowingConversionVariableEvent.h" +#import "GrowingTrackerCore/Event/GrowingCustomEvent.h" +#import "GrowingTrackerCore/Event/GrowingEventManager.h" #import "GrowingTrackerCore/Event/GrowingLoginUserAttributesEvent.h" +#import "GrowingTrackerCore/Event/GrowingVisitEvent.h" +#import "GrowingTrackerCore/Event/GrowingVisitorAttributesEvent.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" +#import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" +#import "ManualTrackHelper.h" +#import "MockEventQueue.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" @interface EventTest : XCTestCase @@ -47,13 +46,13 @@ @implementation EventTest + (void)setUp { GrowingTrackConfiguration *config = [GrowingTrackConfiguration configurationWithProjectId:@"test"]; config.dataSourceId = @"test"; - + // 避免不执行readPropertyInTrackThread config.dataCollectionEnabled = YES; // 开启idMapping config.idMappingEnabled = YES; GrowingConfigurationManager.sharedInstance.trackConfiguration = config; - + // 避免insertEventToDatabase异常 [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) implClass:GrowingEventProtobufDatabase.class]; @@ -76,7 +75,7 @@ - (void)tearDown { - (void)testGrowingVisitEvent { GrowingVisitEvent.builder.setIdfa(@"testIdfa") .setIdfv(@"testIdfv") - .setExtraSdk(@{@"testkey" : @"value"}) + .setExtraSdk(@{@"testkey": @"value"}) .setNetworkState(@"testNetworkState") .setScreenHeight(1920) .setScreenWidth(1280) @@ -96,16 +95,16 @@ - (void)testGrowingVisitEvent { .setUserId(@"zhangsan") .setUserKey(@"phone") .setDeviceId(@"testdeviceID"); - + GrowingBaseBuilder *builder = GrowingVisitEvent.builder; [GrowingEventManager.sharedInstance postEventBuilder:builder]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; XCTAssertEqual(events.count, 1); - + GrowingVisitEvent *event = (GrowingVisitEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypeVisit); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeVisit); XCTAssertTrue([ManualTrackHelper visitEventCheck:dic]); @@ -113,17 +112,17 @@ - (void)testGrowingVisitEvent { } - (void)testGrowingCustomEvent { - GrowingBaseBuilder *builder = GrowingCustomEvent.builder.setEventName(@"custom").setAttributes(@{@"key" : @"value"}); + GrowingBaseBuilder *builder = GrowingCustomEvent.builder.setEventName(@"custom").setAttributes(@{@"key": @"value"}); [GrowingEventManager.sharedInstance postEventBuilder:builder]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); - + GrowingCustomEvent *event = (GrowingCustomEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypeCustom); XCTAssertEqualObjects(event.eventName, @"custom"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeCustom); XCTAssertEqualObjects(dic[@"eventName"], @"custom"); @@ -133,16 +132,16 @@ - (void)testGrowingCustomEvent { } - (void)testGrowingLoginUserAttributesEvent { - GrowingBaseBuilder *builder = GrowingLoginUserAttributesEvent.builder.setAttributes(@{@"key" : @"value"}); + GrowingBaseBuilder *builder = GrowingLoginUserAttributesEvent.builder.setAttributes(@{@"key": @"value"}); [GrowingEventManager.sharedInstance postEventBuilder:builder]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; XCTAssertEqual(events.count, 1); - + GrowingLoginUserAttributesEvent *event = (GrowingLoginUserAttributesEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypeLoginUserAttributes); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeLoginUserAttributes); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); @@ -151,16 +150,16 @@ - (void)testGrowingLoginUserAttributesEvent { } - (void)testGrowingConversionVariableEvent { - GrowingBaseBuilder *builder = GrowingConversionVariableEvent.builder.setAttributes(@{@"key" : @"value"}); + GrowingBaseBuilder *builder = GrowingConversionVariableEvent.builder.setAttributes(@{@"key": @"value"}); [GrowingEventManager.sharedInstance postEventBuilder:builder]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeConversionVariables]; XCTAssertEqual(events.count, 1); - + GrowingConversionVariableEvent *event = (GrowingConversionVariableEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypeConversionVariables); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeConversionVariables); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); @@ -169,16 +168,16 @@ - (void)testGrowingConversionVariableEvent { } - (void)testGrowingVisitorAttributesEvent { - GrowingBaseBuilder *builder = GrowingVisitorAttributesEvent.builder.setAttributes(@{@"key" : @"value"}); + GrowingBaseBuilder *builder = GrowingVisitorAttributesEvent.builder.setAttributes(@{@"key": @"value"}); [GrowingEventManager.sharedInstance postEventBuilder:builder]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisitorAttributes]; XCTAssertEqual(events.count, 1); - + GrowingVisitorAttributesEvent *event = (GrowingVisitorAttributesEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypeVisitorAttributes); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeVisitorAttributes); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); @@ -192,10 +191,10 @@ - (void)testGrowingAppCloseEvent { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeAppClosed]; XCTAssertEqual(events.count, 1); - + GrowingAppCloseEvent *event = (GrowingAppCloseEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypeAppClosed); - + NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeAppClosed); XCTAssertTrue([ManualTrackHelper appCloseEventCheck:dic]); @@ -204,12 +203,11 @@ - (void)testGrowingAppCloseEvent { - (void)testGrowingPageEvent { NSString *orientation = self.deviceOrientation; - GrowingBaseBuilder *builder = GrowingPageEvent.builder - .setPath(@"path") - .setOrientation(orientation) - .setTitle(@"title") - .setReferralPage(@"referralPage") - .setAttributes(@{@"key" : @"value"}); + GrowingBaseBuilder *builder = GrowingPageEvent.builder.setPath(@"path") + .setOrientation(orientation) + .setTitle(@"title") + .setReferralPage(@"referralPage") + .setAttributes(@{@"key": @"value"}); [GrowingEventManager.sharedInstance postEventBuilder:builder]; // !!! 注意:这里有个隐藏的死锁问题 !!! @@ -237,7 +235,7 @@ - (void)testGrowingPageEvent { XCTAssertEqualObjects(dic[@"title"], @"title"); XCTAssertEqualObjects(dic[@"referralPage"], @"referralPage"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); - + NSMutableDictionary *mDic = dic.mutableCopy; if (dic[@"orientation"] == nil && orientation == nil) { // 在无HostApplication的Logic Test时,orientation将为nil,这里手动赋值为PORTRAIT @@ -245,10 +243,10 @@ - (void)testGrowingPageEvent { } XCTAssertTrue([ManualTrackHelper pageEventCheck:mDic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:mDic]); - + [expectation fulfill]; }); - + [self waitForExpectationsWithTimeout:3.0f handler:nil]; } diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/FileStorageTests/FileStorageTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/FileStorageTests/FileStorageTest.m index a4d7969b1..c82a8f958 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/FileStorageTests/FileStorageTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/FileStorageTests/FileStorageTest.m @@ -17,11 +17,10 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" #import "GrowingTrackerCore/FileStorage/GrowingFileStorage.h" +#import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" @interface FileStorageTest : XCTestCase @@ -47,12 +46,12 @@ - (void)testGrowingFileStorage { directory:GrowingUserDirectoryDocuments crypto:nil]); } - + { GrowingFileStorage *storage = [[GrowingFileStorage alloc] initWithName:@"testGrowingFileStorage"]; [storage resetAll]; [storage removeKey:@"testKey"]; - [storage setArray:@[ @"testa", @"testb"] forKey:@"testKey"]; + [storage setArray:@[@"testa", @"testb"] forKey:@"testKey"]; [storage arrayForKey:@"testKey"]; [storage setNumber:@1 forKey:@"testKeyNum"]; XCTAssertNotNil([storage numberForKey:@"testKeyNum"]); diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/GrowingWindowTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/GrowingWindowTest.m index a9b0f2a2f..c6aa09b3b 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/GrowingWindowTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/GrowingWindowTest.m @@ -42,7 +42,8 @@ - (void)testGrowingWindowViewController { [UIScreen mainScreen].bounds.size.height)]; XCTAssertTrue(window.rootViewController.shouldAutorotate); XCTAssertEqual(window.rootViewController.supportedInterfaceOrientations, UIInterfaceOrientationMaskAll); - XCTAssertEqual(window.rootViewController.preferredInterfaceOrientationForPresentation, [[UIApplication sharedApplication]statusBarOrientation]); + XCTAssertEqual(window.rootViewController.preferredInterfaceOrientationForPresentation, + [[UIApplication sharedApplication] statusBarOrientation]); } - (void)testGrowingWindow { @@ -63,11 +64,10 @@ - (void)testGrowingWindow { } XCTAssertNoThrow([sharedInstance hitTest:CGPointMake(0, 0) withEvent:nil]); - GrowingWindowView *windowView = [[GrowingWindowView alloc] init]; windowView.growingViewLevel = 2; XCTAssertEqual(windowView.growingViewLevel, 2); - + XCTAssertNoThrow([window hitTest:CGPointMake(0, 0) withEvent:nil]); #pragma clang diagnostic pop } diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m index 60e142031..082652672 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingFoundationHelpersTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" @@ -90,17 +89,17 @@ - (void)testNSStringGrowingHelper { [a growingHelper_safeSubStringWithLength:1]; [a growingHelper_sha1]; [a growingHelper_isValidU]; - XCTAssertNotNil([[NSString alloc] initWithJsonObject_growingHelper:@{@"key" : @"value"}]); + XCTAssertNotNil([[NSString alloc] initWithJsonObject_growingHelper:@{@"key": @"value"}]); XCTAssertFalse([NSString growingHelper_isBlankString:@"t"]); - a = [@"https://www.baidu.com" growingHelper_absoluteURLStringWithPath:@"path" andQuery:@{@"key" : @"value"}]; + a = [@"https://www.baidu.com" growingHelper_absoluteURLStringWithPath:@"path" andQuery:@{@"key": @"value"}]; XCTAssertEqualObjects(a, @"https://www.baidu.com/path?key=value"); XCTAssertFalse([NSString growingHelper_isEqualStringA:@"A" andStringB:@"B"]); } - (void)testNSURLHelper { NSURL *url = [NSURL URLWithString: - @"growing.3612b67ce562c755://growingio/webservice?serviceType=debugger&wsUrl=wss://" - @"gta0.growingio.com/app/0wDaZmQ1/circle/ec7f5925458f458b8ae6f3901cacaa92"]; + @"growing.3612b67ce562c755://growingio/webservice?serviceType=debugger&wsUrl=wss://" + @"gta0.growingio.com/app/0wDaZmQ1/circle/ec7f5925458f458b8ae6f3901cacaa92"]; XCTAssertNotNil(url.growingHelper_queryDict); } diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingUIKitHelpersTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingUIKitHelpersTest.m index 27085fe9b..0f7892e32 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingUIKitHelpersTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/HelpersTests/GrowingUIKitHelpersTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" @@ -69,7 +68,7 @@ - (void)testUIControlHelper { [button safePerformSelector:@selector(__growingHelper_onClick_handle)]; XCTAssertEqual(a, 4); } - + { UITextField *textField = [[UITextField alloc] init]; textField.growingHelper_onTextChange = nil; diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/HookTests/GrowingULAppLifeCycleTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/HookTests/GrowingULAppLifeCycleTest.m index 6385aedab..59529c618 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/HookTests/GrowingULAppLifeCycleTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/HookTests/GrowingULAppLifeCycleTest.m @@ -43,15 +43,21 @@ - (void)testGrowingULAppLifeCycle { XCTAssertNotNil(sharedInstance); XCTAssertNoThrow([sharedInstance safePerformSelector:@selector(setupAppStateNotification)]); XCTAssertNoThrow([sharedInstance safePerformSelector:@selector(addSceneNotification)]); - + XCTAssertNoThrow([sharedInstance addAppLifecycleDelegate:self]); - - [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidFinishLaunchingNotification object:UIApplication.sharedApplication]; - [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillTerminateNotification object:UIApplication.sharedApplication]; - [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification object:UIApplication.sharedApplication]; - [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillEnterForegroundNotification object:UIApplication.sharedApplication]; - [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillResignActiveNotification object:UIApplication.sharedApplication]; - [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification object:UIApplication.sharedApplication]; + + [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidFinishLaunchingNotification + object:UIApplication.sharedApplication]; + [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillTerminateNotification + object:UIApplication.sharedApplication]; + [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification + object:UIApplication.sharedApplication]; + [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillEnterForegroundNotification + object:UIApplication.sharedApplication]; + [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillResignActiveNotification + object:UIApplication.sharedApplication]; + [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification + object:UIApplication.sharedApplication]; XCTAssertNoThrow([sharedInstance removeAppLifecycleDelegate:self]); sharedInstance = nil; @@ -61,27 +67,21 @@ - (void)testGrowingULAppLifeCycle { #pragma mark - GrowingULAppLifecycleDelegate - (void)applicationDidFinishLaunching:(NSDictionary *)userInfo { - } - (void)applicationWillTerminate { - } - (void)applicationDidBecomeActive { - } - (void)applicationWillResignActive { - } - (void)applicationDidEnterBackground { - } - (void)applicationWillEnterForeground { - } @end diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m index ece677483..93f6b5701 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m @@ -17,17 +17,16 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import -#import "GrowingTrackerCore/Manager/GrowingSession.h" -#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingServiceManager.h" #import "GrowingEventDatabaseService.h" -#import "Services/Protobuf/GrowingEventProtobufDatabase.h" -#import "MockEventQueue.h" +#import "GrowingServiceManager.h" #import "GrowingTrackerCore/Event/GrowingTrackEventType.h" +#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" #import "InvocationHelper.h" +#import "MockEventQueue.h" +#import "Services/Protobuf/GrowingEventProtobufDatabase.h" @interface GrowingSessionTest : XCTestCase @@ -41,11 +40,11 @@ + (void)setUp { config.dataCollectionEnabled = YES; config.sessionInterval = 5.0f; GrowingConfigurationManager.sharedInstance.trackConfiguration = config; - + // 避免insertEventToDatabase异常 [GrowingServiceManager.sharedInstance registerService:@protocol(GrowingPBEventDatabaseService) implClass:GrowingEventProtobufDatabase.class]; - + [GrowingSession startSession]; [GrowingSession.currentSession generateVisit]; } @@ -66,10 +65,10 @@ - (void)testSessionStart { - (void)testGenerateVisit { GrowingConfigurationManager.sharedInstance.trackConfiguration.dataCollectionEnabled = NO; [GrowingSession.currentSession generateVisit]; - + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; XCTAssertEqual(events.count, 0); - + GrowingConfigurationManager.sharedInstance.trackConfiguration.dataCollectionEnabled = YES; [GrowingSession.currentSession generateVisit]; NSArray *events2 = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; @@ -84,22 +83,20 @@ - (void)testApplicationLifeCycle { NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeAppClosed]; XCTAssertEqual(events.count, 1); } - + { [GrowingSession.currentSession performSelector:@selector(applicationWillResignActive)]; NSNumber *sessionInterval = [GrowingSession.currentSession safePerformSelector:@selector(sessionInterval)]; sleep((int)(sessionInterval.longLongValue / 1000LL) + 1); - + NSString *oldSessionId = GrowingSession.currentSession.sessionId; [GrowingSession.currentSession performSelector:@selector(applicationDidBecomeActive)]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeVisit]; XCTAssertEqual(events.count, 1); XCTAssertNotEqualObjects(oldSessionId, GrowingSession.currentSession.sessionId); } - - { - [GrowingSession.currentSession performSelector:@selector(applicationWillTerminate)]; - } + + { [GrowingSession.currentSession performSelector:@selector(applicationWillTerminate)]; } #pragma clang diagnostic pop } diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingAlertTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingAlertTest.m index e0a7548c1..287a89e9f 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingAlertTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingAlertTest.m @@ -41,22 +41,22 @@ - (void)testGrowingAlert { message:@"test"]; [alert addActionWithTitle:@"Default" style:UIAlertActionStyleDefault - handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields) { + handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields){ }]; [alert addOkWithTitle:@"OK" - handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields) { + handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields){ }]; [alert addCancelWithTitle:@"Cancel" - handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields) { + handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields){ }]; [alert addDestructiveWithTitle:@"Destructive" - handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields) { + handler:^(UIAlertAction *_Nonnull action, NSArray *_Nonnull textFields){ }]; - [alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) { + [alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField){ }]; diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingStatusBarTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingStatusBarTest.m index 3997a49dc..a50aa2b42 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingStatusBarTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/MenuTests/GrowingStatusBarTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingTrackerCore/Menu/GrowingStatusBar.h" @@ -38,12 +37,13 @@ - (void)tearDown { } - (void)testGrowingStatusBar { - GrowingStatusBar *statusBar = [[GrowingStatusBar alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 20)]; + GrowingStatusBar *statusBar = + [[GrowingStatusBar alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 20)]; [statusBar setNeedsLayout]; [statusBar layoutIfNeeded]; [statusBar hitTest:CGPointMake(0, 0) withEvent:nil]; [statusBar setOnButtonClick:^{ - + }]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" @@ -52,5 +52,4 @@ - (void)testGrowingStatusBar { statusBar = nil; } - @end diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/SwizzleTests/GrowingSwizzleTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/SwizzleTests/GrowingSwizzleTest.m index a44e86e22..d649eae77 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/SwizzleTests/GrowingSwizzleTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/SwizzleTests/GrowingSwizzleTest.m @@ -19,10 +19,10 @@ #import +#import +#import #import "GrowingULSwizzle.h" #import "GrowingULSwizzler.h" -#import -#import static NSInteger b = 0; @@ -113,7 +113,8 @@ - (instancetype)initWithTarget:(id)target { - (void)delegateSelector { } -static void fooMethod(id obj, SEL _cmd) {} +static void fooMethod(id obj, SEL _cmd) { +} + (BOOL)resolveInstanceMethod:(SEL)sel { if (sel == @selector(delegateSelector2)) { diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/ThreadTests/GrowingDispatchManagerTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/ThreadTests/GrowingDispatchManagerTest.m index 4bf84e983..e0846d6b3 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/ThreadTests/GrowingDispatchManagerTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/ThreadTests/GrowingDispatchManagerTest.m @@ -40,7 +40,7 @@ - (void)testGrowingDispatchManager { [GrowingDispatchManager dispatchInGrowingThread:^{ XCTAssertTrue([[NSThread currentThread] isEqual:[GrowingThread sharedThread]]); }]; - + [GrowingDispatchManager dispatchInGrowingThread:^{ XCTAssertTrue([[NSThread currentThread] isEqual:[GrowingThread sharedThread]]); [GrowingDispatchManager dispatchInGrowingThread:^{ @@ -49,30 +49,36 @@ - (void)testGrowingDispatchManager { }]; __block int i = 0; - [GrowingDispatchManager dispatchInGrowingThread:^{ - XCTAssertTrue([[NSThread currentThread] isEqual:[GrowingThread sharedThread]]); - i = 1; - } waitUntilDone:YES]; + [GrowingDispatchManager + dispatchInGrowingThread:^{ + XCTAssertTrue([[NSThread currentThread] isEqual:[GrowingThread sharedThread]]); + i = 1; + } + waitUntilDone:YES]; XCTAssertTrue(i == 1); [GrowingDispatchManager dispatchInMainThread:^{ XCTAssertTrue([NSThread isMainThread]); }]; - - [GrowingDispatchManager trackApiSel:@selector(test) dispatchInMainThread:^{ - XCTAssertTrue([NSThread isMainThread]); - }]; - - [GrowingDispatchManager dispatchInGrowingThread:^{ - [GrowingDispatchManager dispatchInMainThread:^{ - XCTAssertTrue([NSThread isMainThread]); - }]; - - [GrowingDispatchManager trackApiSel:@selector(test) dispatchInMainThread:^{ - XCTAssertTrue([NSThread isMainThread]); - }]; - } waitUntilDone:YES]; + + [GrowingDispatchManager trackApiSel:@selector(test) + dispatchInMainThread:^{ + XCTAssertTrue([NSThread isMainThread]); + }]; + + [GrowingDispatchManager + dispatchInGrowingThread:^{ + [GrowingDispatchManager dispatchInMainThread:^{ + XCTAssertTrue([NSThread isMainThread]); + }]; + + [GrowingDispatchManager trackApiSel:@selector(test) + dispatchInMainThread:^{ + XCTAssertTrue([NSThread isMainThread]); + }]; + } + waitUntilDone:YES]; } - (void)testGrowingThread { diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m index f8d43a2cb..8b9b7e3a2 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DeviceInfoTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DynamicProxyTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DynamicProxyTest.m index affadfc94..0449b3836 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DynamicProxyTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/UtilsTests/DynamicProxyTest.m @@ -17,7 +17,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #import #import "GrowingDynamicProxy.h" @@ -96,9 +95,7 @@ - (void)testGrowingDynamicProxy { XCTAssertTrue([dynamicObject respondsToSelector:@selector(instanceMethod)]); XCTAssertTrue([dynamicObject instanceMethod]); XCTAssertEqualObjects(dynamicObject.string, realObject.string); - - XCTAssertTrue([dynamicObject isEqual:realObject]); XCTAssertEqual(dynamicObject.hash, realObject.hash); XCTAssertEqualObjects(dynamicObject.superclass, realObject.superclass); @@ -110,7 +107,7 @@ - (void)testGrowingDynamicProxy { XCTAssertEqualObjects([dynamicObject description], [realObject description]); XCTAssertEqualObjects([dynamicObject debugDescription], [realObject description]); } - + { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnonnull" diff --git a/GrowingAnalytics.podspec b/GrowingAnalytics.podspec index 82b503421..052fe6e4f 100644 --- a/GrowingAnalytics.podspec +++ b/GrowingAnalytics.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GrowingAnalytics' - s.version = '3.7.0' + s.version = '4.0.0' s.summary = 'iOS SDK of GrowingIO.' s.description = <<-DESC GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和行为数据等。目前支持代码埋点、无埋点、可视化圈选、热图等功能。 diff --git a/GrowingTrackerCore/Database/GrowingEventDatabase.h b/GrowingTrackerCore/Database/GrowingEventDatabase.h index 44c46a5d0..8357c40b0 100644 --- a/GrowingTrackerCore/Database/GrowingEventDatabase.h +++ b/GrowingTrackerCore/Database/GrowingEventDatabase.h @@ -34,10 +34,7 @@ - (void)setEvent:(id)event forKey:(NSString *)key; -- (NSArray> *)getEventsWithPackageNum:(NSUInteger)packageNum - policy:(NSUInteger)mask; - -- (NSArray> *)getEventsWithPackageNum:(NSUInteger)packageNum; +- (NSArray> *)getEventsByCount:(NSUInteger)count policy:(NSUInteger)mask; - (NSData *)buildRawEventsFromEvents:(NSArray> *)events; diff --git a/GrowingTrackerCore/Database/GrowingEventDatabase.m b/GrowingTrackerCore/Database/GrowingEventDatabase.m index 749aeff86..f8798e335 100644 --- a/GrowingTrackerCore/Database/GrowingEventDatabase.m +++ b/GrowingTrackerCore/Database/GrowingEventDatabase.m @@ -183,19 +183,8 @@ - (void)setEvent:(id)event forKey:(NSString *)k } } -- (NSArray> *)getEventsWithPackageNum:(NSUInteger)packageNum - policy:(NSUInteger)mask { - NSArray *events = [self.db getEventsByCount:packageNum policy:mask]; - - if (!events) { - [self handleDatabaseError:[self.db lastError]]; - } - return events ?: [[NSArray alloc] init]; -} - -- (NSArray> *)getEventsWithPackageNum:(NSUInteger)packageNum { - NSArray *events = [self.db getEventsByCount:packageNum]; - +- (NSArray> *)getEventsByCount:(NSUInteger)count policy:(NSUInteger)mask { + NSArray *events = [self.db getEventsByCount:count policy:mask]; if (!events) { [self handleDatabaseError:[self.db lastError]]; } diff --git a/GrowingTrackerCore/Event/GrowingEventChannel.m b/GrowingTrackerCore/Event/GrowingEventChannel.m index 10a27336f..58805eeed 100644 --- a/GrowingTrackerCore/Event/GrowingEventChannel.m +++ b/GrowingTrackerCore/Event/GrowingEventChannel.m @@ -64,14 +64,15 @@ + (instancetype)eventChannelWithName:(NSString *)name if (!eventChannels) { eventChannels = [NSMutableArray array]; NSArray *autotrackEventTypes = @[ + GrowingEventTypeVisit, GrowingEventTypePage, GrowingEventTypeViewClick, GrowingEventTypeViewChange, GrowingEventTypeAppClosed, - @"FORM_SUBMIT" /* GrowingEventTypeFormSubmit */ + @"FORM_SUBMIT", /* GrowingEventTypeFormSubmit */ + @"ACTIVATE" /* GrowingEventTypeActivate */ ]; - NSArray *trackEventTypes = - @[GrowingEventTypeVisit, GrowingEventTypeCustom, GrowingEventTypeLoginUserAttributes]; + NSArray *trackEventTypes = @[GrowingEventTypeCustom, GrowingEventTypeLoginUserAttributes]; [eventChannels addObject:[GrowingEventChannel eventChannelWithName:@"Autotrack" eventTypes:autotrackEventTypes persistenceType:GrowingEventPersistenceTypeJSON diff --git a/GrowingTrackerCore/Event/GrowingEventManager.h b/GrowingTrackerCore/Event/GrowingEventManager.h index b67d27484..efac5c100 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.h +++ b/GrowingTrackerCore/Event/GrowingEventManager.h @@ -30,10 +30,6 @@ @optional -/// 可配置事件发送通道 -/// @param channels 默认的事件发送通道 -- (void)growingEventManagerChannels:(NSMutableArray *_Nullable)channels; - /// 事件被触发 /// @param eventType 当前事件类型 - (void)growingEventManagerEventTriggered:(NSString *_Nullable)eventType; @@ -50,10 +46,6 @@ /// @param event 当前事件 - (void)growingEventManagerEventDidWrite:(GrowingBaseEvent *_Nullable)event; -/// 自定义event发送请求 -/// @param channel 事件发送通道 -- (id _Nullable)growingEventManagerRequestWithChannel:(GrowingEventChannel *_Nullable)channel; - /// 即将发送事件 /// @param events 发送的事件 - (NSArray *_Nonnull)growingEventManagerEventsWillSend:(NSArray> *_Nonnull)events diff --git a/GrowingTrackerCore/Event/GrowingEventManager.m b/GrowingTrackerCore/Event/GrowingEventManager.m index 2f9c720d5..b232c9e86 100644 --- a/GrowingTrackerCore/Event/GrowingEventManager.m +++ b/GrowingTrackerCore/Event/GrowingEventManager.m @@ -100,11 +100,7 @@ - (void)configManager { [GrowingEventDatabase databaseWithPath:[GrowingFileStorage getRealtimeDatabasePath] isProtobuf:YES]; NSMutableArray *eventChannels = [GrowingEventChannel eventChannels]; - for (NSObject *obj in self.allInterceptor) { - if ([obj respondsToSelector:@selector(growingEventManagerChannels:)]) { - [obj growingEventManagerChannels:eventChannels]; - } - } + // 发送通道的eventTypes不能修改,并与数据库一一对应 for (GrowingEventChannel *ec in eventChannels) { if (ec.isRealtimeEvent) { if (ec.persistenceType == GrowingEventPersistenceTypeProtobuf) { @@ -268,36 +264,42 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { } NSArray> *events = [self getEventsToBeUploadUnsafe:channel policy:policyMask]; - for (NSObject *obj in self.allInterceptor) { - if ([obj respondsToSelector:@selector(growingEventManagerEventsWillSend:channel:)]) { - events = [obj growingEventManagerEventsWillSend:events channel:channel]; + + // 过滤3.x的无埋点事件 + NSMutableArray *removeV3AutotrackEvents = [NSMutableArray arrayWithArray:events]; + for (id e in events) { + if ([e.sdkVersion hasPrefix:@"4."]) { + continue; + } + if ([e.eventType isEqualToString:@"PAGE"] || [e.eventType isEqualToString:@"VIEW_CLICK"] || + [e.eventType isEqualToString:@"VIEW_CHANGE"] || [e.eventType isEqualToString:@"FORM_SUBMIT"] || + [e.eventType isEqualToString:@"APP_CLOSED"]) { + [removeV3AutotrackEvents removeObject:e]; } } + events = removeV3AutotrackEvents.copy; + if (events.count == 0) { return; } + for (NSObject *obj in self.allInterceptor) { + if ([obj respondsToSelector:@selector(growingEventManagerEventsWillSend:channel:)]) { + events = [obj growingEventManagerEventsWillSend:events channel:channel]; + } + } + channel.isUploading = YES; #ifdef DEBUG [self prettyLogForEvents:events withChannel:channel]; #endif - // 如果需要改变发送地址以及请求参数 - NSObject *eventRequest = nil; - for (NSObject *obj in self.allInterceptor) { - if ([obj respondsToSelector:@selector(growingEventManagerRequestWithChannel:)]) { - eventRequest = [obj growingEventManagerRequestWithChannel:channel]; - if (eventRequest) { - break; - } - } - } NSData *rawEvents = nil; if ((channel.persistenceType == GrowingEventPersistenceTypeJSON && trackConfiguration.useProtobuf) || (channel.persistenceType == GrowingEventPersistenceTypeProtobuf && !trackConfiguration.useProtobuf)) { // 该channel的持久化数据格式与配置不同,需要转换为配置的数据格式 - // 步骤为先转成jsonObject,再转成对应格式 + // 先转成jsonObject,再转成对应格式 Class dbClass = nil; if (trackConfiguration.useProtobuf) { dbClass = @@ -313,22 +315,9 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { for (id e in events) { id jsonObject = e.toJSONObject; if (jsonObject) { - NSString *eventType = jsonObject[@"eventType"]; - NSString *sdkVersion = jsonObject[@"sdkVersion"]; - if ([sdkVersion hasPrefix:@"3."]) { - if ([eventType isEqualToString:@"PAGE"] || [eventType isEqualToString:@"VIEW_CLICK"] || - [eventType isEqualToString:@"VIEW_CHANGE"] || [eventType isEqualToString:@"FORM_SUBMIT"] || - [eventType isEqualToString:@"APP_CLOSED"]) { - // 不兼容3.x的无埋点 - continue; - } - } [jsonObjects addObject:jsonObject]; } } - if (jsonObjects.count == 0) { - return; - } rawEvents = [dbClass buildRawEventsFromJsonObjects:jsonObjects]; } @@ -338,14 +327,7 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel { rawEvents = [channel.db buildRawEventsFromEvents:events]; } - if (!eventRequest) { - eventRequest = [[GrowingEventRequest alloc] initWithEvents:rawEvents]; - } else { - if ([eventRequest respondsToSelector:@selector(setEvents:)]) { - eventRequest.events = rawEvents; - } - } - + NSObject *eventRequest = [[GrowingEventRequest alloc] initWithEvents:rawEvents]; id service = [[GrowingServiceManager sharedInstance] createService:@protocol(GrowingEventNetworkService)]; if (!service) { @@ -427,7 +409,7 @@ - (void)removeEvents_unsafe:(NSArray<__kindof id> *)getEventsToBeUploadUnsafe:(GrowingEventChannel *)channel policy:(NSUInteger)mask { - return [channel.db getEventsWithPackageNum:kGrowingMaxBatchSize policy:mask]; + return [channel.db getEventsByCount:kGrowingMaxBatchSize policy:mask]; } #pragma mark Event Log diff --git a/GrowingTrackerCore/GrowingRealTracker.m b/GrowingTrackerCore/GrowingRealTracker.m index 31b8e9b72..74fc79226 100644 --- a/GrowingTrackerCore/GrowingRealTracker.m +++ b/GrowingTrackerCore/GrowingRealTracker.m @@ -38,8 +38,8 @@ #import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h" #import "GrowingULAppLifecycle.h" -NSString *const GrowingTrackerVersionName = @"3.7.0"; -const int GrowingTrackerVersionCode = 30700; +NSString *const GrowingTrackerVersionName = @"4.0.0"; +const int GrowingTrackerVersionCode = 40000; @interface GrowingRealTracker () diff --git a/GrowingTrackerCore/Public/GrowingEventDatabaseService.h b/GrowingTrackerCore/Public/GrowingEventDatabaseService.h index be5d761bf..06979a6f8 100644 --- a/GrowingTrackerCore/Public/GrowingEventDatabaseService.h +++ b/GrowingTrackerCore/Public/GrowingEventDatabaseService.h @@ -65,11 +65,6 @@ extern NSString *const GrowingEventDatabaseErrorDomain; /// @return 事件数量,大于等于0;若返回值为-1,表示读取错误 - (NSInteger)countOfEvents; -/// 获取事件 -/// @param count 数量 -/// @return 事件对象数组,可为空;若返回值为nil,表示读取错误 -- (nullable NSArray> *)getEventsByCount:(NSUInteger)count; - /// 获取事件 /// @param count 数量 /// @param mask 允许的发送协议(数组) diff --git a/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h b/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h index 26e08bbbf..b3c38aade 100644 --- a/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h +++ b/GrowingTrackerCore/Public/GrowingEventPersistenceProtocol.h @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *eventType; @property (nonatomic, strong, readonly) id data; @property (nonatomic, assign, readonly) GrowingEventSendPolicy policy; +@property (nonatomic, copy, readonly) NSString *sdkVersion; + (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSString *)uuid; @@ -38,7 +39,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithUUID:(NSString *)uuid eventType:(NSString *)eventType data:(id)data - policy:(GrowingEventSendPolicy)policy; + policy:(GrowingEventSendPolicy)policy + sdkVersion:(NSString *)sdkVersion; - (id)toJSONObject; diff --git a/Modules/Advert/GrowingAdvertising.m b/Modules/Advert/GrowingAdvertising.m index 5c1a71b03..1be439281 100644 --- a/Modules/Advert/GrowingAdvertising.m +++ b/Modules/Advert/GrowingAdvertising.m @@ -102,14 +102,6 @@ - (BOOL)growingHandlerUrl:(NSURL *)url { return [self growingHandlerUrl:url isManual:NO callback:nil]; } -#pragma mark - GrowingEventInterceptor - -- (void)growingEventManagerChannels:(NSMutableArray *)channels { - [channels addObject:[GrowingEventChannel eventChannelWithName:@"Advert" - eventTypes:@[GrowingEventTypeActivate] - isRealtimeEvent:YES]]; -} - #pragma mark - GrowingULAppLifecycleDelegate - (void)applicationDidBecomeActive { diff --git a/Podfile.lock b/Podfile.lock index 11d85bf4e..2d7e60da3 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,64 +1,64 @@ PODS: - - GrowingAnalytics/Advert (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/APM (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/Advert (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/APM (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) - GrowingAPM/Core - - GrowingAnalytics/Autotracker (3.5.0): - - GrowingAnalytics/AutotrackerCore (= 3.5.0) - - GrowingAnalytics/DefaultServices (= 3.5.0) - - GrowingAnalytics/Hybrid (= 3.5.0) - - GrowingAnalytics/MobileDebugger (= 3.5.0) - - GrowingAnalytics/WebCircle (= 3.5.0) - - GrowingAnalytics/AutotrackerCore (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/Autotracker (4.0.0): + - GrowingAnalytics/AutotrackerCore (= 4.0.0) + - GrowingAnalytics/DefaultServices (= 4.0.0) + - GrowingAnalytics/Hybrid (= 4.0.0) + - GrowingAnalytics/MobileDebugger (= 4.0.0) + - GrowingAnalytics/WebCircle (= 4.0.0) + - GrowingAnalytics/AutotrackerCore (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) - GrowingUtils/AutotrackerCore (= 0.0.5) - - GrowingAnalytics/Compression (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/Database (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/DefaultServices (3.5.0): - - GrowingAnalytics/Compression (= 3.5.0) - - GrowingAnalytics/Encryption (= 3.5.0) - - GrowingAnalytics/JSON (= 3.5.0) - - GrowingAnalytics/Network (= 3.5.0) - - GrowingAnalytics/Protobuf (= 3.5.0) - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/Encryption (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/Hybrid (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/ImpressionTrack (3.5.0): - - GrowingAnalytics/AutotrackerCore (= 3.5.0) - - GrowingAnalytics/JSON (3.5.0): - - GrowingAnalytics/Database (= 3.5.0) - - GrowingAnalytics/MobileDebugger (3.5.0): - - GrowingAnalytics/Screenshot (= 3.5.0) - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/WebSocket (= 3.5.0) - - GrowingAnalytics/Network (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/Protobuf (3.5.0): - - GrowingAnalytics/Database (= 3.5.0) - - GrowingAnalytics/Protobuf/Proto (= 3.5.0) - - GrowingAnalytics/Protobuf/Proto (3.5.0): - - GrowingAnalytics/Database (= 3.5.0) + - GrowingAnalytics/Compression (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/Database (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/DefaultServices (4.0.0): + - GrowingAnalytics/Compression (= 4.0.0) + - GrowingAnalytics/Encryption (= 4.0.0) + - GrowingAnalytics/JSON (= 4.0.0) + - GrowingAnalytics/Network (= 4.0.0) + - GrowingAnalytics/Protobuf (= 4.0.0) + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/Encryption (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/Hybrid (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/ImpressionTrack (4.0.0): + - GrowingAnalytics/AutotrackerCore (= 4.0.0) + - GrowingAnalytics/JSON (4.0.0): + - GrowingAnalytics/Database (= 4.0.0) + - GrowingAnalytics/MobileDebugger (4.0.0): + - GrowingAnalytics/Screenshot (= 4.0.0) + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/WebSocket (= 4.0.0) + - GrowingAnalytics/Network (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/Protobuf (4.0.0): + - GrowingAnalytics/Database (= 4.0.0) + - GrowingAnalytics/Protobuf/Proto (= 4.0.0) + - GrowingAnalytics/Protobuf/Proto (4.0.0): + - GrowingAnalytics/Database (= 4.0.0) - Protobuf (>= 3.22.0) - - GrowingAnalytics/Screenshot (3.5.0): + - GrowingAnalytics/Screenshot (4.0.0): - GrowingAnalytics/TrackerCore - - GrowingAnalytics/Tracker (3.5.0): - - GrowingAnalytics/DefaultServices (= 3.5.0) - - GrowingAnalytics/MobileDebugger (= 3.5.0) - - GrowingAnalytics/TrackerCore (= 3.5.0) - - GrowingAnalytics/TrackerCore (3.5.0): + - GrowingAnalytics/Tracker (4.0.0): + - GrowingAnalytics/DefaultServices (= 4.0.0) + - GrowingAnalytics/MobileDebugger (= 4.0.0) + - GrowingAnalytics/TrackerCore (= 4.0.0) + - GrowingAnalytics/TrackerCore (4.0.0): - GrowingUtils/TrackerCore (= 0.0.5) - - GrowingAnalytics/WebCircle (3.5.0): - - GrowingAnalytics/AutotrackerCore (= 3.5.0) - - GrowingAnalytics/Hybrid (= 3.5.0) - - GrowingAnalytics/Screenshot (= 3.5.0) - - GrowingAnalytics/WebSocket (= 3.5.0) - - GrowingAnalytics/WebSocket (3.5.0): - - GrowingAnalytics/TrackerCore (= 3.5.0) + - GrowingAnalytics/WebCircle (4.0.0): + - GrowingAnalytics/AutotrackerCore (= 4.0.0) + - GrowingAnalytics/Hybrid (= 4.0.0) + - GrowingAnalytics/Screenshot (= 4.0.0) + - GrowingAnalytics/WebSocket (= 4.0.0) + - GrowingAnalytics/WebSocket (4.0.0): + - GrowingAnalytics/TrackerCore (= 4.0.0) - GrowingAPM (0.0.14): - GrowingAPM/Core (= 0.0.14) - GrowingAPM/CrashMonitor (= 0.0.14) @@ -150,7 +150,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: 87434c0b7311aa8a09ff20e4ae86bd033db3d04d + GrowingAnalytics: 8cae5a0b3a8785c219e4c6ea8ddf8af59d0a37ba GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 9c0d6e41c9678397dbaa3304b1738a2867b023ae GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 diff --git a/Services/Database/GrowingEventFMDatabase.m b/Services/Database/GrowingEventFMDatabase.m index e6abe9fed..fceb7b6b8 100644 --- a/Services/Database/GrowingEventFMDatabase.m +++ b/Services/Database/GrowingEventFMDatabase.m @@ -106,38 +106,24 @@ - (NSInteger)countOfEvents { return count; } -- (nullable NSArray> *)getEventsByCount:(NSUInteger)count { - if (self.countOfEvents == 0) { - return [[NSArray alloc] init]; - } - - NSMutableArray> *events = [[NSMutableArray alloc] init]; - [self enumerateKeysAndValuesUsingBlock:^(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop) { - id event = [[self.class.persistenceClass alloc] initWithUUID:key - eventType:type - data:value - policy:policy]; - [events addObject:event]; - if (events.count >= count) { - **stop = YES; - } - }]; - - return events.count != 0 ? events : nil; -} - - (nullable NSArray> *)getEventsByCount:(NSUInteger)count policy:(NSUInteger)mask { if (self.countOfEvents == 0) { return [[NSArray alloc] init]; } NSMutableArray> *events = [[NSMutableArray alloc] init]; - [self enumerateKeysAndValuesUsingBlock:^(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop) { + [self enumerateKeysAndValuesUsingBlock:^(NSString *key, + id value, + NSString *type, + NSUInteger policy, + NSString *sdkVersion, + BOOL **stop) { if (mask & policy) { id event = [[self.class.persistenceClass alloc] initWithUUID:key eventType:type data:value - policy:policy]; + policy:policy + sdkVersion:sdkVersion]; [events addObject:event]; if (events.count >= count) { **stop = YES; @@ -155,12 +141,14 @@ - (BOOL)insertEvent:(id)event { self.databaseError = error; return; } - result = [db executeUpdate:@"INSERT INTO namedcachetable(key,value,createAt,type,policy) values(?,?,?,?,?)", - event.eventUUID, - event.data, - @([GrowingULTimeUtil currentTimeMillis]), - event.eventType, - @(event.policy)]; + result = [db + executeUpdate:@"INSERT INTO namedcachetable(key,value,createAt,type,sdkVersion,policy) values(?,?,?,?,?,?)", + event.eventUUID, + event.data, + @([GrowingULTimeUtil currentTimeMillis]), + event.eventType, + event.sdkVersion, + @(event.policy)]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; @@ -183,12 +171,15 @@ - (BOOL)insertEvents:(NSArray> *)events { } for (int i = 0; i < events.count; i++) { id event = events[i]; - result = [db executeUpdate:@"INSERT INTO namedcachetable(key,value,createAt,type,policy) values(?,?,?,?,?)", - event.eventUUID, - event.data, - @([GrowingULTimeUtil currentTimeMillis]), - event.eventType, - @(event.policy)]; + result = + [db executeUpdate: + @"INSERT INTO namedcachetable(key,value,createAt,type,sdkVersion,policy) values(?,?,?,?,?,?)", + event.eventUUID, + event.data, + @([GrowingULTimeUtil currentTimeMillis]), + event.eventType, + event.sdkVersion, + @(event.policy)]; if (!result) { self.databaseError = [self writeErrorInDatabase:db]; @@ -306,14 +297,24 @@ - (BOOL)initDB:(NSString *)sqlInit createIndex:(NSString *)sqlCreateIndex { return; } - // 兼容早期无policy - NSString *sqlCreateColumnIfNotExist = @"ALTER TABLE namedcachetable ADD policy INTEGER DEFAULT 6"; + // 兼容3.x早期版本无policy + NSString *sqlCreatePolicy = @"ALTER TABLE namedcachetable ADD policy INTEGER DEFAULT 6"; if (![db columnExists:@"policy" inTableWithName:@"namedcachetable"]) { - if (![db executeUpdate:sqlCreateColumnIfNotExist]) { + if (![db executeUpdate:sqlCreatePolicy]) { + self.databaseError = [self createDBErrorInDatabase:db]; + return; + } + } + + // 4.x新增sdkVersion,用于与3.x区分,过滤不兼容的事件类型 + NSString *sqlCreateSDKVersion = @"ALTER TABLE namedcachetable ADD sdkVersion TEXT DEFAULT '' NOT NULL"; + if (![db columnExists:@"sdkVersion" inTableWithName:@"namedcachetable"]) { + if (![db executeUpdate:sqlCreateSDKVersion]) { self.databaseError = [self createDBErrorInDatabase:db]; return; } } + result = YES; }]; @@ -379,7 +380,7 @@ - (void)makeDirByFileName:(NSString *)filePath { } - (void)enumerateKeysAndValuesUsingBlock: - (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop))block { + (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, NSString *sdkVersion, BOOL **stop))block { @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] diff --git a/Services/JSON/GrowingEventJSONDatabase.m b/Services/JSON/GrowingEventJSONDatabase.m index b194a819e..d5a52ff0e 100644 --- a/Services/JSON/GrowingEventJSONDatabase.m +++ b/Services/JSON/GrowingEventJSONDatabase.m @@ -43,19 +43,21 @@ - (BOOL)initDB { @"value TEXT," @"createAt INTEGER NOT NULL," @"type TEXT," + @"sdkVersion TEXT," @"policy INTEGER);"; NSString *sqlCreateIndex = @"CREATE INDEX IF NOT EXISTS namedcachetable_key ON namedcachetable (key);"; return [self initDB:sqlInit createIndex:sqlCreateIndex]; } - (void)enumerateKeysAndValuesUsingBlock: - (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop))block { + (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, NSString *sdkVersion, BOOL **stop))block { [self enumerateTableUsingBlock:^(GrowingFMResultSet *set, BOOL *s) { NSString *key = [set stringForColumn:@"key"]; id value = [set stringForColumn:@"value"]; NSString *type = [set stringForColumn:@"type"]; NSUInteger policy = [set intForColumn:@"policy"]; - block(key, value, type, policy, &s); + NSString *sdkVersion = [set stringForColumn:@"sdkVersion"]; + block(key, value, type, policy, sdkVersion, &s); }]; } diff --git a/Services/JSON/GrowingEventJSONPersistence.h b/Services/JSON/GrowingEventJSONPersistence.h index c251f7f9c..d2b102313 100644 --- a/Services/JSON/GrowingEventJSONPersistence.h +++ b/Services/JSON/GrowingEventJSONPersistence.h @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *eventType; @property (nonatomic, strong, readonly) id data; @property (nonatomic, assign, readonly) GrowingEventSendPolicy policy; +@property (nonatomic, copy, readonly) NSString *sdkVersion; @end diff --git a/Services/JSON/GrowingEventJSONPersistence.m b/Services/JSON/GrowingEventJSONPersistence.m index 2ce780e5a..ff68b76bd 100644 --- a/Services/JSON/GrowingEventJSONPersistence.m +++ b/Services/JSON/GrowingEventJSONPersistence.m @@ -25,12 +25,14 @@ @implementation GrowingEventJSONPersistence - (instancetype)initWithUUID:(NSString *)uuid eventType:(NSString *)eventType data:(id)data - policy:(GrowingEventSendPolicy)policy { + policy:(GrowingEventSendPolicy)policy + sdkVersion:(NSString *)sdkVersion { if (self = [super init]) { _eventUUID = uuid; _eventType = eventType; _data = data; _policy = policy; + _sdkVersion = sdkVersion; } return self; } @@ -41,7 +43,8 @@ + (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSStri return [[GrowingEventJSONPersistence alloc] initWithUUID:uuid eventType:event.eventType data:eventJsonString - policy:event.sendPolicy]; + policy:event.sendPolicy + sdkVersion:event.sdkVersion]; } + (NSData *)buildRawEventsFromEvents:(NSArray *)events { diff --git a/Services/Protobuf/GrowingEventProtobufDatabase.m b/Services/Protobuf/GrowingEventProtobufDatabase.m index e94bcebd8..83ad64312 100644 --- a/Services/Protobuf/GrowingEventProtobufDatabase.m +++ b/Services/Protobuf/GrowingEventProtobufDatabase.m @@ -51,19 +51,21 @@ - (BOOL)initDB { @"value BLOB," @"createAt INTEGER NOT NULL," @"type TEXT," + @"sdkVersion TEXT," @"policy INTEGER);"; NSString *sqlCreateIndex = @"CREATE INDEX IF NOT EXISTS namedcachetable_key ON namedcachetable (key);"; return [self initDB:sqlInit createIndex:sqlCreateIndex]; } - (void)enumerateKeysAndValuesUsingBlock: - (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, BOOL **stop))block { + (void (^)(NSString *key, id value, NSString *type, NSUInteger policy, NSString *sdkVersion, BOOL **stop))block { [self enumerateTableUsingBlock:^(GrowingFMResultSet *set, BOOL *s) { NSString *key = [set stringForColumn:@"key"]; id value = [set dataForColumn:@"value"]; NSString *type = [set stringForColumn:@"type"]; NSUInteger policy = [set intForColumn:@"policy"]; - block(key, value, type, policy, &s); + NSString *sdkVersion = [set stringForColumn:@"sdkVersion"]; + block(key, value, type, policy, sdkVersion, &s); }]; } diff --git a/Services/Protobuf/GrowingEventProtobufPersistence.h b/Services/Protobuf/GrowingEventProtobufPersistence.h index bb38c650e..027e9a638 100644 --- a/Services/Protobuf/GrowingEventProtobufPersistence.h +++ b/Services/Protobuf/GrowingEventProtobufPersistence.h @@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *eventType; @property (nonatomic, strong, readonly) id data; @property (nonatomic, assign, readonly) GrowingEventSendPolicy policy; +@property (nonatomic, copy, readonly) NSString *sdkVersion; @end diff --git a/Services/Protobuf/GrowingEventProtobufPersistence.m b/Services/Protobuf/GrowingEventProtobufPersistence.m index 6c9d682fd..022dc1c2a 100644 --- a/Services/Protobuf/GrowingEventProtobufPersistence.m +++ b/Services/Protobuf/GrowingEventProtobufPersistence.m @@ -42,7 +42,8 @@ @implementation GrowingEventProtobufPersistence - (instancetype)initWithUUID:(NSString *)uuid eventType:(NSString *)eventType data:(id)data - policy:(GrowingEventSendPolicy)policy { + policy:(GrowingEventSendPolicy)policy + sdkVersion:(NSString *)sdkVersion { if (self = [super init]) { _eventUUID = uuid; _eventType = eventType; @@ -53,6 +54,7 @@ - (instancetype)initWithUUID:(NSString *)uuid _dto = [GrowingPBEventV3Dto parseFromData:data error:nil]; #endif _policy = policy; + _sdkVersion = sdkVersion; } return self; } @@ -62,6 +64,7 @@ + (instancetype)persistenceEventWithEvent:(GrowingBaseEvent *)event uuid:(NSStri persistence->_eventUUID = uuid; persistence->_eventType = event.eventType; persistence->_policy = event.sendPolicy; + persistence->_sdkVersion = event.sdkVersion; #if SWIFT_PACKAGE persistence->_dtoBox = event.toProtobuf; From df76517e3cb5b056e5b957208287ffd15ec0158a Mon Sep 17 00:00:00 2001 From: YoloMao Date: Fri, 11 Aug 2023 16:24:23 +0800 Subject: [PATCH 071/126] fix: delete unused codes --- .../FileStorage/GrowingFileStorage.m | 13 ------- GrowingTrackerCore/GrowingRealTracker.h | 25 ------------ GrowingTrackerCore/GrowingRealTracker.m | 39 ------------------- .../Network/GrowingNetworkInterfaceManager.m | 18 --------- .../Network/Request/GrowingNetworkConfig.h | 2 - .../Network/Request/GrowingNetworkConfig.m | 27 ------------- 6 files changed, 124 deletions(-) diff --git a/GrowingTrackerCore/FileStorage/GrowingFileStorage.m b/GrowingTrackerCore/FileStorage/GrowingFileStorage.m index 38656c316..64bdb4853 100644 --- a/GrowingTrackerCore/FileStorage/GrowingFileStorage.m +++ b/GrowingTrackerCore/FileStorage/GrowingFileStorage.m @@ -264,17 +264,4 @@ - (void)setJSON:(id _Nonnull)json forKey:(NSString *)key { [self setData:data forKey:key]; } -- (NSData *_Nullable)dataFromJSON:(id)json { - if (json == nil) { - return nil; - } - - NSError *error = nil; - NSData *data = [NSJSONSerialization dataWithJSONObject:json options:0 error:&error]; - if (error) { - GIOLogError(@"Unable to serialize data from json object; %@, %@", error, json); - } - return data; -} - @end diff --git a/GrowingTrackerCore/GrowingRealTracker.h b/GrowingTrackerCore/GrowingRealTracker.h index 65251d9b4..e99c49215 100644 --- a/GrowingTrackerCore/GrowingRealTracker.h +++ b/GrowingTrackerCore/GrowingRealTracker.h @@ -48,35 +48,10 @@ FOUNDATION_EXPORT const int GrowingTrackerVersionCode; /// @param attributes 事件发生时所伴随的维度信息 - (void)trackCustomEvent:(NSString *)eventName withAttributes:(NSDictionary *)attributes; -/// 发送一个自定义事件 -/// @param eventName 自定义事件名称 -/// @param attributesBuilder 事件发生时所伴随的维度信息构造器 -- (void)trackCustomEvent:(NSString *)eventName withAttributesBuilder:(GrowingAttributesBuilder *)attributesBuilder; - /// 以登录用户的身份定义用户属性变量,用于用户信息相关分析。 /// @param attributes 用户属性信息 - (void)setLoginUserAttributes:(NSDictionary *)attributes; -/// 以登录用户的身份定义用户属性变量,用于用户信息相关分析。 -/// @param attributesBuilder 用户属性信息构造器 -- (void)setLoginUserAttributesWithAttributesBuilder:(GrowingAttributesBuilder *)attributesBuilder; - -/// 以访客的身份定义用户属性变量,也可用于A/B测试上传标签。 -/// @param attributes 用户属性信息 -- (void)setVisitorAttributes:(NSDictionary *)attributes; - -/// 以访客的身份定义用户属性变量,也可用于A/B测试上传标签。 -/// @param attributesBuilder 用户属性信息构造器 -- (void)setVisitorAttributesWithAttributesBuilder:(GrowingAttributesBuilder *)attributesBuilder; - -/// 发送一个转化信息用于高级归因分析,在添加代码之前必须在打点管理界面上声明转化变量。 -/// @param variables 转化变量信息 -- (void)setConversionVariables:(NSDictionary *)variables; - -/// 发送一个转化信息用于高级归因分析,在添加代码之前必须在打点管理界面上声明转化变量。 -/// @param attributesBuilder 转化变量信息构造器 -- (void)setConversionVariablesWithAttributesBuilder:(GrowingAttributesBuilder *)attributesBuilder; - /// 当用户登录之后调用setLoginUserId API,设置登录用户ID。 /// @param userId 用户ID - (void)setLoginUserId:(NSString *)userId; diff --git a/GrowingTrackerCore/GrowingRealTracker.m b/GrowingTrackerCore/GrowingRealTracker.m index 74fc79226..3b82a1127 100644 --- a/GrowingTrackerCore/GrowingRealTracker.m +++ b/GrowingTrackerCore/GrowingRealTracker.m @@ -143,11 +143,6 @@ - (void)trackCustomEvent:(NSString *)eventName withAttributes:(NSDictionary *)attributes { if ([GrowingArgumentChecker isIllegalAttributes:attributes]) { return; @@ -191,11 +186,6 @@ - (void)trackTimerEnd:(NSString *)timerId withAttributes:(NSDictionary *)attributes { - if ([GrowingArgumentChecker isIllegalAttributes:attributes]) { - return; - } - [GrowingEventGenerator generateVisitorAttributesEvent:attributes]; -} - -- (void)setVisitorAttributesWithAttributesBuilder:(GrowingAttributesBuilder *)attributesBuilder { - NSDictionary *attributes = attributesBuilder.build; - [self setVisitorAttributes:attributes]; -} - -- (void)setConversionVariables:(NSDictionary *)variables { - if ([GrowingArgumentChecker isIllegalAttributes:variables]) { - return; - } - [GrowingEventGenerator generateConversionAttributesEvent:variables]; -} - -- (void)setConversionVariablesWithAttributesBuilder:(GrowingAttributesBuilder *)attributesBuilder { - NSDictionary *attributes = attributesBuilder.build; - [self setConversionVariables:attributes]; -} - - (void)setLoginUserId:(NSString *)userId { [GrowingDispatchManager dispatchInGrowingThread:^{ [[GrowingSession currentSession] setLoginUserId:userId]; diff --git a/GrowingTrackerCore/Network/GrowingNetworkInterfaceManager.m b/GrowingTrackerCore/Network/GrowingNetworkInterfaceManager.m index 177481d3a..4783bb9f7 100644 --- a/GrowingTrackerCore/Network/GrowingNetworkInterfaceManager.m +++ b/GrowingTrackerCore/Network/GrowingNetworkInterfaceManager.m @@ -81,21 +81,7 @@ - (NSString *)networkType { return @"WIFI"; #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST } else if (self.WWANValid) { - NSArray *typeStrings2G = - @[CTRadioAccessTechnologyEdge, CTRadioAccessTechnologyGPRS, CTRadioAccessTechnologyCDMA1x]; - - NSArray *typeStrings3G = @[ - CTRadioAccessTechnologyHSDPA, - CTRadioAccessTechnologyWCDMA, - CTRadioAccessTechnologyHSUPA, - CTRadioAccessTechnologyCDMAEVDORev0, - CTRadioAccessTechnologyCDMAEVDORevA, - CTRadioAccessTechnologyCDMAEVDORevB, - CTRadioAccessTechnologyeHRPD - ]; - NSArray *typeStrings4G = @[CTRadioAccessTechnologyLTE]; - NSString *accessString = CTRadioAccessTechnologyLTE; // default 4G if (@available(iOS 12.0, *)) { if ([self.teleInfo respondsToSelector:@selector(serviceCurrentRadioAccessTechnology)]) { @@ -110,10 +96,6 @@ - (NSString *)networkType { if ([typeStrings4G containsObject:accessString]) { return @"4G"; - } else if ([typeStrings3G containsObject:accessString]) { - return @"3G"; - } else if ([typeStrings2G containsObject:accessString]) { - return @"2G"; #if defined(__IPHONE_14_1) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_1) } else if (@available(iOS 14.1, *)) { NSArray *typeStrings5G = @[CTRadioAccessTechnologyNR, CTRadioAccessTechnologyNRNSA]; diff --git a/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.h b/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.h index 2896f7d30..0a50c0cc9 100644 --- a/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.h +++ b/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.h @@ -28,8 +28,6 @@ @interface GrowingNetworkConfig : NSObject -@property (nonatomic, copy) NSString *customDataHost; - + (instancetype)sharedInstance; /// 返回 growingApiHostEnd 拼接的事件上传地址 eg:https://napi.growingio.com/v3/projects/91eaf9b283361032/collect diff --git a/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.m b/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.m index 41e62e5f7..039155d54 100644 --- a/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.m +++ b/GrowingTrackerCore/Network/Request/GrowingNetworkConfig.m @@ -21,7 +21,6 @@ #import #import "GrowingTrackerCore/Helpers/GrowingHelpers.h" #import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h" -#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h" @implementation GrowingNetworkConfig @@ -35,25 +34,6 @@ + (instancetype)sharedInstance { return sharedInstance; } -+ (NSString *)generateValidEndPoint:(NSString *)customHost { - NSString *validEndPoint = - [[customHost stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] copy]; - if (!validEndPoint.length) { - GIOLogError(@"An empty string is set as tracker host."); - return @""; - } - if (![validEndPoint hasPrefix:@"http://"] && ![validEndPoint hasPrefix:@"https://"]) { - validEndPoint = [NSString stringWithFormat:@"https://%@", validEndPoint]; - } - - NSURL *url = [NSURL URLWithString:validEndPoint]; - if (url == nil) { - GIOLogError(@"An Invalid URL is set as tracker host."); - return @""; - } - return validEndPoint; -} - // 获取url字段 + (NSString *)absoluteURL { NSString *baseUrl = [GrowingNetworkConfig sharedInstance].growingApiHostEnd; @@ -70,13 +50,6 @@ + (NSString *)path { return path; } -- (void)setCustomDataHost:(NSString *)customHost { - NSString *validEndPoint = [GrowingNetworkConfig generateValidEndPoint:customHost]; - if (validEndPoint.length) { - _customDataHost = validEndPoint; - } -} - - (NSString *)growingApiHostEnd { return GrowingConfigurationManager.sharedInstance.trackConfiguration.dataCollectionServerHost; } From 8b2e2bc77a6ddbe3e37c5fc1bb9216a396011ab0 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 14 Aug 2023 17:19:44 +0800 Subject: [PATCH 072/126] fix: growingUniqueTag logic --- .../ClickEvent/GIOClickEventViewController.m | 2 +- .../GIOButtonViewController.m | 1 - .../Event/A1ViewClickEventsTest.m | 6 ++-- .../GrowingNode/GrowingNodeHelper.m | 8 ++--- .../GrowingNode/GrowingViewChangeProvider.m | 23 ++++++++------- .../GrowingNode/GrowingViewClickProvider.m | 23 ++++++++------- .../GrowingNode/GrowingViewNode.h | 9 +++--- .../GrowingNode/GrowingViewNode.m | 29 ++++++++++--------- Modules/WebCircle/GrowingWebCircle.m | 9 +++--- 9 files changed, 58 insertions(+), 52 deletions(-) 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; From 7e3d104403ff2608a5cfedcae1995a18b8e23386 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 14 Aug 2023 19:58:39 +0800 Subject: [PATCH 073/126] ci: growingUniqueTag test --- .../ClickEvent/GIOClickEventViewController.m | 10 + .../Storyboard/MeasurementProtocol.storyboard | 223 +++++++++++++++--- .../Event/A1ViewClickEventsTest.m | 51 ++++ 3 files changed, 257 insertions(+), 27 deletions(-) diff --git a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m index 662e908f7..c34f60636 100644 --- a/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m +++ b/Example/Example/MeasurementProtocol/ClickEvent/GIOClickEventViewController.m @@ -16,6 +16,12 @@ @interface GIOClickEventViewController () @property (weak, nonatomic) IBOutlet UIButton *sendEventButton; @property (weak, nonatomic) IBOutlet UISwitch *trackEnabledSwitch; @property (weak, nonatomic) IBOutlet UISwitch *uploadEnabledSwitch; +@property (weak, nonatomic) IBOutlet UIButton *buttonA; +@property (weak, nonatomic) IBOutlet UIButton *buttonB; +@property (weak, nonatomic) IBOutlet UIButton *buttonC; +@property (weak, nonatomic) IBOutlet UIView *CView; +@property (weak, nonatomic) IBOutlet UIView *DView; +@property (weak, nonatomic) IBOutlet UIView *EView; @end @@ -29,6 +35,10 @@ - (void)viewDidLoad { 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"}]; + self.CView.growingUniqueTag = @"CCCCC"; + self.DView.growingUniqueTag = @"DDDDD"; + self.EView.growingUniqueTag = @"EEEEE"; + self.buttonA.growingUniqueTag = @"ButtonAAA"; #endif #endif } diff --git a/Example/Example/Storyboard/MeasurementProtocol.storyboard b/Example/Example/Storyboard/MeasurementProtocol.storyboard index 0d453090a..446d504aa 100644 --- a/Example/Example/Storyboard/MeasurementProtocol.storyboard +++ b/Example/Example/Storyboard/MeasurementProtocol.storyboard @@ -4,6 +4,7 @@ + @@ -441,17 +442,20 @@ - + - + - + + + + @@ -507,22 +515,22 @@ - + - + - + - + + @@ -552,31 +561,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + - + + - - - + + + + + + + + + @@ -595,7 +752,7 @@ - + @@ -910,20 +1067,20 @@ - + - + - + @@ -939,7 +1096,7 @@ - + @@ -959,7 +1116,7 @@ - + @@ -979,7 +1136,7 @@ - + @@ -1206,6 +1363,9 @@ + + + @@ -1215,11 +1375,20 @@ + + + + + + + + + diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 3489a8b57..290f1bf88 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -381,4 +381,55 @@ - (void)test09IgnoreViewClasses { XCTAssertEqualObjects(dic[@"xcontent"], @"/0/1/0/0/0"); } +- (void)test10UniqueButton { + [[viewTester usingLabel:@"协议/接口"] tap]; + [[viewTester usingLabel:@"CLICK请求"] tap]; + [MockEventQueue.sharedQueue cleanQueue]; + [[viewTester usingLabel:@"ButtonA-UniqueTag"] tap]; + [[viewTester usingLabel:@"ButtonB"] tap]; + [[viewTester usingLabel:@"ButtonC"] tap]; + NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; + XCTAssertEqual(events.count, 3); + + { + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events[0]; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"textValue"], @"ButtonA-UniqueTag"); + XCTAssertEqualObjects(dic[@"path"], @"点击事件测试"); + XCTAssertEqualObjects(dic[@"xpath"], @"/ButtonAAA"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0"); + } + + { + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events[1]; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"textValue"], @"ButtonB"); + XCTAssertEqualObjects(dic[@"path"], @"点击事件测试"); + XCTAssertEqualObjects(dic[@"xpath"], @"/CCCCC/UIButton"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/1/0"); + } + + { + GrowingViewElementEvent *event = (GrowingViewElementEvent *)events[2]; + NSDictionary *dic = event.toDictionary; + XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypeViewClick); + XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); + XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); + + XCTAssertEqualObjects(dic[@"textValue"], @"ButtonC"); + XCTAssertEqualObjects(dic[@"path"], @"点击事件测试"); + XCTAssertEqualObjects(dic[@"xpath"], @"/EEEEE/UIButton"); + XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0"); + } + [[viewTester usingLabel:@"协议/接口"] tap]; +} + @end From 20254d23c84ae3521b90385c9960aecee2d013fa Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 14 Aug 2023 20:52:54 +0800 Subject: [PATCH 074/126] fix: swiftProtobuf parse jsonObject --- Services/SwiftProtobuf/SwiftProtobuf.swift | 112 ++++++++++++++------- 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/Services/SwiftProtobuf/SwiftProtobuf.swift b/Services/SwiftProtobuf/SwiftProtobuf.swift index 55f1c735a..dafd39a6d 100644 --- a/Services/SwiftProtobuf/SwiftProtobuf.swift +++ b/Services/SwiftProtobuf/SwiftProtobuf.swift @@ -44,14 +44,52 @@ public class SwiftProtobufWrapper: NSObject { } @objc(parseFromJsonObject:) - public static func parse(from jsonObject: [String: AnyObject]) -> SwiftProtobufWrapper? { - do { - let data = try JSONSerialization.data(withJSONObject: jsonObject) - let dto = try EventDto(jsonUTF8Data: data) - return SwiftProtobufWrapper(dto) - } catch { - return nil - } + public static func parse(from jsonObject: [String: AnyObject]) -> SwiftProtobufWrapper { + var dto = EventDto() + + dto.dataSourceID = jsonObject["dataSourceId"] as? String ?? "" + dto.sessionID = jsonObject["sessionId"] as? String ?? "" + dto.timestamp = (jsonObject["timestamp"] as? NSNumber)?.int64Value ?? 0 + dto.domain = jsonObject["domain"] as? String ?? "" + dto.userID = jsonObject["userId"] as? String ?? "" + dto.deviceID = jsonObject["deviceId"] as? String ?? "" + dto.platform = jsonObject["platform"] as? String ?? "" + dto.platformVersion = jsonObject["platformVersion"] as? String ?? "" + dto.eventSequenceID = (jsonObject["eventSequenceId"] as? NSNumber)?.int32Value ?? 0 + dto.appState = jsonObject["appState"] as? String ?? "" + dto.urlScheme = jsonObject["urlScheme"] as? String ?? "" + dto.networkState = jsonObject["networkState"] as? String ?? "" + dto.screenWidth = (jsonObject["screenWidth"] as? NSNumber)?.int32Value ?? 0 + dto.screenHeight = (jsonObject["screenHeight"] as? NSNumber)?.int32Value ?? 0 + dto.deviceBrand = jsonObject["deviceBrand"] as? String ?? "" + dto.deviceModel = jsonObject["deviceModel"] as? String ?? "" + dto.deviceType = jsonObject["deviceType"] as? String ?? "" + dto.appName = jsonObject["appName"] as? String ?? "" + dto.appVersion = jsonObject["appVersion"] as? String ?? "" + dto.language = jsonObject["language"] as? String ?? "" + dto.latitude = (jsonObject["latitude"] as? NSNumber)?.doubleValue ?? 0 + dto.longitude = (jsonObject["longitude"] as? NSNumber)?.doubleValue ?? 0 + dto.sdkVersion = jsonObject["sdkVersion"] as? String ?? "" + dto.userKey = jsonObject["userKey"] as? String ?? "" + dto.eventType = self.eventType(jsonObject["eventType"] as? String ?? "") + dto.idfa = jsonObject["idfa"] as? String ?? "" + dto.idfv = jsonObject["idfv"] as? String ?? "" + dto.extraSdk = jsonObject["extraSdk"] as? Dictionary ?? [:] + dto.path = jsonObject["path"] as? String ?? "" + dto.textValue = jsonObject["textValue"] as? String ?? "" + dto.xpath = jsonObject["xpath"] as? String ?? "" + dto.xcontent = jsonObject["xcontent"] as? String ?? "" + dto.index = (jsonObject["index"] as? NSNumber)?.int32Value ?? 0 + dto.query = jsonObject["query"] as? String ?? "" + dto.hyperlink = jsonObject["hyperlink"] as? String ?? "" + dto.attributes = jsonObject["extraSdk"] as? Dictionary ?? [:] + dto.orientation = jsonObject["orientation"] as? String ?? "" + dto.title = jsonObject["title"] as? String ?? "" + dto.referralPage = jsonObject["referralPage"] as? String ?? "" + dto.protocolType = jsonObject["protocolType"] as? String ?? "" + dto.eventName = jsonObject["eventName"] as? String ?? "" + + return SwiftProtobufWrapper(dto) } @objc @@ -83,6 +121,34 @@ public class SwiftProtobufWrapper: NSObject { return nil } } + + fileprivate static func eventType(_ eventType: String) -> EventType { + if eventType == "VISIT" { + return .visit + } else if eventType == "CUSTOM" { + return .custom + } else if eventType == "VISITOR_ATTRIBUTES" { + return .visitorAttributes + } else if eventType == "LOGIN_USER_ATTRIBUTES" { + return .loginUserAttributes + } else if eventType == "CONVERSION_VARIABLES" { + return .conversionVariables + } else if eventType == "APP_CLOSED" { + return .appClosed + } else if eventType == "PAGE" { + return .page + } else if eventType == "VIEW_CLICK" { + return .viewClick + } else if eventType == "VIEW_CHANGE" { + return .viewChange + } else if eventType == "FORM_SUBMIT" { + return .formSubmit + } else if eventType == "ACTIVATE" { + return .activate + } + + return .UNRECOGNIZED(100) + } } extension SwiftProtobufWrapper { @@ -135,7 +201,7 @@ extension GrowingBaseEvent { dto.sdkVersion = self.sdkVersion dto.userKey = self.userKey ?? "" - dto.eventType = eventType() + dto.eventType = SwiftProtobufWrapper.eventType(self.eventType) dto.idfa = idfa() dto.idfv = idfv() dto.extraSdk = extraSdk() @@ -158,34 +224,6 @@ extension GrowingBaseEvent { } extension GrowingBaseEvent { - fileprivate func eventType() -> EventType { - if self.eventType == "VISIT" { - return .visit - } else if self.eventType == "CUSTOM" { - return .custom - } else if self.eventType == "VISITOR_ATTRIBUTES" { - return .visitorAttributes - } else if self.eventType == "LOGIN_USER_ATTRIBUTES" { - return .loginUserAttributes - } else if self.eventType == "CONVERSION_VARIABLES" { - return .conversionVariables - } else if self.eventType == "APP_CLOSED" { - return .appClosed - } else if self.eventType == "PAGE" { - return .page - } else if self.eventType == "VIEW_CLICK" { - return .viewClick - } else if self.eventType == "VIEW_CHANGE" { - return .viewChange - } else if self.eventType == "FORM_SUBMIT" { - return .formSubmit - } else if self.eventType == "ACTIVATE" { - return .activate - } - - return .UNRECOGNIZED(100) - } - fileprivate func idfa() -> String { let selector = Selector(("idfa")) if self.responds(to: selector) { From 7413f6e1d9c9ef29cf615c4af80118a82d45b525 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 14 Aug 2023 12:53:39 +0000 Subject: [PATCH 075/126] style: code format --- Services/SwiftProtobuf/SwiftProtobuf.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Services/SwiftProtobuf/SwiftProtobuf.swift b/Services/SwiftProtobuf/SwiftProtobuf.swift index dafd39a6d..1e13279f8 100644 --- a/Services/SwiftProtobuf/SwiftProtobuf.swift +++ b/Services/SwiftProtobuf/SwiftProtobuf.swift @@ -74,7 +74,7 @@ public class SwiftProtobufWrapper: NSObject { dto.eventType = self.eventType(jsonObject["eventType"] as? String ?? "") dto.idfa = jsonObject["idfa"] as? String ?? "" dto.idfv = jsonObject["idfv"] as? String ?? "" - dto.extraSdk = jsonObject["extraSdk"] as? Dictionary ?? [:] + dto.extraSdk = jsonObject["extraSdk"] as? [String: String] ?? [:] dto.path = jsonObject["path"] as? String ?? "" dto.textValue = jsonObject["textValue"] as? String ?? "" dto.xpath = jsonObject["xpath"] as? String ?? "" @@ -82,7 +82,7 @@ public class SwiftProtobufWrapper: NSObject { dto.index = (jsonObject["index"] as? NSNumber)?.int32Value ?? 0 dto.query = jsonObject["query"] as? String ?? "" dto.hyperlink = jsonObject["hyperlink"] as? String ?? "" - dto.attributes = jsonObject["extraSdk"] as? Dictionary ?? [:] + dto.attributes = jsonObject["extraSdk"] as? [String: String] ?? [:] dto.orientation = jsonObject["orientation"] as? String ?? "" dto.title = jsonObject["title"] as? String ?? "" dto.referralPage = jsonObject["referralPage"] as? String ?? "" @@ -121,7 +121,7 @@ public class SwiftProtobufWrapper: NSObject { return nil } } - + fileprivate static func eventType(_ eventType: String) -> EventType { if eventType == "VISIT" { return .visit From f7b75b6f47b93c694387dd807d1cabce93ba0928 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 15 Aug 2023 15:07:36 +0800 Subject: [PATCH 076/126] fix: swiftProtobuf toJsonObject VISIT eventType --- .../Protobuf/GrowingEventProtobufPersistence.m | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Services/Protobuf/GrowingEventProtobufPersistence.m b/Services/Protobuf/GrowingEventProtobufPersistence.m index 022dc1c2a..bb7f5545e 100644 --- a/Services/Protobuf/GrowingEventProtobufPersistence.m +++ b/Services/Protobuf/GrowingEventProtobufPersistence.m @@ -120,13 +120,23 @@ + (NSData *)buildRawEventsFromJsonObjects:(NSArray *)jsonObjects - (id)toJSONObject { #if SWIFT_PACKAGE - return self.dtoBox.toJsonObject; + if (self.dtoBox) { + NSDictionary *jsonObject = self.dtoBox.toJsonObject; + if ([self.eventType isEqualToString:@"VISIT"] + && [jsonObject isKindOfClass:[NSDictionary class]]) { + // 由于VISIT在SwiftProtobuf中默认值为0,转JSON会丢失eventType + NSMutableDictionary *jsonObjectM = [NSMutableDictionary dictionaryWithDictionary:jsonObject]; + [jsonObjectM setObject:@"VISIT" forKey:@"eventType"]; + return jsonObjectM; + } + return jsonObject; + } #else - if (!self.dto) { - return [NSDictionary dictionary]; + if (self.dto) { + return self.dto.growingHelper_jsonObject; } - return self.dto.growingHelper_jsonObject; #endif + return @{}; } - (void)appendExtraParams:(NSDictionary *)extraParams { From 261535134b53dd8c748c75b52abd9691c434eb9a Mon Sep 17 00:00:00 2001 From: runner Date: Tue, 15 Aug 2023 07:08:21 +0000 Subject: [PATCH 077/126] style: code format --- Services/Protobuf/GrowingEventProtobufPersistence.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Services/Protobuf/GrowingEventProtobufPersistence.m b/Services/Protobuf/GrowingEventProtobufPersistence.m index bb7f5545e..3973956bc 100644 --- a/Services/Protobuf/GrowingEventProtobufPersistence.m +++ b/Services/Protobuf/GrowingEventProtobufPersistence.m @@ -122,8 +122,7 @@ - (id)toJSONObject { #if SWIFT_PACKAGE if (self.dtoBox) { NSDictionary *jsonObject = self.dtoBox.toJsonObject; - if ([self.eventType isEqualToString:@"VISIT"] - && [jsonObject isKindOfClass:[NSDictionary class]]) { + if ([self.eventType isEqualToString:@"VISIT"] && [jsonObject isKindOfClass:[NSDictionary class]]) { // 由于VISIT在SwiftProtobuf中默认值为0,转JSON会丢失eventType NSMutableDictionary *jsonObjectM = [NSMutableDictionary dictionaryWithDictionary:jsonObject]; [jsonObjectM setObject:@"VISIT" forKey:@"eventType"]; From aa10fda366efe2879ed9d9870078cff7ff7e1a40 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 17 Aug 2023 11:22:33 +0800 Subject: [PATCH 078/126] ci: workflows should use GIOSDK_PAT --- Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile.lock b/Podfile.lock index 2d7e60da3..edb643166 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -150,7 +150,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - GrowingAnalytics: 8cae5a0b3a8785c219e4c6ea8ddf8af59d0a37ba + GrowingAnalytics: 926677553410bebc3a1e8d6fd90f816c7913fc44 GrowingAPM: 79fe4f4a12d94432fa4a552d56c41940ea13961a GrowingToolsKit: 9c0d6e41c9678397dbaa3304b1738a2867b023ae GrowingUtils: 5212c5c0501ea0c3863a29c33ccefbde5be77353 From 10470ddcd4a1f32ec2921b7bd78172733e4952e2 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 17 Aug 2023 11:30:36 +0800 Subject: [PATCH 079/126] test: format action --- GrowingTracker/GrowingTracker.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GrowingTracker/GrowingTracker.m b/GrowingTracker/GrowingTracker.m index 7b9a65885..edc35968d 100644 --- a/GrowingTracker/GrowingTracker.m +++ b/GrowingTracker/GrowingTracker.m @@ -34,9 +34,16 @@ - (instancetype)initWithRealTracker:(GrowingRealTracker *)realTracker { return self; } -+ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions { ++ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions + + + + + { if (![NSThread isMainThread]) { - @throw [NSException + @throw [NSException + + exceptionWithName:@"初始化异常" reason:@"请在applicationDidFinishLaunching中调用startWithConfiguration函数,并且确保在主线程中" userInfo:nil]; From 04b85d849b60d85a6b47e5a690a91501c63c7508 Mon Sep 17 00:00:00 2001 From: GIOSDK Date: Thu, 17 Aug 2023 03:31:39 +0000 Subject: [PATCH 080/126] style: code format --- GrowingTracker/GrowingTracker.m | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/GrowingTracker/GrowingTracker.m b/GrowingTracker/GrowingTracker.m index edc35968d..8517a3071 100644 --- a/GrowingTracker/GrowingTracker.m +++ b/GrowingTracker/GrowingTracker.m @@ -34,15 +34,12 @@ - (instancetype)initWithRealTracker:(GrowingRealTracker *)realTracker { return self; } -+ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions ++ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration + launchOptions:(NSDictionary *)launchOptions - - - - { +{ if (![NSThread isMainThread]) { - @throw [NSException - + @throw [NSException exceptionWithName:@"初始化异常" reason:@"请在applicationDidFinishLaunching中调用startWithConfiguration函数,并且确保在主线程中" From da502695a060a1ff544f85ab4cb8a8bae9224b86 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 17 Aug 2023 11:34:34 +0800 Subject: [PATCH 081/126] style: code format --- GrowingTracker/GrowingTracker.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/GrowingTracker/GrowingTracker.m b/GrowingTracker/GrowingTracker.m index 8517a3071..7b9a65885 100644 --- a/GrowingTracker/GrowingTracker.m +++ b/GrowingTracker/GrowingTracker.m @@ -34,13 +34,9 @@ - (instancetype)initWithRealTracker:(GrowingRealTracker *)realTracker { return self; } -+ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration - launchOptions:(NSDictionary *)launchOptions - -{ ++ (void)startWithConfiguration:(GrowingTrackConfiguration *)configuration launchOptions:(NSDictionary *)launchOptions { if (![NSThread isMainThread]) { @throw [NSException - exceptionWithName:@"初始化异常" reason:@"请在applicationDidFinishLaunching中调用startWithConfiguration函数,并且确保在主线程中" userInfo:nil]; From 321f94c76026dd1799dc9599ac96598133e7b0a3 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 17 Aug 2023 14:36:19 +0800 Subject: [PATCH 082/126] =?UTF-8?q?fix:=20page.path=20=E5=89=8D=E5=8A=A0?= =?UTF-8?q?=E6=96=9C=E6=9D=86=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m | 3 ++- GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m | 3 ++- GrowingAutotrackerCore/Page/GrowingPageManager.m | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m index 163df9358..8a7ba1c53 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewChangeProvider.m @@ -53,7 +53,8 @@ + (void)viewOnChange:(UIView *)view { } if (autotrackPage) { - builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes); + builder.setPath([NSString stringWithFormat:@"/%@", autotrackPage.alias]) + .setAttributes(autotrackPage.attributes); } [[GrowingEventManager sharedInstance] postEventBuilder:builder]; diff --git a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m index aba80766a..7430b4827 100644 --- a/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m +++ b/GrowingAutotrackerCore/GrowingNode/GrowingViewClickProvider.m @@ -53,7 +53,8 @@ + (void)viewOnClick:(UIView *)view { } if (autotrackPage) { - builder.setPath(autotrackPage.alias).setAttributes(autotrackPage.attributes); + builder.setPath([NSString stringWithFormat:@"/%@", autotrackPage.alias]) + .setAttributes(autotrackPage.attributes); } [[GrowingEventManager sharedInstance] postEventBuilder:builder]; diff --git a/GrowingAutotrackerCore/Page/GrowingPageManager.m b/GrowingAutotrackerCore/Page/GrowingPageManager.m index 56590926a..a1e02542a 100644 --- a/GrowingAutotrackerCore/Page/GrowingPageManager.m +++ b/GrowingAutotrackerCore/Page/GrowingPageManager.m @@ -100,7 +100,7 @@ - (GrowingPage *)createdViewControllerPage:(UIViewController *)controller { - (void)sendPageEventWithPage:(GrowingPage *)page { GrowingBaseBuilder *builder = GrowingPageEvent.builder.setTitle(page.title) - .setPath(page.alias) + .setPath([NSString stringWithFormat:@"/%@", page.alias]) .setTimestamp(page.showTimestamp) .setAttributes(page.attributes); [[GrowingEventManager sharedInstance] postEventBuilder:builder]; From 3b663cd2cd1c1f93424fd0a59a8cc59ce3e7823d Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 17 Aug 2023 15:00:08 +0800 Subject: [PATCH 083/126] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=20GrowingPage?= =?UTF-8?q?Event=20=E5=AF=B9=E8=B1=A1=E4=B8=AD=E7=9A=84=20pageName=20?= =?UTF-8?q?=E4=B8=BA=20path=20ci:=20update=20ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../A0GrowingAnalyticsTest.m | 8 +++--- .../Event/A1ViewClickEventsTest.m | 6 ++--- .../AutotrackerTests/Event/A3PageEventsTest.m | 26 +++++++++---------- .../ProtobufTests/ProtobufEventsTest.m | 8 +++--- .../WebCircleTests/WebCircleTest.m | 2 +- .../TrackerCoreTests/EventTests/EventTest.m | 6 ++--- .../UIViewController+GrowingAutotracker.m | 12 ++++----- .../Event/Autotrack/GrowingPageCustomEvent.h | 2 +- .../Event/Autotrack/GrowingPageCustomEvent.m | 4 +-- .../Event/Autotrack/GrowingPageEvent.h | 4 +-- .../Event/Autotrack/GrowingPageEvent.m | 6 ++--- .../Event/Autotrack/GrowingViewElementEvent.h | 2 +- .../Event/Autotrack/GrowingViewElementEvent.m | 4 +-- .../Catagory/GrowingBaseEvent+Protobuf.m | 2 +- Services/SwiftProtobuf/SwiftProtobuf.swift | 8 ++---- 15 files changed, 48 insertions(+), 52 deletions(-) diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m index 855cbfdd5..d85dbb556 100644 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m +++ b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m @@ -662,12 +662,12 @@ - (void)testAutotrackPageWithoutAttributesTest { GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); - XCTAssertEqualObjects(event.pageName, @"XCTest"); + XCTAssertEqualObjects(event.path, @"/XCTest"); XCTAssertEqualObjects(event.attributes[@"key"], nil); NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); - XCTAssertEqualObjects(dic[@"path"], @"XCTest"); + XCTAssertEqualObjects(dic[@"path"], @"/XCTest"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], nil); [expectation fulfill]; @@ -704,12 +704,12 @@ - (void)testAutotrackPageWithAttributesTest { GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); - XCTAssertEqualObjects(event.pageName, @"XCTest"); + XCTAssertEqualObjects(event.path, @"/XCTest"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); - XCTAssertEqualObjects(dic[@"path"], @"XCTest"); + XCTAssertEqualObjects(dic[@"path"], @"/XCTest"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); [expectation fulfill]; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 290f1bf88..125719315 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -399,7 +399,7 @@ - (void)test10UniqueButton { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"ButtonA-UniqueTag"); - XCTAssertEqualObjects(dic[@"path"], @"点击事件测试"); + XCTAssertEqualObjects(dic[@"path"], @"/点击事件测试"); XCTAssertEqualObjects(dic[@"xpath"], @"/ButtonAAA"); XCTAssertEqualObjects(dic[@"xcontent"], @"/0"); } @@ -412,7 +412,7 @@ - (void)test10UniqueButton { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"ButtonB"); - XCTAssertEqualObjects(dic[@"path"], @"点击事件测试"); + XCTAssertEqualObjects(dic[@"path"], @"/点击事件测试"); XCTAssertEqualObjects(dic[@"xpath"], @"/CCCCC/UIButton"); XCTAssertEqualObjects(dic[@"xcontent"], @"/1/0"); } @@ -425,7 +425,7 @@ - (void)test10UniqueButton { XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); XCTAssertEqualObjects(dic[@"textValue"], @"ButtonC"); - XCTAssertEqualObjects(dic[@"path"], @"点击事件测试"); + XCTAssertEqualObjects(dic[@"path"], @"/点击事件测试"); XCTAssertEqualObjects(dic[@"xpath"], @"/EEEEE/UIButton"); XCTAssertEqualObjects(dic[@"xcontent"], @"/0/0"); } diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m index dde856e72..4508e3e32 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m @@ -60,14 +60,14 @@ - (void)test01AutotrackPage { GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); - XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.path, @"/页面测试"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -81,7 +81,7 @@ - (void)test01AutotrackPage { XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); XCTAssertEqualObjects( dic[@"xpath"], @@ -127,14 +127,14 @@ - (void)test02AutotrackPageDelay { GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); - XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.path, @"/页面测试"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -150,7 +150,7 @@ - (void)test02AutotrackPageDelay { XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); XCTAssertEqualObjects( dic[@"xpath"], @@ -189,7 +189,7 @@ - (void)test03AutotrackPageWithoutCallSuperViewDidAppear { XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); XCTAssertEqualObjects( dic[@"xpath"], @@ -235,14 +235,14 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); - XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.path, @"/页面测试"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -258,7 +258,7 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); XCTAssertEqualObjects( dic[@"xpath"], @@ -290,14 +290,14 @@ - (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); - XCTAssertEqualObjects(event.pageName, @"页面测试"); + XCTAssertEqualObjects(event.path, @"/页面测试"); XCTAssertEqualObjects(event.attributes[@"key"], @"value"); NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value"); } @@ -313,7 +313,7 @@ - (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { XCTAssertTrue([ManualTrackHelper viewClickEventCheck:dic]); XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]); - XCTAssertEqualObjects(dic[@"path"], @"页面测试"); + XCTAssertEqualObjects(dic[@"path"], @"/页面测试"); XCTAssertEqualObjects(dic[@"textValue"], @"Button"); XCTAssertEqualObjects( dic[@"xpath"], diff --git a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m index 196eea464..d6880c26a 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/ProtobufTests/ProtobufEventsTest.m @@ -265,7 +265,7 @@ - (void)testEventConvertToPB_Page { [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypePage, event.eventType); XCTAssertEqual(GrowingPBEventType_Page, protobuf.eventType); - XCTAssertEqualObjects(event.pageName ?: @"", protobuf.path); + XCTAssertEqualObjects(event.path ?: @"", protobuf.path); XCTAssertEqualObjects(event.orientation ?: @"", protobuf.orientation); XCTAssertEqualObjects(event.title ?: @"", protobuf.title); XCTAssertEqualObjects(event.referralPage ?: @"", protobuf.referralPage); @@ -277,7 +277,7 @@ - (void)testEventConvertToPB_Page { [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypePage, event.eventType); XCTAssertEqual(GrowingPBEventType_Page, protobuf.eventType); - XCTAssertEqualObjects(event.pageName ?: @"", protobuf.path); + XCTAssertEqualObjects(event.path ?: @"", protobuf.path); XCTAssertEqualObjects(event.orientation ?: @"", protobuf.orientation); XCTAssertEqualObjects(event.title ?: @"", protobuf.title); XCTAssertEqualObjects(event.referralPage ?: @"", protobuf.referralPage); @@ -298,7 +298,7 @@ - (void)testEventConvertToPB_Page { [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypePage, event.eventType); XCTAssertEqual(GrowingPBEventType_Page, protobuf.eventType); - XCTAssertEqualObjects(event.pageName ?: @"", protobuf.path); + XCTAssertEqualObjects(event.path ?: @"", protobuf.path); XCTAssertEqualObjects(event.orientation ?: @"", protobuf.orientation); XCTAssertEqualObjects(event.title ?: @"", protobuf.title); XCTAssertEqualObjects(event.referralPage ?: @"", protobuf.referralPage); @@ -312,7 +312,7 @@ - (void)testEventConvertToPB_Page { [self contrastOfDefaultParamter:event protobuf:protobuf]; XCTAssertEqualObjects(GrowingEventTypePage, event.eventType); XCTAssertEqual(GrowingPBEventType_Page, protobuf.eventType); - XCTAssertEqualObjects(event.pageName ?: @"", protobuf.path); + XCTAssertEqualObjects(event.path ?: @"", protobuf.path); XCTAssertEqualObjects(event.orientation ?: @"", protobuf.orientation); XCTAssertEqualObjects(event.title ?: @"", protobuf.title); XCTAssertEqualObjects(event.referralPage ?: @"", protobuf.referralPage); diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index eef883f9f..555c59f0a 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -218,7 +218,7 @@ - (void)test07Hybrid { [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; // 尝试通过tapPoint点击到html中的button - [viewTester tapScreenAtPoint:CGPointMake(100, 200)]; + [viewTester tapScreenAtPoint:CGPointMake(100, 300)]; XCTestExpectation *expectation = [self expectationWithDescription:@"WebCircle Test failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m index 9f1443866..6ce9278b7 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/EventTests/EventTest.m @@ -203,7 +203,7 @@ - (void)testGrowingAppCloseEvent { - (void)testGrowingPageEvent { NSString *orientation = self.deviceOrientation; - GrowingBaseBuilder *builder = GrowingPageEvent.builder.setPath(@"path") + GrowingBaseBuilder *builder = GrowingPageEvent.builder.setPath(@"/path") .setOrientation(orientation) .setTitle(@"title") .setReferralPage(@"referralPage") @@ -222,7 +222,7 @@ - (void)testGrowingPageEvent { GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject; XCTAssertEqualObjects(event.eventType, GrowingEventTypePage); - XCTAssertEqualObjects(event.pageName, @"path"); + XCTAssertEqualObjects(event.path, @"/path"); XCTAssertEqualObjects(event.orientation, orientation); XCTAssertEqualObjects(event.title, @"title"); XCTAssertEqualObjects(event.referralPage, @"referralPage"); @@ -230,7 +230,7 @@ - (void)testGrowingPageEvent { NSDictionary *dic = event.toDictionary; XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage); - XCTAssertEqualObjects(dic[@"path"], @"path"); + XCTAssertEqualObjects(dic[@"path"], @"/path"); XCTAssertEqualObjects(dic[@"orientation"], orientation); XCTAssertEqualObjects(dic[@"title"], @"title"); XCTAssertEqualObjects(dic[@"referralPage"], @"referralPage"); diff --git a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m index 0e4c1d666..a8aa7ca3a 100644 --- a/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m +++ b/GrowingAutotrackerCore/Autotrack/UIViewController+GrowingAutotracker.m @@ -27,14 +27,14 @@ @implementation UIViewController (GrowingAutotracker) - (nullable NSString *)growingPageTitle { - NSString *currentPageName = self.title; - if (!currentPageName.length) { - currentPageName = self.navigationItem.title; + NSString *title = self.title; + if (!title.length) { + title = self.navigationItem.title; } - if (!currentPageName.length) { - currentPageName = self.tabBarItem.title; + if (!title.length) { + title = self.tabBarItem.title; } - return currentPageName; + return title; } - (void)setGrowingPageObject:(GrowingPage *)page { diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h index 0369e8729..d0bacbede 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.h @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingPageCustomBuilder : GrowingCustomBuilder -@property (nonatomic, copy, readonly) NSString *pageName; +@property (nonatomic, copy, readonly) NSString *path; - (GrowingPageCustomBuilder * (^)(NSString *value))setPath; diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m index ad78b7992..b572e06fc 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m +++ b/GrowingTrackerCore/Event/Autotrack/GrowingPageCustomEvent.m @@ -28,7 +28,7 @@ + (GrowingPageCustomBuilder *)builder { - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { if (self = [super initWithBuilder:builder]) { GrowingPageCustomBuilder *subBuilder = (GrowingPageCustomBuilder *)builder; - _path = subBuilder.pageName; + _path = subBuilder.path; } return self; } @@ -47,7 +47,7 @@ @implementation GrowingPageCustomBuilder - (GrowingPageCustomBuilder * (^)(NSString *value))setPath { return ^(NSString *value) { - self->_pageName = value; + self->_path = value; return self; }; } diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h index d1b835bcb..6c266da76 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingPageEvent : GrowingBaseAttributesEvent -@property (nonatomic, copy, readonly) NSString *pageName; +@property (nonatomic, copy, readonly) NSString *path; @property (nonatomic, copy, readonly) NSString *orientation; @property (nonatomic, copy, readonly) NSString *title; @property (nonatomic, copy, readonly) NSString *referralPage; @@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingPageBuilder : GrowingBaseAttributesBuilder -@property (nonatomic, copy, readonly) NSString *pageName; +@property (nonatomic, copy, readonly) NSString *path; @property (nonatomic, copy, readonly) NSString *orientation; @property (nonatomic, copy, readonly) NSString *title; @property (nonatomic, copy, readonly) NSString *referralPage; diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.m b/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.m index 9acf5063c..4353c6cb6 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.m +++ b/GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.m @@ -25,7 +25,7 @@ @implementation GrowingPageEvent - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { if (self = [super initWithBuilder:builder]) { GrowingPageBuilder *subBuilder = (GrowingPageBuilder *)builder; - _pageName = subBuilder.pageName; + _path = subBuilder.path; _orientation = subBuilder.orientation; _title = subBuilder.title; _referralPage = subBuilder.referralPage; @@ -35,7 +35,7 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { - (NSDictionary *)toDictionary { NSMutableDictionary *dataDictM = [NSMutableDictionary dictionaryWithDictionary:[super toDictionary]]; - dataDictM[@"path"] = self.pageName; + dataDictM[@"path"] = self.path; dataDictM[@"orientation"] = self.orientation; dataDictM[@"title"] = self.title; dataDictM[@"referralPage"] = self.referralPage; @@ -59,7 +59,7 @@ - (void)readPropertyInTrackThread { - (GrowingPageBuilder * (^)(NSString *value))setPath { return ^(NSString *value) { - self->_pageName = value; + self->_path = value; return self; }; } diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h index 4d19250ff..861b17d09 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GrowingViewElementBuilder : GrowingBaseAttributesBuilder -@property (nonatomic, copy, readonly) NSString *pageName; +@property (nonatomic, copy, readonly) NSString *path; @property (nonatomic, copy, readonly) NSString *textValue; @property (nonatomic, copy, readonly) NSString *xpath; @property (nonatomic, copy, readonly) NSString *xcontent; diff --git a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m index 3ed2107cc..890e7ef7d 100644 --- a/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m +++ b/GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.m @@ -28,7 +28,7 @@ + (GrowingViewElementBuilder *)builder { - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder { if (self = [super initWithBuilder:builder]) { GrowingViewElementBuilder *subBuilder = (GrowingViewElementBuilder *)builder; - _path = subBuilder.pageName; + _path = subBuilder.path; _textValue = subBuilder.textValue; _xpath = subBuilder.xpath; _xcontent = subBuilder.xcontent; @@ -55,7 +55,7 @@ @implementation GrowingViewElementBuilder - (GrowingViewElementBuilder * (^)(NSString *value))setPath { return ^(NSString *value) { - self->_pageName = value; + self->_path = value; return self; }; } diff --git a/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m index 5e47fd7f2..5046fc590 100644 --- a/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m +++ b/Services/Protobuf/Catagory/GrowingBaseEvent+Protobuf.m @@ -84,7 +84,7 @@ - (GrowingPBEventV3Dto *)toProtobuf { dto.idfa = stringBlock(@"idfa"); dto.idfv = stringBlock(@"idfv"); dto.extraSdk = dicBlock(@"extraSdk").mutableCopy; - dto.path = stringBlock(@"pageName").length > 0 ? stringBlock(@"pageName") : stringBlock(@"path"); + dto.path = stringBlock(@"path"); dto.textValue = stringBlock(@"textValue"); dto.xpath = stringBlock(@"xpath"); dto.xcontent = stringBlock(@"xcontent"); diff --git a/Services/SwiftProtobuf/SwiftProtobuf.swift b/Services/SwiftProtobuf/SwiftProtobuf.swift index 1e13279f8..4fa1a15ee 100644 --- a/Services/SwiftProtobuf/SwiftProtobuf.swift +++ b/Services/SwiftProtobuf/SwiftProtobuf.swift @@ -252,12 +252,8 @@ extension GrowingBaseEvent { } fileprivate func path() -> String { - if self.responds(to: Selector(("pageName"))) { - let selector = Selector(("pageName")) - let imp: IMP = method_getImplementation(class_getInstanceMethod(type(of: self), selector)!) - return unsafeBitCast(imp, to: (@convention(c)(GrowingBaseEvent, Selector) -> String?).self)(self, selector) ?? "" - } else if self.responds(to: Selector(("path"))) { - let selector = Selector(("path")) + let selector = Selector(("path")) + if self.responds(to: selector) { let imp: IMP = method_getImplementation(class_getInstanceMethod(type(of: self), selector)!) return unsafeBitCast(imp, to: (@convention(c)(GrowingBaseEvent, Selector) -> String?).self)(self, selector) ?? "" } From 2a5caf276b0bb0f0f68d3df0c369791eb37a7246 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Thu, 17 Aug 2023 15:24:47 +0800 Subject: [PATCH 084/126] =?UTF-8?q?ci:=20=E5=87=8F=E5=B0=91=E8=80=97?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../A0GrowingAnalyticsTest.m | 18 ++++++------ .../UITapGestureRecognizerAutotrackTest.m | 1 - .../Event/A1ViewClickEventsTest.m | 19 ++----------- .../Event/A2ViewChangeEventsTest.m | 4 --- .../AutotrackerTests/Event/A3PageEventsTest.m | 10 ------- .../HybridTests/HybridTest_HostApp.m | 28 +++++++++---------- .../WebCircleTests/WebCircleTest.m | 5 ++-- .../ManagerTests/GrowingSessionTest.m | 2 +- 8 files changed, 29 insertions(+), 58 deletions(-) diff --git a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m index d85dbb556..b4af5cf7d 100644 --- a/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m +++ b/Example/GrowingAnalyticsTests/A0GrowingAnalyticsTest.m @@ -41,7 +41,7 @@ + (void)setUp { GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"test"]; configuration.dataSourceId = @"test"; configuration.idMappingEnabled = YES; - configuration.sessionInterval = 10.0f; + configuration.sessionInterval = 3.0f; configuration.urlScheme = @"growing.xctest"; [GrowingAutotracker startWithConfiguration:configuration launchOptions:nil]; } @@ -202,7 +202,7 @@ - (void)testTrackCustomEventWithAttributes { - (void)testTrackTimer { { NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; @@ -244,7 +244,7 @@ - (void)testTrackTimer { // wrong timerId [MockEventQueue.sharedQueue cleanQueue]; [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName"]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); @@ -256,7 +256,7 @@ - (void)testTrackTimer { // remove timer [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] removeTimer:timerId]; [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; @@ -267,7 +267,7 @@ - (void)testTrackTimer { // clear all timers [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] clearTrackTimer]; [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; @@ -361,7 +361,7 @@ - (void)testTrackTimer { - (void)testTrackTimerWithAttributes { { NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; @@ -377,7 +377,7 @@ - (void)testTrackTimerWithAttributes { // wrong timerId [MockEventQueue.sharedQueue cleanQueue]; [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] trackTimerEnd:@"eventName" withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 0); @@ -389,7 +389,7 @@ - (void)testTrackTimerWithAttributes { // remove timer [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] removeTimer:timerId]; [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; @@ -400,7 +400,7 @@ - (void)testTrackTimerWithAttributes { // clear all timers [MockEventQueue.sharedQueue cleanQueue]; NSString *timerId = [[GrowingAutotracker sharedInstance] trackTimerStart:@"eventName"]; - usleep(1000); + usleep(100); [[GrowingAutotracker sharedInstance] clearTrackTimer]; [[GrowingAutotracker sharedInstance] trackTimerEnd:timerId withAttributes:@{@"key": @"value"}]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m index 0108659b5..bc472eab3 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Autotrack/UITapGestureRecognizerAutotrackTest.m @@ -41,7 +41,6 @@ - (void)beforeAll { [[viewTester usingLabel:@"协议/接口"] tap]; [[viewTester usingLabel:@"CLICK请求"] tap]; - [viewTester waitForTimeInterval:1]; } - (void)afterAll { diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m index 125719315..afe530363 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A1ViewClickEventsTest.m @@ -61,9 +61,7 @@ - (void)checkWebCirclePathWithView:(UIView *)view - (void)test01AlertButtonClick { // 对话框按钮点击,检测click事件 [[viewTester usingLabel:@"AttributeLabel"] tap]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"ShowAlert"] tap]; - [viewTester waitForAnimationsToFinish]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"取消"]; NSString *xpathForView = @@ -112,7 +110,6 @@ - (void)test01AlertButtonClick { - (void)test02ClickDoNotTrack { [[viewTester usingLabel:@"AttributeLabel"] tap]; - [viewTester waitForAnimationsToFinish]; [MockEventQueue.sharedQueue cleanQueue]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"GIODontTrackBtn"]; @@ -156,7 +153,6 @@ - (void)test02ClickDoNotTrack { - (void)test03ButtonWithImageViewClick { // 单击ButtonWithImageView,检测click事件 [[viewTester usingLabel:@"Simple UI Elements"] tap]; - [viewTester waitForAnimationsToFinish]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"Food"]; NSString *xpathForView = @@ -189,7 +185,6 @@ - (void)test03ButtonWithImageViewClick { - (void)test04UIViewButtonClick { // 单击UIViewButton,检测click事件 [[viewTester usingLabel:@"Simple UI Elements"] tap]; - [viewTester waitForAnimationsToFinish]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"Fire"]; NSString *xpathForView = @@ -222,7 +217,6 @@ - (void)test04UIViewButtonClick { - (void)test05UISegmentedControlClick { // 单击UISegmentedControl,检测click事件 [[viewTester usingLabel:@"Simple UI Elements"] tap]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"SecondSegment"] tap]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"ThirdSegment"]; @@ -236,7 +230,6 @@ - (void)test05UISegmentedControlClick { xcontent:xcontentForView originxcontent:originxcontentForView]; [actor tap]; - [viewTester waitForAnimationsToFinish]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 3); @@ -257,7 +250,6 @@ - (void)test05UISegmentedControlClick { - (void)test06ClickCustomContent { // 单击自定义content的UISegmentedControl,检测textValue [[viewTester usingLabel:@"Simple UI Elements"] tap]; - [viewTester waitForAnimationsToFinish]; [MockEventQueue.sharedQueue cleanQueue]; @@ -289,7 +281,6 @@ - (void)test06ClickCustomContent { - (void)test07UITableViewHeaderFooterViewButtonClick { // 单击UITableViewHeaderFooterView上的Button,检测click事件 [[viewTester usingLabel:@"协议/接口"] tap]; - [viewTester waitForAnimationsToFinish]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"header1"]; NSString *xpathForView = @@ -321,11 +312,8 @@ - (void)test07UITableViewHeaderFooterViewButtonClick { - (void)test08IgnoreViewClass { [[viewTester usingLabel:@"IgnoreViewClass"] tap]; - [viewTester waitForAnimationsToFinish]; - [[viewTester usingLabel:@"ignoreViewClass"] tap]; - [viewTester waitForAnimationsToFinish]; - + [MockEventQueue.sharedQueue cleanQueue]; [[viewTester usingLabel:@"IgnoreButton1"] tap]; @@ -352,11 +340,8 @@ - (void)test08IgnoreViewClass { - (void)test09IgnoreViewClasses { [[viewTester usingLabel:@"IgnoreViewClass"] tap]; - [viewTester waitForAnimationsToFinish]; - [[viewTester usingLabel:@"ignoreViewClasses"] tap]; - [viewTester waitForAnimationsToFinish]; - + [MockEventQueue.sharedQueue cleanQueue]; [[viewTester usingLabel:@"IgnoreButton1"] tap]; diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m index 5edaf3d11..3caaf9f6a 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A2ViewChangeEventsTest.m @@ -33,7 +33,6 @@ - (void)setUp { - (void)test01TextFields { [[viewTester usingLabel:@"UI界面"] tap]; [[viewTester usingLabel:@"Text Fields"] tap]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"fisrtTF"] tap]; [[viewTester usingFirstResponder] enterText:@"Good"]; [[viewTester usingFirstResponder].view resignFirstResponder]; @@ -53,7 +52,6 @@ - (void)test01TextFields { - (void)test02TextFieldsIgnore { [[viewTester usingLabel:@"UI界面"] tap]; [[viewTester usingLabel:@"Text Fields"] tap]; - [viewTester waitForAnimationsToFinish]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"fisrtTF"]; { @@ -88,7 +86,6 @@ - (void)test02TextFieldsIgnore { - (void)test03DataPicker { [[viewTester usingLabel:@"协议/接口"] tap]; [[viewTester usingLabel:@"VIEW_CHANGE请求"] tap]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"dataPickerOper"] tap]; NSArray *date = @[@"June", @"10", @"2019"]; @@ -104,7 +101,6 @@ - (void)test03DataPicker { - (void)test04Slider { [[viewTester usingLabel:@"UI界面"] tap]; [[viewTester usingLabel:@"Simple UI Elements"] tap]; - [viewTester waitForAnimationsToFinish]; KIFUIViewTestActor *actor = [viewTester usingLabel:@"defaultSlider"]; { diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m index 4508e3e32..54c0864a8 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/AutotrackerTests/Event/A3PageEventsTest.m @@ -49,9 +49,7 @@ - (void)tearDown { - (void)test01AutotrackPage { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; { @@ -93,9 +91,7 @@ - (void)test01AutotrackPage { - (void)test02AutotrackPageDelay { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; // 立即点击按钮,由于尚未调用autotrackPage,path字段无值 @@ -166,9 +162,7 @@ - (void)test02AutotrackPageDelay { - (void)test03AutotrackPageWithoutCallSuperViewDidAppear { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; // 不兼容在viewDidLoad调用autotrackPage,却未调用super viewDidAppear的情况 @@ -201,9 +195,7 @@ - (void)test03AutotrackPageWithoutCallSuperViewDidAppear { - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; // 立即点击按钮,走findPageByView内部的补page逻辑,由于尚未调用autotrackPage,path字段无值 @@ -274,9 +266,7 @@ - (void)test04AutotrackPageDelayWithoutCallSuperViewDidAppear { - (void)test05AutotrackPageDelayWithoutCallSuperViewDidAppear { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]]; - [viewTester waitForAnimationsToFinish]; [[viewTester usingLabel:@"Button"] tap]; // 不点击按钮,走autotrackPage内部的补page逻辑 diff --git a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m index 2c3c42cb6..568acc3c7 100644 --- a/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m +++ b/Example/GrowingAnalyticsTests/HostApplicationTests/HybridTests/HybridTest_HostApp.m @@ -66,7 +66,7 @@ - (void)tearDown { - (void)test02SendMockCustomEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockCustomEvent()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); @@ -86,7 +86,7 @@ - (void)test02SendMockCustomEvent { - (void)test03SendMockCustomEventWithAttributes { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockCustomEventWithAttributes()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeCustom]; XCTAssertEqual(events.count, 1); @@ -106,7 +106,7 @@ - (void)test03SendMockCustomEventWithAttributes { - (void)test04SendMockLoginUserAttributesEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockLoginUserAttributesEvent()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeLoginUserAttributes]; XCTAssertEqual(events.count, 1); @@ -124,7 +124,7 @@ - (void)test04SendMockLoginUserAttributesEvent { - (void)test06SendMockPageEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockPageEvent()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); @@ -143,7 +143,7 @@ - (void)test06SendMockPageEvent { - (void)test07SendMockPageEventWithQuery { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockPageEventWithQuery()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); @@ -163,7 +163,7 @@ - (void)test07SendMockPageEventWithQuery { - (void)test08SendMockPageEventWithAttributes { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockPageEventWithAttributes()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage]; XCTAssertEqual(events.count, 1); @@ -185,7 +185,7 @@ - (void)test08SendMockPageEventWithAttributes { - (void)test09SendMockViewClickEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockViewClickEvent()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewClick]; XCTAssertEqual(events.count, 1); @@ -207,7 +207,7 @@ - (void)test09SendMockViewClickEvent { - (void)test10SendMockViewChangeEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockViewChangeEvent()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeViewChange]; XCTAssertEqual(events.count, 1); @@ -229,7 +229,7 @@ - (void)test10SendMockViewChangeEvent { - (void)test11SendMockFormSubmitEvent { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"sendMockFormSubmitEvent()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; NSArray *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypeFormSubmit]; XCTAssertEqual(events.count, 1); @@ -249,7 +249,7 @@ - (void)test11SendMockFormSubmitEvent { - (void)test12MockSetUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockSetUserId('xctest_userId_hybrid')"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; [GrowingDispatchManager dispatchInGrowingThread:^{ @@ -262,7 +262,7 @@ - (void)test12MockSetUserId { - (void)test13MockClearUserId { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockClearUserId()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; [GrowingDispatchManager dispatchInGrowingThread:^{ @@ -275,7 +275,7 @@ - (void)test14MockSetUserIdAndUserKey { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockSetUserIdAndUserKey('xctest_userId_hybrid2', 'xctest_userKey_hybrid2')"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; [GrowingDispatchManager dispatchInGrowingThread:^{ XCTAssertEqualObjects([[GrowingPersistenceDataProvider sharedInstance] loginUserId], @@ -289,7 +289,7 @@ - (void)test14MockSetUserIdAndUserKey { - (void)test15MockClearUserIdAndUserKey { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockClearUserIdAndUserKey()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; [GrowingDispatchManager dispatchInGrowingThread:^{ @@ -305,7 +305,7 @@ - (void)test16MockDomChanged { KIFUIViewTestActor *actor = [viewTester usingLabel:@"HybridWebView"]; [self webView:actor.view evaluateJavaScript:@"mockDomChanged()"]; - [viewTester waitForTimeInterval:1]; + [viewTester waitForTimeInterval:0.5]; XCTAssertEqual(XCTest_didDomChanged, 1); } diff --git a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m index 555c59f0a..d64af27d2 100644 --- a/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m +++ b/Example/GrowingAnalyticsTests/ModulesTests/WebCircleTests/WebCircleTest.m @@ -160,7 +160,7 @@ - (void)test01SocketSend { [viewTester tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; XCTestExpectation *expectation = [self expectationWithDescription:@"WebCircle Test failed : timeout"]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSString *message = MockWebSocket.sharedInstance.lastMessage; NSMutableDictionary *dic = [[message growingHelper_jsonObject] mutableCopy]; [self webCircleSocketParamsCheck:dic]; @@ -215,10 +215,11 @@ - (void)test07Hybrid { // 再执行webSocket:didReceiveMessage:以触发getDomTree [[viewTester usingLabel:@"UI界面"] tap]; [[viewTester usingLabel:@"Hybrid"] tap]; + [viewTester waitForTimeInterval:5]; [webCircle webSocket:nil didReceiveMessage:@"{\"msgType\":\"ready\"}"]; // 尝试通过tapPoint点击到html中的button - [viewTester tapScreenAtPoint:CGPointMake(100, 300)]; + [viewTester tapScreenAtPoint:CGPointMake(100, 200)]; XCTestExpectation *expectation = [self expectationWithDescription:@"WebCircle Test failed : timeout"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ diff --git a/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m b/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m index 93f6b5701..f05ce96ef 100644 --- a/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m +++ b/Example/GrowingAnalyticsTests/TrackerCoreTests/ManagerTests/GrowingSessionTest.m @@ -38,7 +38,7 @@ + (void)setUp { GrowingTrackConfiguration *config = [GrowingTrackConfiguration configurationWithProjectId:@"test"]; // 避免不执行readPropertyInTrackThread config.dataCollectionEnabled = YES; - config.sessionInterval = 5.0f; + config.sessionInterval = 3.0f; GrowingConfigurationManager.sharedInstance.trackConfiguration = config; // 避免insertEventToDatabase异常 From 9ca1922f76262150f1cf841250a0ee18ed5d7e8d Mon Sep 17 00:00:00 2001 From: YoloMao Date: Mon, 21 Aug 2023 20:11:34 +0800 Subject: [PATCH 085/126] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=20SwiftUI=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20SDK=20=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/Example.xcodeproj/project.pbxproj | 22 +++ Example/Example/Example-Bridging-Header.h | 24 +++ .../Others/GIOSwiftUIContentViewController.h | 28 ++++ .../Others/GIOSwiftUIContentViewController.m | 40 +++++ Example/Example/Others/SwiftUIView.swift | 68 ++++++++ Example/Example/Storyboard/Others.storyboard | 147 +++++++++++------- 6 files changed, 275 insertions(+), 54 deletions(-) create mode 100644 Example/Example/Example-Bridging-Header.h create mode 100644 Example/Example/Others/GIOSwiftUIContentViewController.h create mode 100644 Example/Example/Others/GIOSwiftUIContentViewController.m create mode 100644 Example/Example/Others/SwiftUIView.swift diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index c0a75c9c9..cf5379a01 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -167,6 +167,8 @@ 34C0BF3A277EA7C90047ADC4 /* DataTrafficTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C0BF39277EA7C90047ADC4 /* DataTrafficTest.m */; }; 34C0BF3D277EA9BA0047ADC4 /* MobileDebuggerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C0BF3C277EA9BA0047ADC4 /* MobileDebuggerTest.m */; }; 34ECFDBF2A5C082A0059F87C /* GrowingAutotrackPageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34ECFDBE2A5C082A0059F87C /* GrowingAutotrackPageViewController.m */; }; + 34FCF7E12A937ECA009611B3 /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34FCF7E02A937ECA009611B3 /* SwiftUIView.swift */; }; + 34FCF7E42A937F4F009611B3 /* GIOSwiftUIContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34FCF7E32A937F4F009611B3 /* GIOSwiftUIContentViewController.m */; }; 46B566A91FF28564AA03491F /* Pods_ProtobufTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2E2C01C3AC89773BC3F4BE1 /* Pods_ProtobufTests.framework */; }; 4916270F24E157BB00444AF2 /* GIOPresentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4916270E24E157BB00444AF2 /* GIOPresentViewController.m */; }; 4916271224E157CF00444AF2 /* GIOPagingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4916271124E157CF00444AF2 /* GIOPagingViewController.m */; }; @@ -400,6 +402,10 @@ 34C0BF3C277EA9BA0047ADC4 /* MobileDebuggerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MobileDebuggerTest.m; sourceTree = ""; }; 34ECFDBD2A5C082A0059F87C /* GrowingAutotrackPageViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GrowingAutotrackPageViewController.h; sourceTree = ""; }; 34ECFDBE2A5C082A0059F87C /* GrowingAutotrackPageViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GrowingAutotrackPageViewController.m; sourceTree = ""; }; + 34F94ED82A938725002CB9FC /* Example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Example-Bridging-Header.h"; path = "Example/Example-Bridging-Header.h"; sourceTree = SOURCE_ROOT; }; + 34FCF7E02A937ECA009611B3 /* SwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = ""; }; + 34FCF7E22A937F4F009611B3 /* GIOSwiftUIContentViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GIOSwiftUIContentViewController.h; sourceTree = ""; }; + 34FCF7E32A937F4F009611B3 /* GIOSwiftUIContentViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GIOSwiftUIContentViewController.m; sourceTree = ""; }; 3D63F725A31AE372B485C361 /* Pods-HostApplicationTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HostApplicationTests.debug.xcconfig"; path = "Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests.debug.xcconfig"; sourceTree = ""; }; 42ADE26B250B292900CA7268 /* HybridTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HybridTest.m; sourceTree = ""; }; 42F5EA0EFE2552358C35A0F5 /* Pods_HostApplicationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HostApplicationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -543,6 +549,7 @@ 046530FF24DD4271002D254C /* AppDelegate.m */, 046530D124DD4271002D254C /* Assets.xcassets */, 04A6FAE024E2BF11006C72F0 /* Example.entitlements */, + 34F94ED82A938725002CB9FC /* Example-Bridging-Header.h */, 046530FD24DD4271002D254C /* GrowingIO-Info.plist */, 046530BD24DD4271002D254C /* GrowingIO-Prefix.pch */, 046530DA24DD4271002D254C /* LaunchScreen.storyboard */, @@ -936,6 +943,9 @@ 34106BB328FECB0E00E7DB01 /* Crasher.mm */, 349DA46A28F2BF9400C4281F /* GIOCrashMonitorTableViewController.h */, 349DA46B28F2BF9400C4281F /* GIOCrashMonitorTableViewController.mm */, + 34FCF7E02A937ECA009611B3 /* SwiftUIView.swift */, + 34FCF7E22A937F4F009611B3 /* GIOSwiftUIContentViewController.h */, + 34FCF7E32A937F4F009611B3 /* GIOSwiftUIContentViewController.m */, ); path = Others; sourceTree = ""; @@ -1611,6 +1621,7 @@ }; 6003F589195388D20070C39A = { DevelopmentTeam = SXBU677CPT; + LastSwiftMigration = 1430; ProvisioningStyle = Automatic; }; }; @@ -2277,6 +2288,7 @@ files = ( 04A6FAF224E662E9006C72F0 /* GIOChildsAddViewController.m in Sources */, 348C86AF2A60FC9000310C22 /* GrowingIgnoreButton3.m in Sources */, + 34FCF7E12A937ECA009611B3 /* SwiftUIView.swift in Sources */, 349F1492285B560200437F53 /* UIColor+Hex.m in Sources */, 348C86A52A60FC1100310C22 /* GrowingIgnoreViewClsViewController.m in Sources */, 349F1489285B503B00437F53 /* GIOH5BrowserViewController.m in Sources */, @@ -2312,6 +2324,7 @@ 0465315A24DD4272002D254C /* GIOFoodTableViewCell.m in Sources */, 0465314524DD4272002D254C /* GIOCustomEventViewController.m in Sources */, 0465314724DD4272002D254C /* GIOContainerViewController.m in Sources */, + 34FCF7E42A937F4F009611B3 /* GIOSwiftUIContentViewController.m in Sources */, 0465314E24DD4272002D254C /* GIOLabelAttributeViewController.m in Sources */, 349F1488285B503B00437F53 /* GIODefaultWebViewController.m in Sources */, 0465315324DD4272002D254C /* GIOActionSheetViewController.m in Sources */, @@ -2532,6 +2545,7 @@ 3494DD0128597E1A00A6CE46 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; @@ -2577,6 +2591,7 @@ 3494DD0228597E1A00A6CE46 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; @@ -3192,6 +3207,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 3D63F725A31AE372B485C361 /* Pods-HostApplicationTests.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -3239,6 +3255,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = FAB05E3514907518EF7B9514 /* Pods-HostApplicationTests.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -3361,6 +3378,7 @@ baseConfigurationReference = 91EEE76F9E0E94DB389A9D21 /* Pods-Example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; @@ -3381,6 +3399,8 @@ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Example/Example-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; @@ -3392,6 +3412,7 @@ baseConfigurationReference = DDE20EE0BB4E138A407A5D1C /* Pods-Example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; @@ -3412,6 +3433,7 @@ SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Example/Example-Bridging-Header.h"; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; diff --git a/Example/Example/Example-Bridging-Header.h b/Example/Example/Example-Bridging-Header.h new file mode 100644 index 000000000..a6f5333cd --- /dev/null +++ b/Example/Example/Example-Bridging-Header.h @@ -0,0 +1,24 @@ +// +// Example-Bridging-Header.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/8/21. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef Example_Bridging_Header_h +#define Example_Bridging_Header_h + + +#endif /* Example_Bridging_Header_h */ diff --git a/Example/Example/Others/GIOSwiftUIContentViewController.h b/Example/Example/Others/GIOSwiftUIContentViewController.h new file mode 100644 index 000000000..81574cf75 --- /dev/null +++ b/Example/Example/Others/GIOSwiftUIContentViewController.h @@ -0,0 +1,28 @@ +// +// GIOSwiftUIContentViewController.h +// GrowingAnalytics +// +// Created by YoloMao on 2023/8/21. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GIOSwiftUIContentViewController : UIViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Example/Others/GIOSwiftUIContentViewController.m b/Example/Example/Others/GIOSwiftUIContentViewController.m new file mode 100644 index 000000000..c9cda0cb9 --- /dev/null +++ b/Example/Example/Others/GIOSwiftUIContentViewController.m @@ -0,0 +1,40 @@ +// +// GIOSwiftUIContentViewController.m +// GrowingAnalytics +// +// Created by YoloMao on 2023/8/21. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import "GIOSwiftUIContentViewController.h" +#import "Example-Swift.h" + +@interface GIOSwiftUIContentViewController () + +@end + +@implementation GIOSwiftUIContentViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + if (@available(iOS 13.0, *)) { + UIViewController *controller = [SwiftUIViewWrapper viewController]; + UIView *view = controller.view; + view.frame = self.view.frame; + [self.view addSubview:view]; + } +} + +@end diff --git a/Example/Example/Others/SwiftUIView.swift b/Example/Example/Others/SwiftUIView.swift new file mode 100644 index 000000000..61c06ee0d --- /dev/null +++ b/Example/Example/Others/SwiftUIView.swift @@ -0,0 +1,68 @@ +// +// SwiftUIView.swift +// GrowingAnalytics +// +// Created by YoloMao on 2023/8/21. +// Copyright (C) 2023 Beijing Yishu Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// 参考:https://github.com/firebase/firebase-ios-sdk/tree/master/FirebaseAnalyticsSwift +#if canImport(SwiftUI) +import SwiftUI +import GrowingAnalytics + +@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) +@objc class SwiftUIViewWrapper: NSObject { + @objc static func viewController() -> UIViewController { + UIHostingController(rootView: SwiftUIView()) + } +} + +@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) +struct SwiftUIView: View { + var body: some View { + VStack { + Text("Hello, World!") + .padding() + Button("TrackCustomEvent") { + GrowingAutotracker.sharedInstance().trackCustomEvent("Custom", withAttributes: ["key": "value"]) + } + } + .growingTrackView("SwiftUI-View-OnAppear", attributes: ["key": "value"]) +// .onAppear { +// GrowingAutotracker.sharedInstance().trackCustomEvent("SwiftUI-View-OnAppear", withAttributes: ["key": "value"]) +// } + } +} + +@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) +extension View { + func growingTrackView(_ eventName: String, attributes: [String: String]? = nil) -> some View { + onAppear { + if let attributes = attributes { + GrowingAutotracker.sharedInstance().trackCustomEvent(eventName, withAttributes: attributes) + } else { + GrowingAutotracker.sharedInstance().trackCustomEvent(eventName) + } + } + } +} + +@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) +struct SwiftUIView_Previews: PreviewProvider { + static var previews: some View { + SwiftUIView() + } +} +#endif diff --git a/Example/Example/Storyboard/Others.storyboard b/Example/Example/Storyboard/Others.storyboard index 1bf5131ec..e3d4a5e8f 100644 --- a/Example/Example/Storyboard/Others.storyboard +++ b/Example/Example/Storyboard/Others.storyboard @@ -1,9 +1,9 @@ - + - + @@ -16,7 +16,7 @@ - + @@ -39,14 +39,14 @@ - + - + + + + + + + + + + + + + + + @@ -84,14 +104,14 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +