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

fix: allow setting anonymousId #799

Merged
merged 1 commit into from
Nov 29, 2018
Merged

Conversation

f2prateek
Copy link
Contributor

@f2prateek f2prateek commented Nov 28, 2018

Historically, the iOS library has allowed setting a custom anonymous identifier (#485).

During adding middlewares, a bug was introduced which started ignoring the anonymousId option.

This fixes the bug and adds a test to validate the fix. This was also tested in the example app end to end and I've verified that events show up with the custom anonymousId.

How should this be manually tested?
Test snipet:

[[SEGAnalytics sharedAnalytics] identify:@"Prateek" traits:nil options: @{
                                                                           @"anonymousId":@"test_anonymousId"
                                                                         }];

Event in debugger: https://cloudup.com/cFyVH4NPR_f

Subsequent events will automatically attach the new anonymous ID https://cloudup.com/cK-i_SCbwsN

Closes #753

What are the relevant tickets?
https://segment.atlassian.net/browse/LIB-266

@nhi-nguyen
Copy link
Contributor

LGTM, but probably needs another set of eyes

@@ -36,6 +36,20 @@ class TrackingTests: QuickSpec {
expect(passthrough.lastContext?.eventType) == SEGEventType.identify
let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload
expect(identify?.userId) == "testUserId1"
expect(identify?.anonymousId) == nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use the beNil matcher to match nil:

expect(identify?.anonymousId).to(beNil())

The tests are breaking because you match an Optional with a pointer (nil? == nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

Historically, the iOS library has allowed setting a custom anonymous identifier (#485).

During adding middlewares, a bug was introduced which started ignoring the anonymousId option.

This fixes the bug and adds a test to validate the fix. This was also tested in the example app end to end and I've verified that events show up with the custom anonymousId.

Test snipet:

```
[[SEGAnalytics sharedAnalytics] identify:@"Prateek" traits:nil options: @{
                                                                           @"anonymousId":@"test_anonymousId"
                                                                         }];
```

Event in debugger: https://cloudup.com/cFyVH4NPR_f

Subsequent events will automatically attach the new anonymous ID https://cloudup.com/cK-i_SCbwsN
@f2prateek f2prateek force-pushed the allow-setting-anonymousId branch from aa9fb47 to 0e98d4a Compare November 29, 2018 16:48
@f2prateek f2prateek merged commit 06b2003 into master Nov 29, 2018
@fathyb fathyb deleted the allow-setting-anonymousId branch November 29, 2018 17:10
Serheo pushed a commit to fubotv/analytics-ios that referenced this pull request Aug 15, 2019
Historically, the iOS library has allowed setting a custom anonymous identifier (segmentio#485).

During adding middlewares, a bug was introduced which started ignoring the anonymousId option.

This fixes the bug and adds a test to validate the fix. This was also tested in the example app end to end and I've verified that events show up with the custom anonymousId.

Test snipet:

```
[[SEGAnalytics sharedAnalytics] identify:@"Prateek" traits:nil options: @{
                                                                           @"anonymousId":@"test_anonymousId"
                                                                         }];
```

Event in debugger: https://cloudup.com/cFyVH4NPR_f

Subsequent events will automatically attach the new anonymous ID https://cloudup.com/cK-i_SCbwsN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to set anonymousId removed in 3.6.0
3 participants