From 5bcfb2f07ad84431e28dcef3df075e13accbb5d2 Mon Sep 17 00:00:00 2001 From: Carlos Nogueira Date: Tue, 28 Oct 2025 09:50:04 +0000 Subject: [PATCH] Conditionally remove webview tracking from tvOS builds --- packages/core/ios/Sources/DatadogSDKWrapper.swift | 7 ++++++- packages/core/ios/Sources/DdSdk.mm | 2 ++ packages/core/ios/Sources/DdSdkImplementation.swift | 13 ++++++++++--- .../ios/Sources/DdSdkNativeInitialization.swift | 9 ++++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/core/ios/Sources/DatadogSDKWrapper.swift b/packages/core/ios/Sources/DatadogSDKWrapper.swift index 0b9e51573..58ae82b73 100644 --- a/packages/core/ios/Sources/DatadogSDKWrapper.swift +++ b/packages/core/ios/Sources/DatadogSDKWrapper.swift @@ -10,10 +10,13 @@ import DatadogRUM import DatadogLogs import DatadogTrace import DatadogCrashReporting -import DatadogWebViewTracking import DatadogInternal import Foundation +#if os(iOS) +import DatadogWebViewTracking +#endif + public typealias OnSdkInitializedListener = () -> Void /// Wrapper around the Datadog SDK. Use DatadogSDKWrapper.shared to access the instance. @@ -47,6 +50,7 @@ public class DatadogSDKWrapper { self.loggerConfiguration = loggerConfiguration } +#if os(iOS) // Webview private var webviewMessageEmitter: InternalExtension.AbstractMessageEmitter? @@ -57,6 +61,7 @@ public class DatadogSDKWrapper { internal func sendWebviewMessage(body: NSString) throws { try self.webviewMessageEmitter?.send(body: body) } +#endif } diff --git a/packages/core/ios/Sources/DdSdk.mm b/packages/core/ios/Sources/DdSdk.mm index 7129d7af1..06736a69e 100644 --- a/packages/core/ios/Sources/DdSdk.mm +++ b/packages/core/ios/Sources/DdSdk.mm @@ -149,9 +149,11 @@ - (dispatch_queue_t)methodQueue { return [RNQueue getSharedQueue]; } +#if TARGET_OS_IOS - (void)consumeWebviewEvent:(NSString *)message resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { [self.ddSdkImplementation consumeWebviewEventWithMessage:message resolve:resolve reject:reject]; } +#endif - (void)initialize:(NSDictionary *)configuration resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { [self.ddSdkImplementation initializeWithConfiguration:configuration resolve:resolve reject:reject]; diff --git a/packages/core/ios/Sources/DdSdkImplementation.swift b/packages/core/ios/Sources/DdSdkImplementation.swift index 87fe91729..1f7186a54 100644 --- a/packages/core/ios/Sources/DdSdkImplementation.swift +++ b/packages/core/ios/Sources/DdSdkImplementation.swift @@ -10,10 +10,13 @@ import DatadogInternal import DatadogLogs import DatadogRUM import DatadogTrace -import DatadogWebViewTracking import Foundation import React +#if os(iOS) +import DatadogWebViewTracking +#endif + func getDefaultAppVersion() -> String { let bundleShortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String @@ -28,7 +31,10 @@ public class DdSdkImplementation: NSObject { let mainDispatchQueue: DispatchQueueType let RUMMonitorProvider: () -> RUMMonitorProtocol let RUMMonitorInternalProvider: () -> RUMMonitorInternalProtocol? + +#if os(iOS) var webviewMessageEmitter: InternalExtension.AbstractMessageEmitter? +#endif private let jsLongTaskThresholdInSeconds: TimeInterval = 0.1 @@ -193,11 +199,12 @@ public class DdSdkImplementation: NSObject { resolve(nil) } +#if os(iOS) @objc public func consumeWebviewEvent( message: NSString, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock ) { - do { + do{ try DatadogSDKWrapper.shared.sendWebviewMessage(body: message) } catch { DdTelemetry.telemetryError( @@ -206,9 +213,9 @@ public class DdSdkImplementation: NSObject { kind: "WebViewEventBridgeError" as String, stack: String(describing: error) as String) } - resolve(nil) } +#endif @objc public func clearAllData(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) { diff --git a/packages/core/ios/Sources/DdSdkNativeInitialization.swift b/packages/core/ios/Sources/DdSdkNativeInitialization.swift index 7b0f1be19..e6e5a1911 100644 --- a/packages/core/ios/Sources/DdSdkNativeInitialization.swift +++ b/packages/core/ios/Sources/DdSdkNativeInitialization.swift @@ -10,10 +10,13 @@ import DatadogRUM import DatadogLogs import DatadogTrace import DatadogCrashReporting -import DatadogWebViewTracking import DatadogInternal import React +#if os(iOS) +import DatadogWebViewTracking +#endif + @objc public class DdSdkNativeInitialization: NSObject { let jsonFileReader: ResourceFileReader @@ -90,6 +93,10 @@ public class DdSdkNativeInitialization: NSObject { if sdkConfiguration.nativeCrashReportEnabled ?? false { CrashReporting.enable() } + + #if os(iOS) + DatadogSDKWrapper.shared.enableWebviewTracking() + #endif } func buildSDKConfiguration(configuration: DdSdkConfiguration, defaultAppVersion: String = getDefaultAppVersion()) -> Datadog.Configuration {