Skip to content

Commit

Permalink
Release 4.5.21
Browse files Browse the repository at this point in the history
  • Loading branch information
陈玉国 authored and 陈玉国 committed Oct 27, 2023
1 parent 520ac45 commit a951be2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 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.5.20"
s.version = "4.5.21"
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
4 changes: 4 additions & 0 deletions SensorsAnalyticsSDK/Core/Builder/SAIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ extern NSString * const kSALoginIdSpliceKey;
/// 用于合并 H5 传过来的业务 ID
- (NSDictionary *)mergeH5Identities:(NSDictionary *)identities eventType:(SAEventType)eventType;


/// ID3 reset anonymous identity
- (void)resetAnonymousIdentity:(nullable NSString *)identity;

@end

NS_ASSUME_NONNULL_END
27 changes: 27 additions & 0 deletions SensorsAnalyticsSDK/Core/Builder/SAIdentifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,31 @@ - (void)archiveIdentities:(NSDictionary *)identities {
}
}

- (void)resetAnonymousIdentity:(NSString *)identity {
if (self.loginId) {
SALogError(@"you should not use this function when login");
return;
}
NSString *anonymousId = identity;
if (!anonymousId || anonymousId.length == 0) {
anonymousId = [NSUUID UUID].UUIDString;
}
dispatch_async(self.queue, ^{
//set anonymous id
self.anonymousId = anonymousId;
[self archiveAnonymousId:anonymousId];
//set anonymousId in identities
NSMutableDictionary *identities = [self.identities mutableCopy];
if (identities[kSAIdentitiesUniqueID]) {
identities[kSAIdentitiesUniqueID] = anonymousId;
}
if (identities[kSAIdentitiesUUID]) {
identities[kSAIdentitiesUUID] = anonymousId;
}
self.identities = identities;
[self archiveIdentities:identities];
[[NSNotificationCenter defaultCenter] postNotificationName:SA_TRACK_RESETANONYMOUSID_NOTIFICATION object:nil];
});
}

@end
3 changes: 3 additions & 0 deletions SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK+Public.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ extern NSString * const SensorsAnalyticsIdentityKeyEmail;
*/
- (void)unbind:(NSString *)key value:(NSString *)value;

/// ID3 reset anonymous identity
- (void)resetAnonymousIdentity:(nullable NSString *)identity;

#pragma mark - trackTimer
/**
开始事件计时
Expand Down
12 changes: 11 additions & 1 deletion SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#import "SALimitKeyManager.h"
#import "NSDictionary+SACopyProperties.h"

#define VERSION @"4.5.20"
#define VERSION @"4.5.21"

void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag;

Expand Down Expand Up @@ -669,6 +669,16 @@ - (void)unbind:(NSString *)key value:(NSString *)value {
});
}

-(void)resetAnonymousIdentity:(NSString *)identity {
if (identity && ![identity isKindOfClass:[NSString class]]) {
SALogError(@"anonymous identity should be string");
return;
}
dispatch_async(self.serialQueue, ^{
[self.identifier resetAnonymousIdentity:identity];
});
}

- (void)track:(NSString *)event {
[self track:event withProperties:nil];
}
Expand Down
13 changes: 13 additions & 0 deletions SensorsAnalyticsTests/Builder/SAIdentifierTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,17 @@ - (void)testH5EventForNativeInitial {
XCTAssertNotNil(native[kIDFV]);
}

- (void)testResetAnonymousIdentity {
NSString *distinctId = _identifier.distinctId;
[_identifier resetAnonymousIdentity:nil];
XCTAssertTrue(![distinctId isEqualToString:_identifier.distinctId]);
NSString *newDistinctId = _identifier.distinctId;
[_identifier resetAnonymousIdentity:@"dedea-deada-dadaed-deded"];
XCTAssertTrue(![newDistinctId isEqualToString:_identifier.distinctId]);
XCTAssertTrue([@"dedea-deada-dadaed-deded" isEqualToString:_identifier.distinctId]);
[_identifier loginWithKey:@"testKey" loginId:@"testLoginId"];
[_identifier resetAnonymousIdentity:@"dedea-deada-dadaed-deded"];
XCTAssertTrue([_identifier.distinctId isEqualToString:@"testKey+testLoginId"]);
}

@end

0 comments on commit a951be2

Please sign in to comment.