Skip to content

Fix context issue and macOS vendor system miss. #44

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

Merged
merged 5 commits into from
Aug 19, 2021
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
2 changes: 2 additions & 0 deletions Sources/Segment/Plugins/Platforms/Vendors/VendorSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ internal class VendorSystem {
static var current: VendorSystem {
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
return iOSVendorSystem()
#elseif os(macOS)
return MacOSVendorSystem()
#elseif os(watchOS)
return watchOSVendorSystem()
#elseif os(Linux)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Segment/Startup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ extension Analytics: Subscriber {
internal func platformPlugins() -> [PlatformPlugin]? {
var plugins = [PlatformPlugin]()

// add context plugin as well as it's platform specific internally.
// this must come first.
plugins.append(Context())

// setup lifecycle if desired
if configuration.values.trackApplicationLifecycleEvents {
// add context plugin as well as it's platform specific internally.
// this must come first.
plugins.append(Context())

#if os(iOS) || os(tvOS)
plugins += [iOSLifecycleMonitor(), iOSLifecycleEvents(), DeviceToken()]
#endif
Expand Down
33 changes: 33 additions & 0 deletions Tests/Segment-Tests/Analytics_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,39 @@ final class Analytics_Tests: XCTestCase {
XCTAssertTrue(anonId.count == 36) // it's a UUID y0.
}

func testContext() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
let outputReader = OutputReaderPlugin()
analytics.add(plugin: outputReader)

waitUntilStarted(analytics: analytics)

analytics.track(name: "token check")

let trackEvent: TrackEvent? = outputReader.lastEvent as? TrackEvent
let context = trackEvent?.context?.dictionaryValue
// Verify that context isn't empty here.
// We need to verify the values but will do that in separate platform specific tests.
XCTAssertNotNil(context)
XCTAssertNotNil(context?["screen"], "screen missing!")
XCTAssertNotNil(context?["network"], "network missing!")
XCTAssertNotNil(context?["os"], "os missing!")
XCTAssertNotNil(context?["timezone"], "timezone missing!")
XCTAssertNotNil(context?["library"], "library missing!")
XCTAssertNotNil(context?["device"], "device missing!")

// this key not present on watchOS (doesn't have webkit)
#if !os(watchOS)
XCTAssertNotNil(context?["userAgent"], "userAgent missing!")
#endif

// these keys not present on linux
#if !os(Linux)
XCTAssertNotNil(context?["app"], "app missing!")
XCTAssertNotNil(context?["locale"], "locale missing!")
#endif
}

func testDeviceToken() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
let outputReader = OutputReaderPlugin()
Expand Down