Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: options request #311

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Example/Pods-Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAPM/GrowingAPM.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-18cf2943/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-232e7e5e/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingToolsKit/GrowingToolsKit.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
Expand Down Expand Up @@ -2361,7 +2361,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsStartTests/Pods-GrowingAnalyticsStartTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-88384491/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-4f84af90/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
);
Expand Down Expand Up @@ -2559,7 +2559,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Example-watchOS Watch App/Pods-Example-watchOS Watch App-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-3edd9a5d/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-403bfd64/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-TrackerCore-watchOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-watchOS/Protobuf.framework",
);
Expand All @@ -2582,7 +2582,7 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-ExampleiOS13/Pods-ExampleiOS13-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAPM/GrowingAPM.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-8f52182e/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-0ddd49d8/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingToolsKit/GrowingToolsKit.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
Expand All @@ -2608,7 +2608,7 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Example-SwiftUI/Pods-Example-SwiftUI-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAPM-Core/GrowingAPM.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-dd4d243e/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-d1292d27/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
);
Expand Down Expand Up @@ -2653,7 +2653,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-GrowingAnalyticsTests/Pods-GrowingAnalyticsTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-b35945a7/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-5371fadd/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
);
Expand All @@ -2675,7 +2675,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-ABTestingTests/Pods-ABTestingTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-cfbe515d/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-fa1c1980/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
"${BUILT_PRODUCTS_DIR}/OHHTTPStubs/OHHTTPStubs.framework",
Expand All @@ -2699,7 +2699,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Example-tvOS/Pods-Example-tvOS-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-67f52605/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-6ab1300e/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-tvOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-tvOS/Protobuf.framework",
);
Expand Down Expand Up @@ -2765,7 +2765,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-HostApplicationTests/Pods-HostApplicationTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-d5b2e835/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-a2e10ca9/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
"${BUILT_PRODUCTS_DIR}/KIF/KIF.framework",
Expand Down Expand Up @@ -2855,7 +2855,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-ProtobufTests/Pods-ProtobufTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-d5b2e835/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-a2e10ca9/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
);
Expand All @@ -2877,7 +2877,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Example-macOS/Pods-Example-macOS-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-9b78b9c4/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-8df63dd3/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-TrackerCore-macOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-macOS/Protobuf.framework",
);
Expand All @@ -2899,7 +2899,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AdvertisingTests/Pods-AdvertisingTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-8f52182e/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingAnalytics-0ddd49d8/GrowingAnalytics.framework",
"${BUILT_PRODUCTS_DIR}/GrowingUtils-AutotrackerCore-TrackerCore-iOS/GrowingUtils.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf-iOS/Protobuf.framework",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ - (void)testDefaultConfiguration_Autotracker {
GrowingAutotrackConfiguration *configuration =
(GrowingAutotrackConfiguration *)GrowingConfigurationManager.sharedInstance.trackConfiguration;
XCTAssertEqual(configuration.debugEnabled, NO);
XCTAssertEqual(configuration.cellularDataLimit, 10);
XCTAssertEqual(configuration.cellularDataLimit, 20);
XCTAssertEqual(configuration.dataUploadInterval, 15);
XCTAssertEqual(configuration.sessionInterval, 30);
XCTAssertEqual(configuration.dataCollectionEnabled, YES);
Expand Down Expand Up @@ -190,7 +190,7 @@ - (void)testDefaultConfiguration_Tracker {

GrowingTrackConfiguration *configuration = GrowingConfigurationManager.sharedInstance.trackConfiguration;
XCTAssertEqual(configuration.debugEnabled, NO);
XCTAssertEqual(configuration.cellularDataLimit, 10);
XCTAssertEqual(configuration.cellularDataLimit, 20);
XCTAssertEqual(configuration.dataUploadInterval, 15);
XCTAssertEqual(configuration.sessionInterval, 30);
XCTAssertEqual(configuration.dataCollectionEnabled, YES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)testDefaultConfiguration_Autotracker {
GrowingAutotrackConfiguration *configuration =
(GrowingAutotrackConfiguration *)GrowingConfigurationManager.sharedInstance.trackConfiguration;
XCTAssertEqual(configuration.debugEnabled, NO);
XCTAssertEqual(configuration.cellularDataLimit, 10);
XCTAssertEqual(configuration.cellularDataLimit, 20);
XCTAssertEqual(configuration.dataUploadInterval, 15);
XCTAssertEqual(configuration.sessionInterval, 30);
XCTAssertEqual(configuration.dataCollectionEnabled, YES);
Expand All @@ -72,7 +72,7 @@ - (void)testDefaultConfiguration_Tracker {

GrowingTrackConfiguration *configuration = GrowingConfigurationManager.sharedInstance.trackConfiguration;
XCTAssertEqual(configuration.debugEnabled, NO);
XCTAssertEqual(configuration.cellularDataLimit, 10);
XCTAssertEqual(configuration.cellularDataLimit, 20);
XCTAssertEqual(configuration.dataUploadInterval, 15);
XCTAssertEqual(configuration.sessionInterval, 30);
XCTAssertEqual(configuration.dataCollectionEnabled, YES);
Expand Down
8 changes: 8 additions & 0 deletions GrowingAnalytics.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和
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/Preflight', s.version.to_s
autotracker.dependency 'GrowingAnalytics/DefaultServices', s.version.to_s
end

Expand All @@ -40,6 +41,7 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和

# Modules
tracker.ios.dependency 'GrowingAnalytics/MobileDebugger', s.version.to_s
tracker.dependency 'GrowingAnalytics/Preflight', s.version.to_s
tracker.dependency 'GrowingAnalytics/DefaultServices', s.version.to_s
end

Expand Down Expand Up @@ -205,6 +207,12 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和
ab.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s
end

s.subspec 'Preflight' do |preflight|
preflight.source_files = 'Modules/Preflight/**/*{.h,.m,.c,.cpp,.mm}'
preflight.public_header_files = 'Modules/Preflight/Public/*.h'
preflight.dependency 'GrowingAnalytics/TrackerCore', s.version.to_s
end

# 使用flutter无埋点插件时,将自动导入该库,正常情况下请勿手动导入
s.subspec 'Flutter' do |flutter|
flutter.source_files = 'Modules/Flutter/**/*{.h,.m,.c,.cpp,.mm}'
Expand Down
2 changes: 2 additions & 0 deletions GrowingTrackerCore/Core/GrowingModuleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

static NSString *kInitSelector = @"growingModInit:";
static NSString *kSetDataCollectionEnabledSelector = @"growingModSetDataCollectionEnabled:";
static NSString *kRefreshSessionSelector = @"growingModRefreshSession:";

@interface GrowingModuleManager ()

Expand Down Expand Up @@ -191,6 +192,7 @@ - (NSMutableArray *)modules {
_selectorByEvent = @{
@(GrowingMInitEvent): kInitSelector,
@(GrowingMSetDataCollectionEnabledEvent): kSetDataCollectionEnabledSelector,
@(GrowingMRefreshSessionEvent): kRefreshSessionSelector,
};
}
return _selectorByEvent;
Expand Down
19 changes: 15 additions & 4 deletions GrowingTrackerCore/Event/GrowingEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,27 @@
/// @param event 当前事件
- (void)growingEventManagerEventDidWrite:(GrowingBaseEvent *_Nullable)event;

/// 是否开始发送事件
/// @param channel 当前发送通道
- (BOOL)growingEventManagerEventShouldBeginSending:(GrowingEventChannel *_Nonnull)channel;

/// 即将发送事件
/// @param events 发送的事件
/// @param channel 当前发送通道
- (NSArray *_Nonnull)growingEventManagerEventsWillSend:(NSArray<id<GrowingEventPersistenceProtocol>> *_Nonnull)events
channel:(GrowingEventChannel *_Nonnull)channel;

/// 事件发送完毕
/// 事件发送请求完毕
/// @param events 发送的事件
- (void)growingEventManagerEventsDidSend:(NSArray<id<GrowingEventPersistenceProtocol>> *_Nonnull)events
request:(id<GrowingRequestProtocol> _Nonnull)request
channel:(GrowingEventChannel *_Nonnull)channel;
/// @param request 当前请求
/// @param channel 当前发送通道
/// @param httpResponse 当前请求响应
/// @param error 当前请求错误
- (void)growingEventManagerEventsSendingCompletion:(NSArray<id<GrowingEventPersistenceProtocol>> *_Nonnull)events
request:(id<GrowingRequestProtocol> _Nonnull)request
channel:(GrowingEventChannel *_Nonnull)channel
httpResponse:(NSHTTPURLResponse *_Nonnull)httpResponse
error:(NSError *_Nonnull)error;

@end

Expand Down
54 changes: 33 additions & 21 deletions GrowingTrackerCore/Event/GrowingEventManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@

// 非安全 发送日志
- (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel {
BOOL shouldBeginSending = YES;
for (NSObject<GrowingEventInterceptor> *obj in self.allInterceptor) {
if ([obj respondsToSelector:@selector(growingEventManagerEventShouldBeginSending:)]) {
shouldBeginSending = [obj growingEventManagerEventShouldBeginSending:channel];
}
}

if (!shouldBeginSending) {
return;
}

if (channel.isUploading) {
return;
}
Expand Down Expand Up @@ -338,39 +349,40 @@
NSObject<GrowingRequestProtocol> *eventRequest = [[GrowingEventRequest alloc] initWithEvents:rawEvents];
[service sendRequest:eventRequest
completion:^(NSHTTPURLResponse *_Nonnull httpResponse, NSData *_Nonnull data, NSError *_Nonnull error) {
if (error) {
[GrowingDispatchManager dispatchInGrowingThread:^{
channel.isUploading = NO;
}];
}
if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) {
[GrowingDispatchManager dispatchInGrowingThread:^{
[GrowingDispatchManager dispatchInGrowingThread:^{
for (NSObject<GrowingEventInterceptor> *obj in self.allInterceptor) {
if ([obj respondsToSelector:@selector
(growingEventManagerEventsSendingCompletion:request:channel:httpResponse:error:)]) {
[obj growingEventManagerEventsSendingCompletion:events
request:eventRequest
channel:channel
httpResponse:httpResponse
error:error];
}
}

channel.isUploading = NO;

if (error) {
return;

Check warning on line 367 in GrowingTrackerCore/Event/GrowingEventManager.m

View check run for this annotation

Codecov / codecov/patch

GrowingTrackerCore/Event/GrowingEventManager.m#L367

Added line #L367 was not covered by tests
}

if ((httpResponse.statusCode >= 200 && httpResponse.statusCode < 400) ||
httpResponse.statusCode == 413) {
if (isViaCellular) {
if ([eventRequest respondsToSelector:@selector(outsize)]) {
self.uploadEventSize += eventRequest.outsize;
}
}

for (NSObject<GrowingEventInterceptor> *obj in self.allInterceptor) {
if ([obj respondsToSelector:@selector(growingEventManagerEventsDidSend:
request:channel:)]) {
[obj growingEventManagerEventsDidSend:events request:eventRequest channel:channel];
}
}

[self removeEvents_unsafe:events forChannel:channel];
channel.isUploading = NO;

// 如果剩余数量 大于单包数量 则直接发送
if (channel.db.countOfEvents >= kGrowingMaxBatchSize) {
[self sendEventsInstantWithChannel:channel];
}
}];
} else {
[GrowingDispatchManager dispatchInGrowingThread:^{
channel.isUploading = NO;
}];
}
}
}];
}];
}

Expand Down
15 changes: 14 additions & 1 deletion GrowingTrackerCore/GrowingTrackConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "GrowingTrackerCore/Manager/GrowingSession.h"

NSString *const kGrowingDefaultDataCollectionServerHost = @"https://napi.growingio.com";
NSString *const kGrowingDefaultAlternateDataCollectionServerHost = @"https://alternate.napi.growingio.com";
NSString *const kGrowingDefaultDeepLinkHost = @"https://link.growingio.com";
NSString *const kGrowingDefaultABTestingServerHost = @"https://ab.growingio.com";

Expand All @@ -39,6 +40,10 @@ @interface GrowingTrackConfiguration ()
@property (nonatomic, copy) NSString *abTestingServerHost;
@property (nonatomic, assign) NSUInteger abTestingRequestInterval;

// Preflight
@property (nonatomic, assign) BOOL requestPreflight;
@property (nonatomic, copy) NSString *alternateDataCollectionServerHost;

@end

@implementation GrowingTrackConfiguration
Expand All @@ -50,7 +55,7 @@ - (instancetype)initWithAccountId:(NSString *)accountId {
_dataSourceId = nil;

_debugEnabled = NO;
_cellularDataLimit = 10;
_cellularDataLimit = 20;
_dataUploadInterval = 15;
_sessionInterval = 30;
_dataCollectionEnabled = YES;
Expand Down Expand Up @@ -78,6 +83,10 @@ - (instancetype)initWithAccountId:(NSString *)accountId {
// ABTesting
_abTestingServerHost = kGrowingDefaultABTestingServerHost;
_abTestingRequestInterval = 5;

// Preflight
_requestPreflight = NO;
_alternateDataCollectionServerHost = kGrowingDefaultAlternateDataCollectionServerHost;
}

return self;
Expand Down Expand Up @@ -125,6 +134,10 @@ - (id)copyWithZone:(NSZone *)zone {
configuration->_abTestingServerHost = [_abTestingServerHost copy];
configuration->_abTestingRequestInterval = _abTestingRequestInterval;

// Preflight
configuration->_requestPreflight = _requestPreflight;
configuration->_alternateDataCollectionServerHost = [_alternateDataCollectionServerHost copy];

return configuration;
}

Expand Down
11 changes: 8 additions & 3 deletions GrowingTrackerCore/Manager/GrowingSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "GrowingTrackerCore/Event/Tools/GrowingPersistenceDataProvider.h"
#import "GrowingTrackerCore/Helpers/GrowingHelpers.h"
#import "GrowingTrackerCore/Manager/GrowingConfigurationManager.h"
#import "GrowingTrackerCore/Public/GrowingModuleManager.h"
#import "GrowingTrackerCore/Public/GrowingTrackConfiguration.h"
#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogMacros.h"
#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h"
Expand All @@ -34,6 +35,7 @@

@interface GrowingSession () <GrowingULAppLifecycleDelegate>

@property (nonatomic, assign, readwrite, getter=isSentVisitAfterRefreshSessionId) BOOL sentVisitAfterRefreshSessionId;
@property (nonatomic, copy, readwrite) NSString *sessionId;
@property (nonatomic, copy, readwrite) NSString *loginUserId;
@property (nonatomic, copy, readwrite) NSString *loginUserKey;
Expand Down Expand Up @@ -88,13 +90,16 @@ - (void)generateVisit {
if (!trackConfiguration.dataCollectionEnabled) {
return;
}
_sentVisitAfterRefreshSessionId = YES;
self.sentVisitAfterRefreshSessionId = YES;
[GrowingEventGenerator generateVisitEvent];
}

- (void)refreshSessionId {
_sessionId = NSUUID.UUID.UUIDString;
_sentVisitAfterRefreshSessionId = NO;
self.sessionId = NSUUID.UUID.UUIDString;
self.sentVisitAfterRefreshSessionId = NO;

[[GrowingModuleManager sharedInstance] triggerEvent:GrowingMRefreshSessionEvent
withCustomParam:@{@"sessionId": self.sessionId.copy}];
}

// iOS 11系统上面VC的viewDidAppear生命周期会早于AppDelegate的applicationDidBecomeActive,这样会造成Page事件早于Visit事件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ - (NSMutableURLRequest *)adaptedURLRequest:(NSMutableURLRequest *)request {
httpMethod = @"DELETE";
break;

case GrowingHTTPMethodOPTIONS:
httpMethod = @"OPTIONS";
break;

default:
break;
}
Expand Down
Loading
Loading