Skip to content

In 1.4.x of analytics-swift the track() call in ObjCAnalytics forces properties to [Any, Codable] and NSDictionaries don't support Codable #224

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

Closed
cwheeler42 opened this issue May 9, 2023 · 3 comments · Fixed by #226
Assignees
Labels

Comments

@cwheeler42
Copy link

Describe the bug
In the 1.4.x version of the library, the ObjCAnalytics track calls have been changed to call back to the Swift functions forcing the properties parameter to [Any, Codable]. This causes all properties to be dropped from Segment track calls and the event to have no properties and no indication anything is wrong.

From line 42 of ObjCAnalytics.swift:

    @objc(track:properties:)
    public func track(name: String, properties: [String: Any]?) {
        analytics.track(name: name, properties: properties as? [String: Codable])
    }

The Events.swift track method that is being called here even takes [String: Any] so it's only this code in the ObjCAnalytics helpers that is enforcing Codable and causing it not to work with NSDictionaries for properties.

To Reproduce
Steps to reproduce the behavior:

  1. From ObjC, set up a SEGAnalytics object
  2. Create an NSDictionary or NSMutableDictionary for properties
  3. Call track with that properties object
  4. No properties will be sent to Segment (if you step through the track calls, the one in Events.swift will have a nil properties object) and no errors are displayed or returned.

Expected behavior
I understand the point of creating strongly typed properties, but ObjC doesn't support this directly, so it would be helpful if the ObjCAnalytics object didn't try to enforce Codable on the properties. Even your example for Objective-C in the documentation just says to pass a simple dictionary: https://segment.com/docs/connections/sources/catalog/libraries/mobile/apple/implementation/#track

This worked fine in 1.3.5 of the library and was only changed recently. We have temporarily reverted our use of analytics-swift back to 1.3.5 because of this issue.

Platform (please complete the following information):

  • Library Version in use: 1.4.x
  • Platform being tested: iOS
  • Integrations in use: None
@bsneed
Copy link
Contributor

bsneed commented May 10, 2023

Thanks @cwheeler42 ! I've got one more bug to look at it before doing a release. Will likely be later today or tomorrow.

@bsneed
Copy link
Contributor

bsneed commented May 15, 2023

@cwheeler42
Copy link
Author

Thank you--I'll give it an update and try now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants