Skip to content

Commit

Permalink
Release 4.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
王洋洋 committed Jul 29, 2022
1 parent 0387b24 commit f6c9585
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 51 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -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}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (void)autoTrackEventWithViewController:(UIViewController *)viewController {
}

- (void)trackEventWithViewController:(UIViewController *)viewController properties:(NSDictionary<NSString *, id> *)properties {
if (!viewController) {
if (!viewController || ![viewController isKindOfClass:UIViewController.class]) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#endif

#import "SACorrectUserIdInterceptor.h"
#import "SAValidator.h"

#pragma mark userId
// A/B Testing 触发 $ABTestTrigge 事件修正属性
Expand All @@ -43,55 +44,58 @@ @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
if (properties[kSABLoginId]) {
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
if (properties[kSFLoginId]) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
37 changes: 1 addition & 36 deletions SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#import "SASessionPropertyPlugin.h"
#import "SAEventStore.h"

#define VERSION @"4.4.1"
#define VERSION @"4.4.2"

void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag;

Expand Down Expand Up @@ -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<NSString *, id> *)willEnqueueWithType:(NSString *)type andEvent:(NSDictionary *)e {
if (!self.trackEventCallback || !e[@"event"]) {
return [e copy];
}
NSMutableDictionary *event = [e mutableCopy];
NSMutableDictionary<NSString *, id> *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];

Expand Down
13 changes: 11 additions & 2 deletions SensorsAnalyticsSDK/Deeplink/SARequestDeepLinkProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 {
Expand Down

0 comments on commit f6c9585

Please sign in to comment.