Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differences observed in how iOS/android pass userId/anonId; Corrected. #864

Merged
merged 9 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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