Skip to content

Commit 3ed8340

Browse files
authored
Differences observed in how iOS/android pass userId/anonId; Corrected. (#864)
* Disabled tvOS tests temporarily. * Updated podfile lock. * Fixed LIB-1698; Differences observed in how ios/android pass userId/anonId in traits. * Another podfile lock update. * Fixed test. * Set swift version for tests. * Reverted podfile lock changes due to incompatibilities.
1 parent 956b4eb commit 3ed8340

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

Analytics.xcodeproj/xcshareddata/xcschemes/Analytics.xcscheme

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
ReferencedContainer = "container:Analytics.xcodeproj">
2121
</BuildableReference>
2222
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "NO"
25+
buildForRunning = "NO"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "NO">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "9D8CE58B23EE014E00197D0C"
32+
BuildableName = "AnalyticsTestsTVOS.xctest"
33+
BlueprintName = "AnalyticsTestsTVOS"
34+
ReferencedContainer = "container:Analytics.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
2337
</BuildActionEntries>
2438
</BuildAction>
2539
<TestAction

Analytics/Classes/SEGAnalytics.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,24 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits
205205
- (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDictionary *)options
206206
{
207207
NSCAssert2(userId.length > 0 || traits.count > 0, @"either userId (%@) or traits (%@) must be provided.", userId, traits);
208+
209+
// this is done here to match functionality on android where these are inserted BEFORE being spread out amongst destinations.
210+
// it will be set globally later when it runs through SEGIntegrationManager.identify.
211+
NSString *anonId = [options objectForKey:@"anonymousId"];
212+
if (anonId == nil) {
213+
anonId = [self getAnonymousId];
214+
}
215+
// configure traits to match what is seen on android.
216+
NSMutableDictionary *newTraits = [traits mutableCopy];
217+
newTraits[@"anonymousId"] = anonId;
218+
if (userId != nil) {
219+
newTraits[@"userId"] = userId;
220+
}
221+
208222
[self run:SEGEventTypeIdentify payload:
209223
[[SEGIdentifyPayload alloc] initWithUserId:userId
210-
anonymousId:[options objectForKey:@"anonymousId"]
211-
traits:SEGCoerceDictionary(traits)
224+
anonymousId:anonId
225+
traits:SEGCoerceDictionary(newTraits)
212226
context:SEGCoerceDictionary([options objectForKey:@"context"])
213227
integrations:[options objectForKey:@"integrations"]]];
214228
}

AnalyticsTests/TrackingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TrackingTests: QuickSpec {
3636
expect(passthrough.lastContext?.eventType) == SEGEventType.identify
3737
let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload
3838
expect(identify?.userId) == "testUserId1"
39-
expect(identify?.anonymousId).to(beNil())
39+
expect(identify?.anonymousId).toNot(beNil())
4040
expect(identify?.traits?["firstName"] as? String) == "Peter"
4141
}
4242

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ XC_ARGS := -workspace Analytics.xcworkspace GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES
22
IOS_XCARGS := $(XC_ARGS) -destination "platform=iOS Simulator,name=iPhone 11" -sdk iphonesimulator
33
TVOS_XCARGS := $(XC_ARGS) -destination "platform=tvOS Simulator,name=Apple TV"
44
XC_BUILD_ARGS := -scheme Analytics ONLY_ACTIVE_ARCH=NO
5-
XC_TEST_ARGS := GCC_GENERATE_TEST_COVERAGE_FILES=YES RUN_E2E_TESTS=$(RUN_E2E_TESTS) WEBHOOK_AUTH_USERNAME=$(WEBHOOK_AUTH_USERNAME)
5+
XC_TEST_ARGS := GCC_GENERATE_TEST_COVERAGE_FILES=YES SWIFT_VERSION=4.0 RUN_E2E_TESTS=$(RUN_E2E_TESTS) WEBHOOK_AUTH_USERNAME=$(WEBHOOK_AUTH_USERNAME)
66

77
bootstrap:
88
.buildscript/bootstrap.sh

0 commit comments

Comments
 (0)