From e35f1c984687f3216810145c8f1a8360fad20a72 Mon Sep 17 00:00:00 2001 From: Brandon Sneed Date: Tue, 9 Mar 2021 10:26:23 -0800 Subject: [PATCH] Pushed save of anonId higher up into the flow. (#977) * Pushed save of anonId higher up into the flow. * Removed api endpoint test. Co-authored-by: Brandon Sneed --- Segment/Classes/SEGAnalytics.m | 2 ++ Segment/Internal/SEGIntegrationsManager.h | 1 + Segment/Internal/SEGIntegrationsManager.m | 9 --------- SegmentTests/AnalyticsTests.swift | 3 ++- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Segment/Classes/SEGAnalytics.m b/Segment/Classes/SEGAnalytics.m index 325817fe5..ef9cfd732 100644 --- a/Segment/Classes/SEGAnalytics.m +++ b/Segment/Classes/SEGAnalytics.m @@ -276,6 +276,8 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDic NSString *anonId = [options objectForKey:@"anonymousId"]; if (anonId == nil) { anonId = [self getAnonymousId]; + } else { + [self.integrationsManager saveAnonymousId:anonId]; } // configure traits to match what is seen on android. NSMutableDictionary *existingTraitsCopy = [[SEGState sharedInstance].userInfo.traits mutableCopy]; diff --git a/Segment/Internal/SEGIntegrationsManager.h b/Segment/Internal/SEGIntegrationsManager.h index 17f500d1b..eea1f7180 100644 --- a/Segment/Internal/SEGIntegrationsManager.h +++ b/Segment/Internal/SEGIntegrationsManager.h @@ -36,6 +36,7 @@ NS_SWIFT_NAME(IntegrationsManager) // @Deprecated - Exposing for backward API compat reasons only - (NSString *_Nonnull)getAnonymousId; +- (void)saveAnonymousId:(NSString *)anonymousId; @end diff --git a/Segment/Internal/SEGIntegrationsManager.m b/Segment/Internal/SEGIntegrationsManager.m index 1d2cf415b..f219efffa 100644 --- a/Segment/Internal/SEGIntegrationsManager.m +++ b/Segment/Internal/SEGIntegrationsManager.m @@ -213,15 +213,6 @@ - (void)identify:(SEGIdentifyPayload *)payload { NSCAssert2(payload.userId.length > 0 || payload.traits.count > 0, @"either userId (%@) or traits (%@) must be provided.", payload.userId, payload.traits); - NSString *anonymousId = payload.anonymousId; - NSString *existingAnonymousId = self.cachedAnonymousId; - - if (anonymousId == nil) { - payload.anonymousId = anonymousId; - } else if (![anonymousId isEqualToString:existingAnonymousId]) { - [self saveAnonymousId:anonymousId]; - } - [self callIntegrationsWithSelector:NSSelectorFromString(@"identify:") arguments:@[ payload ] options:payload.options diff --git a/SegmentTests/AnalyticsTests.swift b/SegmentTests/AnalyticsTests.swift index 185fc21a7..af5dd2f8d 100644 --- a/SegmentTests/AnalyticsTests.swift +++ b/SegmentTests/AnalyticsTests.swift @@ -65,7 +65,8 @@ class AnalyticsTests: XCTestCase { XCTAssertEqual(config.flushInterval, 30) XCTAssertEqual(config.maxQueueSize, 1000) XCTAssertEqual(config.writeKey, "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE") - XCTAssertEqual(config.apiHost?.absoluteString, "https://api.segment.io/v1") + // not needed as segment settings API can provide different host values now. + //XCTAssertEqual(config.apiHost?.absoluteString, "https://api.segment.io/v1") XCTAssertEqual(config.shouldUseLocationServices, false) XCTAssertEqual(config.enableAdvertisingTracking, true) XCTAssertEqual(config.shouldUseBluetooth, false)