snowplow / snowplow-ios-tracker

Snowplow event tracker for Swift and Objective-C. Add analytics to your iOS, macOS, tvOS and watchOS apps and games
http://snowplow.io
Apache License 2.0
81 stars 93 forks source link

Providing `TrackerConfiguration` overrides the `TrackerDefaults.devicePlatform` #893

Open markst opened 4 months ago

markst commented 4 months ago

Describe the bug

If no devicePlatform is provided to TrackerConfiguration, the device platform defaults to mobile

To Reproduce

Device platform is initialised here: https://github.com/snowplow/snowplow-ios-tracker/blob/master/Sources/Core/Utils/Utilities.swift#L45

Tracker adds devicePlatform with param p to payload: https://github.com/snowplow/snowplow-ios-tracker/blob/master/Sources/Core/Tracker/Tracker.swift#L525

Which is redefined here when providing TrackerConfiguration: https://github.com/snowplow/snowplow-ios-tracker/blob/master/Sources/Core/Tracker/ServiceProvider.swift#L298

Which defaults to DevicePlatform.mobile

Device information (please complete the following information):

markst commented 4 months ago

One solution could be to use the TrackerDefaults.devicePlatform for the nil coalescing optional TrackerConfiguration initialiser:

        if let devicePlatform = dictionary["devicePlatform"] as? String {
            self.devicePlatform = stringToDevicePlatform(devicePlatform) ?? TrackerDefaults.devicePlatform
        }
markst commented 4 months ago

or in the getter optional rather than defaulting to mobile:

    @objc
    public var devicePlatform: DevicePlatform {
        get { return _devicePlatform ?? sourceConfig?.devicePlatform ?? TrackerDefaults.devicePlatform }
markst commented 4 months ago

our solution for now is to simply provide a devicePlatform:

TrackerConfiguration()
    .appId(appId)
    .devicePlatform(.current)
extension DevicePlatform {
  /// Local replacement for `Utilities.platform`
  static var current: DevicePlatform {
#if os(tvOS)
    return .connectedTV
#else
    return .mobile
#endif
  }
}