From f6c958509eae2a360d46a57a9019c50ebf7bf123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B4=8B=E6=B4=8B?= Date: Fri, 29 Jul 2022 16:08:56 +0800 Subject: [PATCH] Release 4.4.2 --- SensorsAnalyticsSDK.podspec | 2 +- .../AppViewScreen/SAAppViewScreenTracker.m | 2 +- .../EventBuild/SACorrectUserIdInterceptor.m | 24 +++++++----- .../EventBuild/SAEventValidateInterceptor.m | 7 +++- .../Core/SensorsAnalyticsSDK.m | 37 +------------------ .../Deeplink/SARequestDeepLinkProcessor.m | 13 ++++++- 6 files changed, 34 insertions(+), 51 deletions(-) diff --git a/SensorsAnalyticsSDK.podspec b/SensorsAnalyticsSDK.podspec index 32ac1eca..aaae9226 100644 --- a/SensorsAnalyticsSDK.podspec +++ b/SensorsAnalyticsSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SensorsAnalyticsSDK" - s.version = "4.4.1" + s.version = "4.4.2" s.summary = "The official iOS SDK of Sensors Analytics." s.homepage = "http://www.sensorsdata.cn" s.source = { :git => 'https://github.com/sensorsdata/sa-sdk-ios.git', :tag => "v#{s.version}" } diff --git a/SensorsAnalyticsSDK/AutoTrack/AppViewScreen/SAAppViewScreenTracker.m b/SensorsAnalyticsSDK/AutoTrack/AppViewScreen/SAAppViewScreenTracker.m index ed748745..ebb4780f 100644 --- a/SensorsAnalyticsSDK/AutoTrack/AppViewScreen/SAAppViewScreenTracker.m +++ b/SensorsAnalyticsSDK/AutoTrack/AppViewScreen/SAAppViewScreenTracker.m @@ -94,7 +94,7 @@ - (void)autoTrackEventWithViewController:(UIViewController *)viewController { } - (void)trackEventWithViewController:(UIViewController *)viewController properties:(NSDictionary *)properties { - if (!viewController) { + if (!viewController || ![viewController isKindOfClass:UIViewController.class]) { return; } diff --git a/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SACorrectUserIdInterceptor.m b/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SACorrectUserIdInterceptor.m index 8059dd8b..205e5dba 100644 --- a/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SACorrectUserIdInterceptor.m +++ b/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SACorrectUserIdInterceptor.m @@ -23,6 +23,7 @@ #endif #import "SACorrectUserIdInterceptor.h" +#import "SAValidator.h" #pragma mark userId // A/B Testing 触发 $ABTestTrigge 事件修正属性 @@ -43,17 +44,20 @@ @implementation SACorrectUserIdInterceptor - (void)processWithInput:(SAFlowData *)input completion:(SAFlowDataCompletion)completion { NSParameterAssert(input.eventObject); - + if (!input.properties) { + return completion(input); + } + SABaseEventObject *object = input.eventObject; NSString *eventName = object.event; NSMutableDictionary *properties = [input.properties mutableCopy]; - + // item 操作,不采集用户 Id 信息 BOOL isNeedCorrectUserId = [eventName isEqualToString:kSABTriggerEventName] || [eventName isEqualToString:SFPlanPopupDisplayEventName]; - if (![eventName isKindOfClass:NSString.class] || !isNeedCorrectUserId || ![properties isKindOfClass:[NSDictionary class]]) { + if (![SAValidator isValidString:eventName] || !isNeedCorrectUserId) { return completion(input); } - + // $ABTestTrigger 事件修正 if ([eventName isEqualToString:kSABTriggerEventName]) { // 修改 loginId, distinctId,anonymousId @@ -61,18 +65,18 @@ - (void)processWithInput:(SAFlowData *)input completion:(SAFlowDataCompletion)co object.loginId = properties[kSABLoginId]; [properties removeObjectForKey:kSABLoginId]; } - + if (properties[kSABDistinctId]) { object.distinctId = properties[kSABDistinctId]; [properties removeObjectForKey:kSABDistinctId]; } - + if (properties[kSABAnonymousId]) { object.anonymousId = properties[kSABAnonymousId]; [properties removeObjectForKey:kSABAnonymousId]; } } - + // $PlanPopupDisplay 事件修正 if ([eventName isEqualToString:SFPlanPopupDisplayEventName]) { // 修改 loginId, distinctId,anonymousId @@ -80,18 +84,18 @@ - (void)processWithInput:(SAFlowData *)input completion:(SAFlowDataCompletion)co object.loginId = properties[kSFLoginId]; [properties removeObjectForKey:kSFLoginId]; } - + if (properties[kSFDistinctId]) { object.distinctId = properties[kSFDistinctId]; [properties removeObjectForKey:kSFDistinctId]; } - + if (properties[kSFAnonymousId]) { object.anonymousId = properties[kSFAnonymousId]; [properties removeObjectForKey:kSFAnonymousId]; } } - + input.properties = [properties copy]; completion(input); } diff --git a/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SAEventValidateInterceptor.m b/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SAEventValidateInterceptor.m index 83d1abd0..4cd359e6 100644 --- a/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SAEventValidateInterceptor.m +++ b/SensorsAnalyticsSDK/Core/Interceptor/EventBuild/SAEventValidateInterceptor.m @@ -24,18 +24,23 @@ #import "SAEventValidateInterceptor.h" #import "SAModuleManager.h" +#import "SAPropertyValidator.h" @implementation SAEventValidateInterceptor - (void)processWithInput:(SAFlowData *)input completion:(SAFlowDataCompletion)completion { NSParameterAssert(input.eventObject); - + + // 事件名校验 NSError *error = nil; [input.eventObject validateEventWithError:&error]; if (error) { [SAModuleManager.sharedInstance showDebugModeWarning:error.localizedDescription]; } input.message = error.localizedDescription; + + // 传入 properties 校验 + input.properties = [SAPropertyValidator validProperties:input.properties]; completion(input); } diff --git a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m index b08ec0e7..ae08e888 100755 --- a/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m +++ b/SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m @@ -62,7 +62,7 @@ #import "SASessionPropertyPlugin.h" #import "SAEventStore.h" -#define VERSION @"4.4.1" +#define VERSION @"4.4.2" void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag; @@ -629,41 +629,6 @@ - (void)itemDeleteWithType:(NSString *)itemType itemId:(NSString *)itemId { #pragma mark - track event -/// Native 触发事件属性校验 -- (BOOL)willEnqueueWithObject:(SABaseEventObject *)obj { - NSString *eventName = obj.event; - if (!self.trackEventCallback || !eventName) { - return YES; - } - BOOL willEnque = self.trackEventCallback(eventName, obj.properties); - if (!willEnque) { - SALogDebug(@"\n【track event】: %@ can not insert database.", eventName); - return NO; - } - // 校验 properties - NSMutableDictionary *properties = [SAPropertyValidator validProperties:obj.properties]; - obj.properties = properties; - return YES; -} - -/// H5 打通事件校验 -- (NSDictionary *)willEnqueueWithType:(NSString *)type andEvent:(NSDictionary *)e { - if (!self.trackEventCallback || !e[@"event"]) { - return [e copy]; - } - NSMutableDictionary *event = [e mutableCopy]; - NSMutableDictionary *originProperties = event[@"properties"]; - BOOL isIncluded = self.trackEventCallback(event[@"event"], originProperties); - if (!isIncluded) { - SALogDebug(@"\n【track event】: %@ are not allowed insert database by callback", event[@"event"]); - return nil; - } - // 校验 properties - NSDictionary *validProperties = [SAPropertyValidator validProperties:originProperties]; - event[@"properties"] = validProperties; - return event; -} - - (void)profile:(NSString *)type properties:(NSDictionary *)properties { SAProfileEventObject *object = [[SAProfileEventObject alloc] initWithType:type]; diff --git a/SensorsAnalyticsSDK/Deeplink/SARequestDeepLinkProcessor.m b/SensorsAnalyticsSDK/Deeplink/SARequestDeepLinkProcessor.m index 0cf2a00a..5be463ce 100644 --- a/SensorsAnalyticsSDK/Deeplink/SARequestDeepLinkProcessor.m +++ b/SensorsAnalyticsSDK/Deeplink/SARequestDeepLinkProcessor.m @@ -46,7 +46,13 @@ + (BOOL)isNormalDeepLinkURL:(NSURL *)url { return NO; } NSString *host = SensorsAnalyticsSDK.sharedInstance.network.serverURL.host; - return ([url.host isEqualToString:kSchemeDeepLinkHost] || [url.host isEqualToString:host]); + if ([url.host caseInsensitiveCompare:kSchemeDeepLinkHost] == NSOrderedSame) { + return YES; + } + if (!host) { + return NO; + } + return [url.host caseInsensitiveCompare:host] == NSOrderedSame; } /// URL 的 Path 符合特定规则。示例:https://{ 自定义域名}/slink/{appId}/{key} 或 {scheme}://sensorsdata/slink/{key} @@ -66,10 +72,13 @@ + (BOOL)isCustomDeepLinkURL:(NSURL *)url { NSString *primaryDomain = [self primaryDomainForURL:url]; NSString *channelPrimaryDomain = [self primaryDomainForURL:components.URL]; + if ([url.host caseInsensitiveCompare:kSchemeDeepLinkHost] == NSOrderedSame) { + return YES; + } if (!channelPrimaryDomain) { return NO; } - return ([url.host isEqualToString:kSchemeDeepLinkHost] || [primaryDomain isEqualToString:channelPrimaryDomain]); + return [primaryDomain caseInsensitiveCompare:channelPrimaryDomain] == NSOrderedSame; } + (NSString *)primaryDomainForURL:(NSURL *)url {