Skip to content

Commit

Permalink
Differences observed in how iOS/android pass userId/anonId; Corrected. (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
bsneed authored Feb 12, 2020
1 parent 956b4eb commit 3ed8340
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
14 changes: 14 additions & 0 deletions Analytics.xcodeproj/xcshareddata/xcschemes/Analytics.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
ReferencedContainer = "container:Analytics.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "NO"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9D8CE58B23EE014E00197D0C"
BuildableName = "AnalyticsTestsTVOS.xctest"
BlueprintName = "AnalyticsTestsTVOS"
ReferencedContainer = "container:Analytics.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
18 changes: 16 additions & 2 deletions Analytics/Classes/SEGAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,24 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits
- (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDictionary *)options
{
NSCAssert2(userId.length > 0 || traits.count > 0, @"either userId (%@) or traits (%@) must be provided.", userId, traits);

// this is done here to match functionality on android where these are inserted BEFORE being spread out amongst destinations.
// it will be set globally later when it runs through SEGIntegrationManager.identify.
NSString *anonId = [options objectForKey:@"anonymousId"];
if (anonId == nil) {
anonId = [self getAnonymousId];
}
// configure traits to match what is seen on android.
NSMutableDictionary *newTraits = [traits mutableCopy];
newTraits[@"anonymousId"] = anonId;
if (userId != nil) {
newTraits[@"userId"] = userId;
}

[self run:SEGEventTypeIdentify payload:
[[SEGIdentifyPayload alloc] initWithUserId:userId
anonymousId:[options objectForKey:@"anonymousId"]
traits:SEGCoerceDictionary(traits)
anonymousId:anonId
traits:SEGCoerceDictionary(newTraits)
context:SEGCoerceDictionary([options objectForKey:@"context"])
integrations:[options objectForKey:@"integrations"]]];
}
Expand Down
2 changes: 1 addition & 1 deletion AnalyticsTests/TrackingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TrackingTests: QuickSpec {
expect(passthrough.lastContext?.eventType) == SEGEventType.identify
let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload
expect(identify?.userId) == "testUserId1"
expect(identify?.anonymousId).to(beNil())
expect(identify?.anonymousId).toNot(beNil())
expect(identify?.traits?["firstName"] as? String) == "Peter"
}

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ XC_ARGS := -workspace Analytics.xcworkspace GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES
IOS_XCARGS := $(XC_ARGS) -destination "platform=iOS Simulator,name=iPhone 11" -sdk iphonesimulator
TVOS_XCARGS := $(XC_ARGS) -destination "platform=tvOS Simulator,name=Apple TV"
XC_BUILD_ARGS := -scheme Analytics ONLY_ACTIVE_ARCH=NO
XC_TEST_ARGS := GCC_GENERATE_TEST_COVERAGE_FILES=YES RUN_E2E_TESTS=$(RUN_E2E_TESTS) WEBHOOK_AUTH_USERNAME=$(WEBHOOK_AUTH_USERNAME)
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)

bootstrap:
.buildscript/bootstrap.sh
Expand Down

0 comments on commit 3ed8340

Please sign in to comment.