-
Notifications
You must be signed in to change notification settings - Fork 240
Add device_id as an automatic context value for Feature Flags #675
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: msiebert <1504059+msiebert@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the feature flags context by automatically including a device_id
(the anonymous ID) alongside the existing distinct_id
when making feature flag API requests.
- Added
getAnonymousId()
to the delegate and Mixpanel instance - Updated context-building logic to conditionally include
device_id
- Extended and added tests for anonymous ID behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
Sources/MixpanelInstance.swift | Exposed getAnonymousId() returning the instance’s anonymousId |
Sources/FeatureFlags.swift | Added protocol method and context logic to include device_id |
MixpanelDemo/MixpanelDemoTests/MixpanelFeatureFlagTests.swift | Extended mock delegate and added tests for anonymous ID scenarios |
Comments suppressed due to low confidence (3)
MixpanelDemo/MixpanelDemoTests/MixpanelFeatureFlagTests.swift:887
- The new tests verify delegate call counts but don’t assert that the HTTP request body actually includes
device_id
. To fully cover this feature, stub or intercept the network request and assertrequestBodyDict["context"]["device_id"] == testAnonymousId
.
func testFeatureFlagContextIncludesDeviceId() {
Sources/MixpanelInstance.swift:465
- [nitpick] Add a doc comment explaining that this returns the current anonymous device ID used in feature flag context. This helps maintainers understand its purpose and usage.
public func getAnonymousId() -> String? {
Sources/FeatureFlags.swift:74
- [nitpick] Document the new
getAnonymousId()
in theMixpanelFlagDelegate
protocol (e.g., mark it with///
) so implementers know when and why to return an anonymous ID.
func getAnonymousId() -> String?
Using this commit as a reference, please implement tracking for for |
…ment_started events Co-authored-by: msiebert <1504059+msiebert@users.noreply.github.com>
I've implemented tracking for
Both properties are now included in all |
The latest commit introduces the following compilation error:
|
Co-authored-by: msiebert <1504059+msiebert@users.noreply.github.com>
... Fixed the compilation error by removing the intermediate |
Tests fail due to the following error:
|
…rties Co-authored-by: msiebert <1504059+msiebert@users.noreply.github.com>
... Fixed the private access level issue by changing |
This PR adds
device_id
as an automatic context value for Feature Flags, using the anonymous ID as the context property value. Thedevice_id
is now included alongside the existingdistinct_id
in the feature flags context when making requests to the feature flags API.Changes Made
getAnonymousId()
method to provide access to the anonymous IDgetAnonymousId()
to return theanonymousId
propertydevice_id
in the context when anonymous ID is availableMockFeatureFlagDelegate
to support the new methoddevice_id
inclusion in both scenarios (with and without anonymous ID)Implementation Details
The implementation follows the same pattern as the Android SDK (as referenced in the issue). When building the feature flags context in
_performFetchRequest()
, the code now:This ensures that:
distinct_id
is always included (existing behavior)device_id
is included whenanonymousId
is not nilfeatureFlagsContext
Testing
Added comprehensive tests to verify:
device_id
is included in context when anonymous ID is availabledevice_id
is omitted when anonymous ID is nilFixes #674.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.