diff --git a/README.md b/README.md index eb77779..0daf9d3 100644 --- a/README.md +++ b/README.md @@ -74,17 +74,27 @@ TelemetryDeck.signal("Database.updated", parameters: ["numberOfDatabaseEntries": TelemetryDeck will automatically send base parameters, such as: +- TelemetryDeck.Accessibility.isBoldTextEnabled +- TelemetryDeck.Accessibility.isDarkerSystemColorsEnabled +- TelemetryDeck.Accessibility.isInvertColorsEnabled +- TelemetryDeck.Accessibility.isReduceMotionEnabled +- TelemetryDeck.Accessibility.isReduceTransparencyEnabled +- TelemetryDeck.Accessibility.isSwitchControlEnabled +- TelemetryDeck.Accessibility.isVoiceOverEnabled +- TelemetryDeck.Accessibility.preferredContentSizeCategory +- TelemetryDeck.Accessibility.shouldDifferentiateWithoutColor + - TelemetryDeck.AppInfo.buildNumber - TelemetryDeck.AppInfo.version - TelemetryDeck.Device.architecture - TelemetryDeck.Device.modelName - TelemetryDeck.Device.operatingSystem -- TelemetryDeck.Device.platform - TelemetryDeck.Device.orientation +- TelemetryDeck.Device.platform - TelemetryDeck.Device.screenResolutionHeight - TelemetryDeck.Device.screenResolutionWidth -- TelemetryDeck.Device.systemMajorVersion - TelemetryDeck.Device.systemMajorMinorVersion +- TelemetryDeck.Device.systemMajorVersion - TelemetryDeck.Device.systemVersion - TelemetryDeck.Device.timeZone - TelemetryDeck.RunContext.isAppStore @@ -94,9 +104,10 @@ TelemetryDeck will automatically send base parameters, such as: - TelemetryDeck.RunContext.language - TelemetryDeck.RunContext.targetEnvironment - TelemetryDeck.SDK.version -- TelemetryDeck.UserPreference.region -- TelemetryDeck.UserPreference.language - TelemetryDeck.UserPreference.colorScheme +- TelemetryDeck.UserPreference.language +- TelemetryDeck.UserPreference.layoutDirection +- TelemetryDeck.UserPreference.region See our [Grand Renaming article](https://telemetrydeck.com/docs/articles/grand-rename/?source=github) for a full list. diff --git a/Sources/TelemetryDeck/Signals/Signal.swift b/Sources/TelemetryDeck/Signals/Signal.swift index 5330840..5a65ef4 100644 --- a/Sources/TelemetryDeck/Signals/Signal.swift +++ b/Sources/TelemetryDeck/Signals/Signal.swift @@ -94,11 +94,14 @@ public struct DefaultSignalPayload: Encodable { "TelemetryDeck.SDK.nameAndVersion": "SwiftSDK \(sdkVersion)", "TelemetryDeck.SDK.version": sdkVersion, + "TelemetryDeck.UserPreference.colorScheme": Self.colorScheme, "TelemetryDeck.UserPreference.language": Self.preferredLanguage, + "TelemetryDeck.UserPreference.layoutDirection": Self.layoutDirection, "TelemetryDeck.UserPreference.region": Self.region, - "TelemetryDeck.UserPreference.colorScheme": Self.colorScheme ] + parameters.merge(self.accessibilityParameters, uniquingKeysWith: { $1 }) + if let extensionIdentifier = Self.extensionIdentifier { // deprecated name parameters["extensionIdentifier"] = extensionIdentifier @@ -114,6 +117,34 @@ public struct DefaultSignalPayload: Encodable { // MARK: - Helpers extension DefaultSignalPayload { + @MainActor + static var accessibilityParameters: [String: String] { + var a11yParams: [String: String] = [:] + + #if os(iOS) || os(tvOS) + a11yParams["TelemetryDeck.Accessibility.isVoiceOverEnabled"] = "\(UIAccessibility.isVoiceOverRunning)" + a11yParams["TelemetryDeck.Accessibility.isReduceMotionEnabled"] = "\(UIAccessibility.isReduceMotionEnabled)" + a11yParams["TelemetryDeck.Accessibility.isBoldTextEnabled"] = "\(UIAccessibility.isBoldTextEnabled)" + a11yParams["TelemetryDeck.Accessibility.isInvertColorsEnabled"] = "\(UIAccessibility.isInvertColorsEnabled)" + a11yParams["TelemetryDeck.Accessibility.isDarkerSystemColorsEnabled"] = "\(UIAccessibility.isDarkerSystemColorsEnabled)" + a11yParams["TelemetryDeck.Accessibility.isReduceTransparencyEnabled"] = "\(UIAccessibility.isReduceTransparencyEnabled)" + if #available(iOS 13.0, *) { + a11yParams["TelemetryDeck.Accessibility.shouldDifferentiateWithoutColor"] = "\(UIAccessibility.shouldDifferentiateWithoutColor)" + } + a11yParams["TelemetryDeck.Accessibility.preferredContentSizeCategory"] = UIApplication.shared.preferredContentSizeCategory.rawValue + .replacingOccurrences(of: "UICTContentSizeCategory", with: "") // replaces output "UICTContentSizeCategoryL" with "L" + a11yParams["TelemetryDeck.Accessibility.isSwitchControlEnabled"] = "\(UIAccessibility.isSwitchControlRunning)" + #elseif os(macOS) + a11yParams["TelemetryDeck.Accessibility.isVoiceOverEnabled"] = "\(NSWorkspace.shared.isVoiceOverEnabled)" + if let systemPrefs = UserDefaults.standard.persistentDomain(forName: "com.apple.universalaccess") { + a11yParams["TelemetryDeck.Accessibility.isReduceMotionEnabled"] = "\(systemPrefs["reduceMotion"] as? Bool ?? false)" + a11yParams["TelemetryDeck.Accessibility.isInvertColorsEnabled"] = "\(systemPrefs["InvertColors"] as? Bool ?? false)" + } + #endif + + return a11yParams + } + static var isSimulatorOrTestFlight: Bool { isSimulator || isTestFlight } @@ -368,6 +399,18 @@ extension DefaultSignalPayload { #endif } + /// The user-preferred layout direction (left-to-right or right-to-left) based on the current language/region settings. + @MainActor + static var layoutDirection: String { + #if os(iOS) || os(tvOS) + return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft" + #elseif os(macOS) + return NSApp.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft" + #else + return "N/A" + #endif + } + /// The current devices screen resolution width in points. @MainActor static var screenResolutionWidth: String {