@adshift/react-native-plugin 1.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/AdShiftReactNativePlugin.podspec +11 -7
  2. package/CHANGELOG.md +138 -0
  3. package/README.md +513 -542
  4. package/android/build.gradle +17 -3
  5. package/android/consumer-rules.pro +21 -0
  6. package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +786 -229
  7. package/android/src/test/java/com/adshift/reactnativeplugin/ConsentSnapshotTest.kt +180 -0
  8. package/android/src/test/java/com/adshift/reactnativeplugin/DeepLinkDeliveryTest.kt +146 -0
  9. package/android/src/test/java/com/adshift/reactnativeplugin/InitializeOrderingTest.kt +111 -0
  10. package/android/src/test/java/com/adshift/reactnativeplugin/IntentLinkDedupTest.kt +168 -0
  11. package/android/src/test/java/com/adshift/reactnativeplugin/LaunchIntentForwardingTest.kt +106 -0
  12. package/android/src/test/java/com/adshift/reactnativeplugin/ModuleTestSupport.kt +167 -0
  13. package/android/src/test/java/com/adshift/reactnativeplugin/StartVerdictTest.kt +164 -0
  14. package/ios/AdShiftReactNativePlugin.h +7 -7
  15. package/ios/AdShiftReactNativePlugin.mm +200 -181
  16. package/ios/AdShiftReactNativePluginHelper.swift +584 -286
  17. package/ios/Core/BridgeRules.swift +82 -0
  18. package/lib/commonjs/Adshift.js +1138 -0
  19. package/lib/commonjs/Adshift.js.map +1 -0
  20. package/lib/commonjs/NativeAdShiftReactNativePlugin.js +22 -0
  21. package/lib/commonjs/NativeAdShiftReactNativePlugin.js.map +1 -0
  22. package/lib/commonjs/index.js +94 -0
  23. package/lib/commonjs/index.js.map +1 -0
  24. package/lib/commonjs/jest/index.js +164 -0
  25. package/lib/commonjs/jest/index.js.map +1 -0
  26. package/lib/commonjs/nativeSdkVersions.js +17 -0
  27. package/lib/commonjs/nativeSdkVersions.js.map +1 -0
  28. package/lib/commonjs/package.json +1 -0
  29. package/lib/commonjs/types/AdshiftAdRevenue.js +47 -0
  30. package/lib/commonjs/types/AdshiftAdRevenue.js.map +1 -0
  31. package/lib/commonjs/types/AdshiftConfig.js +45 -0
  32. package/lib/commonjs/types/AdshiftConfig.js.map +1 -0
  33. package/lib/commonjs/types/AdshiftConsent.js +113 -0
  34. package/lib/commonjs/types/AdshiftConsent.js.map +1 -0
  35. package/lib/commonjs/types/AdshiftConsentSnapshot.js +69 -0
  36. package/lib/commonjs/types/AdshiftConsentSnapshot.js.map +1 -0
  37. package/lib/commonjs/types/AdshiftDeepLink.js +154 -0
  38. package/lib/commonjs/types/AdshiftDeepLink.js.map +1 -0
  39. package/lib/commonjs/types/AdshiftError.js +91 -0
  40. package/lib/commonjs/types/AdshiftError.js.map +1 -0
  41. package/lib/commonjs/types/AdshiftEventParam.js +140 -0
  42. package/lib/commonjs/types/AdshiftEventParam.js.map +1 -0
  43. package/lib/commonjs/types/AdshiftEventType.js +88 -0
  44. package/lib/commonjs/types/AdshiftEventType.js.map +1 -0
  45. package/lib/commonjs/types/AdshiftThirdPartySharing.js +70 -0
  46. package/lib/commonjs/types/AdshiftThirdPartySharing.js.map +1 -0
  47. package/lib/commonjs/types/index.js +123 -0
  48. package/lib/commonjs/types/index.js.map +1 -0
  49. package/lib/commonjs/version.js +9 -0
  50. package/lib/commonjs/version.js.map +1 -0
  51. package/lib/module/Adshift.js +962 -296
  52. package/lib/module/Adshift.js.map +1 -1
  53. package/lib/module/NativeAdShiftReactNativePlugin.js +10 -7
  54. package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -1
  55. package/lib/module/index.js +26 -25
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/jest/index.js +144 -0
  58. package/lib/module/jest/index.js.map +1 -0
  59. package/lib/module/nativeSdkVersions.js +13 -0
  60. package/lib/module/nativeSdkVersions.js.map +1 -0
  61. package/lib/module/types/AdshiftAdRevenue.js +43 -0
  62. package/lib/module/types/AdshiftAdRevenue.js.map +1 -0
  63. package/lib/module/types/AdshiftConfig.js +23 -26
  64. package/lib/module/types/AdshiftConfig.js.map +1 -1
  65. package/lib/module/types/AdshiftConsent.js +57 -50
  66. package/lib/module/types/AdshiftConsent.js.map +1 -1
  67. package/lib/module/types/AdshiftConsentSnapshot.js +65 -0
  68. package/lib/module/types/AdshiftConsentSnapshot.js.map +1 -0
  69. package/lib/module/types/AdshiftDeepLink.js +97 -67
  70. package/lib/module/types/AdshiftDeepLink.js.map +1 -1
  71. package/lib/module/types/AdshiftError.js +87 -0
  72. package/lib/module/types/AdshiftError.js.map +1 -0
  73. package/lib/module/types/AdshiftEventParam.js +135 -0
  74. package/lib/module/types/AdshiftEventParam.js.map +1 -0
  75. package/lib/module/types/AdshiftEventType.js +11 -36
  76. package/lib/module/types/AdshiftEventType.js.map +1 -1
  77. package/lib/module/types/AdshiftThirdPartySharing.js +65 -0
  78. package/lib/module/types/AdshiftThirdPartySharing.js.map +1 -0
  79. package/lib/module/types/index.js +9 -7
  80. package/lib/module/types/index.js.map +1 -1
  81. package/lib/module/version.js +5 -0
  82. package/lib/module/version.js.map +1 -0
  83. package/lib/typescript/commonjs/package.json +1 -0
  84. package/lib/typescript/commonjs/src/Adshift.d.ts +314 -0
  85. package/lib/typescript/commonjs/src/Adshift.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts +102 -0
  87. package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/index.d.ts +51 -0
  89. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/jest/index.d.ts +103 -0
  91. package/lib/typescript/commonjs/src/jest/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts +11 -0
  93. package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts +56 -0
  95. package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts +104 -0
  97. package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts +76 -0
  99. package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts +56 -0
  101. package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts +89 -0
  103. package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/types/AdshiftError.d.ts +57 -0
  105. package/lib/typescript/commonjs/src/types/AdshiftError.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts +111 -0
  107. package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts.map +1 -0
  108. package/lib/typescript/{src → commonjs/src}/types/AdshiftEventType.d.ts +12 -35
  109. package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts +53 -0
  111. package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts.map +1 -0
  112. package/lib/typescript/commonjs/src/types/index.d.ts +17 -0
  113. package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -0
  114. package/lib/typescript/commonjs/src/version.d.ts +2 -0
  115. package/lib/typescript/commonjs/src/version.d.ts.map +1 -0
  116. package/lib/typescript/module/src/Adshift.d.ts +314 -0
  117. package/lib/typescript/module/src/Adshift.d.ts.map +1 -0
  118. package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts +102 -0
  119. package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
  120. package/lib/typescript/module/src/index.d.ts +51 -0
  121. package/lib/typescript/module/src/index.d.ts.map +1 -0
  122. package/lib/typescript/module/src/jest/index.d.ts +103 -0
  123. package/lib/typescript/module/src/jest/index.d.ts.map +1 -0
  124. package/lib/typescript/module/src/nativeSdkVersions.d.ts +11 -0
  125. package/lib/typescript/module/src/nativeSdkVersions.d.ts.map +1 -0
  126. package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts +56 -0
  127. package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts.map +1 -0
  128. package/lib/typescript/module/src/types/AdshiftConfig.d.ts +104 -0
  129. package/lib/typescript/module/src/types/AdshiftConfig.d.ts.map +1 -0
  130. package/lib/typescript/module/src/types/AdshiftConsent.d.ts +76 -0
  131. package/lib/typescript/module/src/types/AdshiftConsent.d.ts.map +1 -0
  132. package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts +56 -0
  133. package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts.map +1 -0
  134. package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts +89 -0
  135. package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts.map +1 -0
  136. package/lib/typescript/module/src/types/AdshiftError.d.ts +57 -0
  137. package/lib/typescript/module/src/types/AdshiftError.d.ts.map +1 -0
  138. package/lib/typescript/module/src/types/AdshiftEventParam.d.ts +111 -0
  139. package/lib/typescript/module/src/types/AdshiftEventParam.d.ts.map +1 -0
  140. package/lib/typescript/module/src/types/AdshiftEventType.d.ts +64 -0
  141. package/lib/typescript/module/src/types/AdshiftEventType.d.ts.map +1 -0
  142. package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts +53 -0
  143. package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts.map +1 -0
  144. package/lib/typescript/module/src/types/index.d.ts +17 -0
  145. package/lib/typescript/module/src/types/index.d.ts.map +1 -0
  146. package/lib/typescript/module/src/version.d.ts +2 -0
  147. package/lib/typescript/module/src/version.d.ts.map +1 -0
  148. package/package.json +50 -11
  149. package/src/Adshift.ts +1276 -342
  150. package/src/NativeAdShiftReactNativePlugin.ts +81 -115
  151. package/src/index.tsx +40 -25
  152. package/src/jest/index.ts +224 -0
  153. package/src/nativeSdkVersions.ts +10 -0
  154. package/src/types/AdshiftAdRevenue.ts +58 -0
  155. package/src/types/AdshiftConfig.ts +101 -53
  156. package/src/types/AdshiftConsent.ts +75 -72
  157. package/src/types/AdshiftConsentSnapshot.ts +103 -0
  158. package/src/types/AdshiftDeepLink.ts +123 -102
  159. package/src/types/AdshiftError.ts +107 -0
  160. package/src/types/AdshiftEventParam.ts +216 -0
  161. package/src/types/AdshiftEventType.ts +13 -35
  162. package/src/types/AdshiftThirdPartySharing.ts +63 -0
  163. package/src/types/index.ts +38 -6
  164. package/src/version.ts +2 -0
  165. package/lib/typescript/src/Adshift.d.ts +0 -335
  166. package/lib/typescript/src/Adshift.d.ts.map +0 -1
  167. package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts +0 -143
  168. package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts.map +0 -1
  169. package/lib/typescript/src/index.d.ts +0 -47
  170. package/lib/typescript/src/index.d.ts.map +0 -1
  171. package/lib/typescript/src/types/AdshiftConfig.d.ts +0 -74
  172. package/lib/typescript/src/types/AdshiftConfig.d.ts.map +0 -1
  173. package/lib/typescript/src/types/AdshiftConsent.d.ts +0 -88
  174. package/lib/typescript/src/types/AdshiftConsent.d.ts.map +0 -1
  175. package/lib/typescript/src/types/AdshiftDeepLink.d.ts +0 -93
  176. package/lib/typescript/src/types/AdshiftDeepLink.d.ts.map +0 -1
  177. package/lib/typescript/src/types/AdshiftEventType.d.ts.map +0 -1
  178. package/lib/typescript/src/types/index.d.ts +0 -5
  179. package/lib/typescript/src/types/index.d.ts.map +0 -1
  180. /package/lib/typescript/{package.json → module/package.json} +0 -0
@@ -2,238 +2,302 @@
2
2
  // AdShiftReactNativePluginHelper.swift
3
3
  // AdShiftReactNativePlugin
4
4
  //
5
- // Swift helper that bridges Objective-C++ Turbo Module to Swift SDK.
6
- // Provides @objc compatible wrappers for Swift-only features.
5
+ // Swift bridge between the Objective-C++ Turbo Module and the AdShift iOS SDK.
7
6
  //
8
7
  // Copyright © 2025 AdShift. All rights reserved.
9
8
  //
10
9
 
11
10
  import Foundation
12
11
  import AdshiftSDK
12
+ import os
13
13
 
14
- /// Callback types for async operations
15
- public typealias StartCallback = ([String: Any]?, Error?) -> Void
16
- public typealias TrackCallback = ([String: Any]?, Error?) -> Void
17
- public typealias DeepLinkCallback = ([String: Any]?, Error?) -> Void
18
- public typealias DeepLinkEventCallback = ([String: Any]) -> Void
14
+ // MARK: - Objective-C facing types
19
15
 
20
- /// React Native helper class that provides @objc compatible methods for the Swift SDK.
16
+ /// Implemented by the Turbo Module. Receives serialised deep link payloads on the main thread.
17
+ /// Returns false when JavaScript cannot receive the payload, so it can be delivered later.
18
+ @objc public protocol AdShiftDeepLinkEmitting: AnyObject, Sendable {
19
+ func emitDeepLink(_ payload: [String: Any]) -> Bool
20
+ }
21
+
22
+ /// Delivers the `start()` result dictionary; `start()` never fails at the bridge level.
23
+ public typealias AdShiftStartCompletion = @Sendable ([String: Any]) -> Void
24
+ /// Delivers a result dictionary or a bridge `NSError` (see `BridgeError`).
25
+ public typealias AdShiftResultCompletion = @Sendable ([String: Any]?, NSError?) -> Void
26
+ public typealias AdShiftVoidCompletion = @Sendable (NSError?) -> Void
27
+ public typealias AdShiftStringCompletion = @Sendable (String?) -> Void
28
+ public typealias AdShiftBoolCompletion = @Sendable (Bool) -> Void
29
+
30
+ private let log = Logger(subsystem: "com.adshift.reactnativeplugin", category: "bridge")
31
+
32
+ // MARK: - Error model
33
+
34
+ /// Platform-neutral error passed to JavaScript.
35
+ ///
36
+ /// Serialised as an `NSError` whose `userInfo` carries the bridge `code`
37
+ /// plus the native SDK code and domain when available.
38
+ struct BridgeError: Error {
39
+ static let domain = "com.adshift.reactnativeplugin"
40
+
41
+ let code: String
42
+ let message: String
43
+ let nativeCode: Int?
44
+ let nativeDomain: String?
45
+
46
+ static func invalidArgument(_ message: String) -> BridgeError {
47
+ BridgeError(code: "INVALID_ARGUMENT", message: message, nativeCode: nil, nativeDomain: nil)
48
+ }
49
+
50
+ static let optedOut = BridgeError(
51
+ code: "OPTED_OUT",
52
+ message: "Tracking is disabled for this device",
53
+ nativeCode: nil,
54
+ nativeDomain: nil
55
+ )
56
+
57
+ var nsError: NSError {
58
+ var userInfo: [String: Any] = [
59
+ "code": code,
60
+ NSLocalizedDescriptionKey: message,
61
+ ]
62
+ if let nativeCode {
63
+ userInfo["nativeCode"] = nativeCode
64
+ }
65
+ if let nativeDomain {
66
+ userInfo["nativeDomain"] = nativeDomain
67
+ }
68
+ return NSError(domain: Self.domain, code: 0, userInfo: userInfo)
69
+ }
70
+ }
71
+
72
+ func mapError(_ error: Error) -> BridgeError {
73
+ let code: String
74
+ switch error {
75
+ case AdShiftError.notStarted:
76
+ code = "NOT_STARTED"
77
+ case AdShiftError.invalidAPIKey:
78
+ code = "INVALID_API_KEY"
79
+ case AdShiftError.trackingDisabled:
80
+ code = "OPTED_OUT"
81
+ default:
82
+ code = "UNKNOWN"
83
+ }
84
+ let nsError = error as NSError
85
+ return BridgeError(
86
+ code: code,
87
+ message: nsError.localizedDescription,
88
+ nativeCode: nsError.code,
89
+ nativeDomain: nsError.domain
90
+ )
91
+ }
92
+
93
+ // MARK: - Main-actor state
94
+
95
+ /// Mutable bridge state. Lives on the main actor together with the SDK.
96
+ @MainActor
97
+ private final class BridgeState {
98
+ static let shared = BridgeState()
99
+
100
+ /// The current Turbo Module instance; replaced on React Native reloads.
101
+ weak var emitter: AdShiftDeepLinkEmitting?
102
+ /// The SDK listener is registered once per process.
103
+ var isDeepLinkListenerRegistered = false
104
+ var pushDeepLinkPaths: Set<[String]> = []
105
+ /// Deep links kept while no module could receive them, oldest first.
106
+ var pendingDeepLinks: [[String: Any]] = []
107
+ /// URLs that opened this process, oldest first. Kept until the process dies,
108
+ /// because JavaScript reads the launch URL again after every reload.
109
+ var launchForwardedUrls: [String] = []
110
+
111
+ /// Deep link results are delivered once, so a reload must not consume them.
112
+ static let pendingDeepLinkLimit = 20
113
+ static let launchUrlMemoryLimit = 20
114
+
115
+ private init() {}
116
+ }
117
+
118
+ /// Carries a bridge value into a main-actor task. Sound only because the caller hands the
119
+ /// value over and never touches it again.
120
+ private struct BridgeValue<Value>: @unchecked Sendable {
121
+ let value: Value
122
+ }
123
+
124
+ // MARK: - Helper
125
+
126
+ /// Objective-C entry points for the Turbo Module.
21
127
  ///
22
- /// This is needed because:
23
- /// 1. AdshiftSDK uses @MainActor which requires Swift
24
- /// 2. Swift enums with associated values don't export to Objective-C
25
- /// 3. Swift async/await needs to be converted to callbacks for ObjC++
26
- @available(iOS 15.0, *)
27
- @objc public class AdShiftReactNativePluginHelper: NSObject {
28
-
29
- /// Shared instance
128
+ /// Every method returns immediately and performs the SDK call on the main
129
+ /// actor; results are delivered through `@Sendable` completion blocks.
130
+ @objc public final class AdShiftReactNativePluginHelper: NSObject, @unchecked Sendable {
131
+
30
132
  @objc public static let shared = AdShiftReactNativePluginHelper()
31
-
32
- /// Stored deep link event callback for NativeEventEmitter
33
- private var deepLinkEventCallback: DeepLinkEventCallback?
34
-
35
- /// Whether deep link listener is registered
36
- private var isDeepLinkListenerRegistered = false
37
-
133
+
38
134
  private override init() {
39
135
  super.init()
40
136
  }
41
-
42
- // MARK: - SDK Lifecycle
43
-
44
- /// Initializes the SDK with configuration dictionary
45
- @objc public func initialize(config: [String: Any]) {
137
+
138
+ // MARK: Module binding
139
+
140
+ /// Registers the module that receives deep link events and delivers anything kept for it.
141
+ @objc nonisolated public func setModule(_ module: AdShiftDeepLinkEmitting) {
46
142
  Task { @MainActor in
47
- // Required: API key
48
- if let apiKey = config["apiKey"] as? String, !apiKey.isEmpty {
49
- Adshift.shared.apiKey = apiKey
50
- }
51
-
52
- // Optional: Debug mode
53
- if let isDebug = config["isDebug"] as? Bool {
54
- Adshift.shared.isDebug = isDebug
143
+ let state = BridgeState.shared
144
+ state.emitter = module
145
+ let pending = state.pendingDeepLinks
146
+ guard !pending.isEmpty else { return }
147
+ state.pendingDeepLinks = []
148
+ for payload in pending {
149
+ Self.deliverDeepLink(payload)
55
150
  }
56
-
57
- // Optional: App open debounce
58
- if let appOpenDebounceMs = config["appOpenDebounceMs"] as? Int {
59
- Adshift.shared.appOpenDebounceMs = appOpenDebounceMs
60
- }
61
-
62
- // iOS only: SKAN settings
63
- if let disableSKAN = config["disableSKAN"] as? Bool {
64
- Adshift.shared.disableSKAN = disableSKAN
65
- }
66
-
67
- // iOS only: ATT settings
68
- if let waitForATTBeforeStart = config["waitForATTBeforeStart"] as? Bool {
69
- Adshift.shared.waitForATTBeforeStart = waitForATTBeforeStart
70
- }
71
-
72
- if let attTimeoutMs = config["attTimeoutMs"] as? Int {
73
- Adshift.shared.attTimeoutMs = attTimeoutMs
151
+ }
152
+ }
153
+
154
+ /// Unregisters `module`; a newer registration is left untouched.
155
+ @objc nonisolated public func clearModule(_ module: AdShiftDeepLinkEmitting) {
156
+ Task { @MainActor in
157
+ if BridgeState.shared.emitter === module {
158
+ BridgeState.shared.emitter = nil
74
159
  }
75
-
76
- // Android only options are ignored on iOS (collectOaid)
77
160
  }
78
161
  }
79
-
80
- /// Starts the SDK with completion callback
81
- @objc public func start(completion: @escaping StartCallback) {
162
+
163
+ // MARK: Lifecycle
164
+
165
+ /// Applies the configuration dictionary. Only keys that are present change SDK settings.
166
+ @objc nonisolated public func initialize(config: [String: Any]) {
167
+ let boxed = BridgeValue(value: config)
168
+ Task { @MainActor in
169
+ Self.applyConfig(boxed.value)
170
+ Self.registerDeepLinkListenerIfNeeded()
171
+ }
172
+ }
173
+
174
+ /// Starts the SDK. The result dictionary always contains `success`.
175
+ @objc nonisolated public func start(completion: @escaping AdShiftStartCompletion) {
82
176
  Task { @MainActor in
83
177
  Adshift.shared.start { response, error in
84
- if let error = error {
85
- completion(nil, error)
86
- } else {
87
- completion(response ?? ["success": true], nil)
88
- }
178
+ completion(Self.startResult(response: response, error: error))
89
179
  }
90
180
  }
91
181
  }
92
-
93
- /// Stops the SDK
94
- @objc public func stop() {
182
+
183
+ @objc nonisolated public func stop() {
95
184
  Task { @MainActor in
96
185
  Adshift.shared.stop()
97
186
  }
98
187
  }
99
-
100
- /// Checks if SDK is started
101
- @objc public func isStarted() -> Bool {
102
- // Must dispatch to MainActor since Adshift.shared is @MainActor isolated
103
- var result = false
104
- if Thread.isMainThread {
105
- result = MainActor.assumeIsolated {
106
- Adshift.shared.isStarted()
107
- }
108
- } else {
109
- DispatchQueue.main.sync {
110
- result = MainActor.assumeIsolated {
111
- Adshift.shared.isStarted()
112
- }
188
+
189
+ // MARK: Configuration
190
+
191
+ @objc nonisolated public func setCustomerUserId(_ userId: String) {
192
+ Task { @MainActor in
193
+ Adshift.shared.setCustomerUserId(userId)
194
+ }
195
+ }
196
+
197
+ @objc nonisolated public func setDebugEnabled(_ enabled: Bool) {
198
+ Task { @MainActor in
199
+ Adshift.shared.isDebug = enabled
200
+ }
201
+ }
202
+
203
+ @objc nonisolated public func setAppOpenDebounceMs(_ milliseconds: Double) {
204
+ Task { @MainActor in
205
+ if let value = Self.milliseconds(from: milliseconds) {
206
+ Adshift.shared.appOpenDebounceMs = value
113
207
  }
114
208
  }
115
- return result
116
209
  }
117
-
118
- // MARK: - Configuration
119
-
120
- /// Sets customer user ID
121
- @objc public func setCustomerUserId(_ userId: String) {
210
+
211
+ @objc nonisolated public func setBrandedDomains(_ domains: [String]) {
122
212
  Task { @MainActor in
123
- Adshift.shared.setCustomerUserId(userId)
213
+ Adshift.shared.brandedDomains = domains
124
214
  }
125
215
  }
126
-
127
- /// Sets debug mode
128
- @objc public func setDebugEnabled(_ enabled: Bool) {
216
+
217
+ /// Meta app id is used by the Android SDK only.
218
+ @objc nonisolated public func setMetaAppId(_ appId: String) {
219
+ log.debug("setMetaAppId has no effect on iOS")
220
+ }
221
+
222
+ /// OAID exists on Android devices only.
223
+ @objc nonisolated public func setOaidData(_ oaid: String) {
224
+ log.debug("setOaidData has no effect on iOS")
225
+ }
226
+
227
+ // MARK: Consent
228
+
229
+ @objc nonisolated public func setConsentData(_ consent: [String: Any]) {
230
+ let boxed = BridgeValue(value: consent)
129
231
  Task { @MainActor in
130
- Adshift.shared.isDebug = enabled
232
+ Adshift.shared.setConsentData(Self.consent(from: boxed.value))
131
233
  }
132
234
  }
133
-
134
- /// Sets app open debounce interval
135
- @objc public func setAppOpenDebounceMs(_ milliseconds: Int) {
235
+
236
+ @objc nonisolated public func enableTCFDataCollection(_ enabled: Bool) {
136
237
  Task { @MainActor in
137
- Adshift.shared.appOpenDebounceMs = milliseconds
238
+ Adshift.shared.enableTCFDataCollection(enabled)
138
239
  }
139
240
  }
140
-
141
- // MARK: - Consent
142
-
143
- /// Sets consent data from dictionary
144
- @objc public func setConsentData(_ consentDict: [String: Any]) {
241
+
242
+ @objc nonisolated public func enableGPPDataCollection(_ enabled: Bool) {
145
243
  Task { @MainActor in
146
- let isGDPR = consentDict["isUserSubjectToGDPR"] as? Bool ?? false
147
- let dataUsage = consentDict["hasConsentForDataUsage"] as? Bool ?? false
148
- let personalization = consentDict["hasConsentForAdsPersonalization"] as? Bool ?? false
149
- let storage = consentDict["hasConsentForAdStorage"] as? Bool ?? false
150
-
151
- let consent: AdShiftConsent
152
- if isGDPR {
153
- consent = AdShiftConsent.forGDPRUser(
154
- hasConsentForDataUsage: dataUsage,
155
- hasConsentForAdsPersonalization: personalization,
156
- hasConsentForAdStorage: storage
157
- )
158
- } else {
159
- consent = AdShiftConsent.forNonGDPRUser()
244
+ Adshift.shared.enableGPPDataCollection(enabled)
245
+ }
246
+ }
247
+
248
+ /// A call carrying no usable answer is dropped rather than defaulted; the
249
+ /// reasoning sits with the rule in `BridgeRules`.
250
+ @objc nonisolated public func setThirdPartySharing(_ sharing: [String: Any]) {
251
+ let boxed = BridgeValue(value: sharing)
252
+ Task { @MainActor in
253
+ guard let optOut = BridgeRules.thirdPartySharingOptOut(from: boxed.value) else {
254
+ return
160
255
  }
161
-
162
- Adshift.shared.setConsentData(consent)
256
+ Adshift.shared.setThirdPartySharing(
257
+ optOut ? AdShiftThirdPartySharing.optedOut() : AdShiftThirdPartySharing.allowed()
258
+ )
163
259
  }
164
260
  }
165
-
166
- /// Enables/disables TCF data collection
167
- @objc public func enableTCFDataCollection(_ enabled: Bool) {
261
+
262
+ @objc nonisolated public func clearThirdPartySharing() {
168
263
  Task { @MainActor in
169
- Adshift.shared.enableTCFDataCollection(enabled)
264
+ Adshift.shared.clearThirdPartySharing()
170
265
  }
171
266
  }
172
-
173
- /// Refreshes consent state
174
- @objc public func refreshConsent(completion: @escaping ([String: Any]?, Error?) -> Void) {
267
+
268
+ @objc nonisolated public func refreshConsent(completion: @escaping AdShiftResultCompletion) {
175
269
  Task { @MainActor in
176
270
  let snapshot = Adshift.shared.refreshConsent()
177
- // Convert ConsentSnapshot to dictionary
178
- var result: [String: Any] = [
179
- "source": snapshot.source.rawValue.lowercased(),
180
- "tcStringPresent": snapshot.tcStringPresent,
181
- "appliedAtMillis": snapshot.appliedAtMillis
182
- ]
183
-
184
- // Optional fields
185
- if let gdprApplies = snapshot.gdprApplies {
186
- result["gdprApplies"] = gdprApplies
187
- }
188
- if let adUserDataEnabled = snapshot.adUserDataEnabled {
189
- result["adUserDataEnabled"] = adUserDataEnabled
190
- }
191
- if let adPersonalizationEnabled = snapshot.adPersonalizationEnabled {
192
- result["adPersonalizationEnabled"] = adPersonalizationEnabled
193
- }
194
- if let adStorageEnabled = snapshot.adStorageEnabled {
195
- result["adStorageEnabled"] = adStorageEnabled
196
- }
197
-
198
- // Convenience field for JS
199
- result["hasConsent"] = (snapshot.adStorageEnabled == true) || (snapshot.adUserDataEnabled == true)
200
-
201
- completion(result, nil)
202
- }
203
- }
204
-
205
- // MARK: - Event Tracking
206
-
207
- /// Tracks an event with optional values
208
- @objc public func trackEvent(
271
+ completion(Self.serialize(snapshot), nil)
272
+ }
273
+ }
274
+
275
+ // MARK: Event tracking
276
+
277
+ @objc nonisolated public func trackEvent(
209
278
  _ eventName: String,
210
279
  values: [String: Any]?,
211
- completion: @escaping TrackCallback
280
+ completion: @escaping AdShiftVoidCompletion
212
281
  ) {
282
+ let boxed = BridgeValue(value: values)
213
283
  Task { @MainActor in
214
- let eventType = mapStringToEventType(eventName)
215
-
284
+ let eventValues = boxed.value.map(Self.coerceEventValues)
216
285
  await Adshift.shared.track(
217
- event: eventType,
218
- values: values,
286
+ event: Self.eventType(for: eventName),
287
+ values: eventValues,
219
288
  completionHandler: { response, error in
220
- if let error = error {
221
- completion(nil, error)
222
- } else {
223
- completion(response, nil)
224
- }
289
+ completion(Self.trackingOutcome(response, error))
225
290
  }
226
291
  )
227
292
  }
228
293
  }
229
-
230
- /// Tracks a purchase event
231
- @objc public func trackPurchase(
294
+
295
+ @objc nonisolated public func trackPurchase(
232
296
  productId: String,
233
297
  price: Double,
234
298
  currency: String,
235
299
  token: String,
236
- completion: @escaping TrackCallback
300
+ completion: @escaping AdShiftVoidCompletion
237
301
  ) {
238
302
  Task { @MainActor in
239
303
  await Adshift.shared.trackPurchase(
@@ -242,75 +306,335 @@ public typealias DeepLinkEventCallback = ([String: Any]) -> Void
242
306
  currency: currency,
243
307
  token: token,
244
308
  completionHandler: { response, error in
245
- if let error = error {
246
- completion(nil, error)
247
- } else {
248
- completion(response, nil)
249
- }
309
+ completion(Self.trackingOutcome(response, error))
250
310
  }
251
311
  )
252
312
  }
253
313
  }
254
-
255
- // MARK: - Deep Links
256
-
257
- /// Handles a deep link URL
258
- @objc public func handleDeepLink(
259
- _ urlString: String,
260
- completion: @escaping DeepLinkCallback
314
+
315
+ /// Turns the answer to a tracking call into a single outcome.
316
+ ///
317
+ /// An excluded device comes back as a status next to no error, and it is a
318
+ /// refusal to record the event, so JavaScript is told so on both platforms.
319
+ private static func trackingOutcome(_ response: [String: Any]?, _ error: Error?) -> NSError? {
320
+ if let error {
321
+ return mapError(error).nsError
322
+ }
323
+ guard BridgeRules.isExcludedFromTracking(responseStatus: response?["status"] as? String)
324
+ else { return nil }
325
+ return BridgeError.optedOut.nsError
326
+ }
327
+
328
+ @objc nonisolated public func logAdRevenue(
329
+ _ data: [String: Any],
330
+ completion: @escaping AdShiftVoidCompletion
261
331
  ) {
262
- guard let url = URL(string: urlString) else {
263
- let error = NSError(
264
- domain: "AdShiftReactNativePlugin",
265
- code: -1,
266
- userInfo: [NSLocalizedDescriptionKey: "Invalid URL: \(urlString)"]
267
- )
268
- completion(nil, error)
269
- return
332
+ let boxed = BridgeValue(value: data)
333
+ Task { @MainActor in
334
+ switch Self.adRevenueInput(from: boxed.value) {
335
+ case .failure(let error):
336
+ completion(error.nsError)
337
+ case .success(let input):
338
+ await Adshift.shared.logAdRevenue(
339
+ input.data,
340
+ additionalParameters: input.additionalParameters
341
+ )
342
+ completion(nil)
343
+ }
270
344
  }
271
-
345
+ }
346
+
347
+ // MARK: Identity
348
+
349
+ @objc nonisolated public func getAdShiftDeviceId(completion: @escaping AdShiftStringCompletion) {
350
+ Task { @MainActor in
351
+ completion(Adshift.shared.getAdShiftDeviceId())
352
+ }
353
+ }
354
+
355
+ // MARK: Deep links
356
+
357
+ /// Passes a URL to the SDK. The result is delivered through the deep link listener only.
358
+ ///
359
+ /// `fromLaunch` marks the URL that opened the app. Those are remembered for the lifetime of
360
+ /// the process, so a JavaScript reload cannot book the same link twice, while a second tap
361
+ /// arrives as a live URL and is forwarded.
362
+ @objc nonisolated public func handleDeepLink(
363
+ _ urlString: String,
364
+ fromLaunch: Bool,
365
+ completion: @escaping AdShiftVoidCompletion
366
+ ) {
272
367
  Task { @MainActor in
368
+ guard let url = URL(string: urlString),
369
+ let scheme = url.scheme, !scheme.isEmpty else {
370
+ completion(BridgeError.invalidArgument("url must be an absolute URL").nsError)
371
+ return
372
+ }
373
+ if fromLaunch {
374
+ let state = BridgeState.shared
375
+ if state.launchForwardedUrls.contains(urlString) {
376
+ log.debug("Launch URL already forwarded in this process")
377
+ completion(nil)
378
+ return
379
+ }
380
+ state.launchForwardedUrls.append(urlString)
381
+ if state.launchForwardedUrls.count > BridgeState.launchUrlMemoryLimit {
382
+ state.launchForwardedUrls.removeFirst()
383
+ }
384
+ }
273
385
  do {
274
- let response = try await Adshift.shared.handleDeepLink(url: url)
275
- let result = serializeDeepLinkResponse(response)
276
- completion(result, nil)
386
+ _ = try await Adshift.shared.handleDeepLink(url: url)
387
+ completion(nil)
388
+ } catch AdShiftError.trackingDisabled {
389
+ log.debug("Deep link ignored: tracking is disabled")
390
+ completion(nil)
277
391
  } catch {
278
- let result: [String: Any] = [
279
- "status": "error",
280
- "errorMessage": error.localizedDescription,
281
- "isDeferred": false
282
- ]
283
- completion(result, nil)
392
+ completion(mapError(error).nsError)
393
+ }
394
+ }
395
+ }
396
+
397
+ @objc nonisolated public func addPushNotificationDeepLinkPath(_ path: [String]) {
398
+ Task { @MainActor in
399
+ Self.registerPushDeepLinkPath(path)
400
+ }
401
+ }
402
+
403
+ @objc nonisolated public func handlePushNotification(
404
+ _ payload: [AnyHashable: Any],
405
+ completion: @escaping AdShiftBoolCompletion
406
+ ) {
407
+ let boxed = BridgeValue(value: payload)
408
+ Task { @MainActor in
409
+ completion(Adshift.shared.handlePushNotification(userInfo: boxed.value))
410
+ }
411
+ }
412
+
413
+ // MARK: - Main-actor helpers
414
+
415
+ @MainActor
416
+ private static func applyConfig(_ config: [String: Any]) {
417
+ let sdk = Adshift.shared
418
+ if let isDebug = boolValue(config["isDebug"]) {
419
+ sdk.isDebug = isDebug
420
+ }
421
+ if let apiKey = config["apiKey"] as? String, !apiKey.isEmpty {
422
+ sdk.apiKey = apiKey
423
+ }
424
+ if let value = (config["appOpenDebounceMs"] as? NSNumber)?.doubleValue,
425
+ let milliseconds = milliseconds(from: value) {
426
+ sdk.appOpenDebounceMs = milliseconds
427
+ }
428
+ if let disableSKAN = boolValue(config["disableSKAN"]) {
429
+ sdk.disableSKAN = disableSKAN
430
+ }
431
+ if let waitForATT = boolValue(config["waitForATTBeforeStart"]) {
432
+ sdk.waitForATTBeforeStart = waitForATT
433
+ }
434
+ if let value = (config["attTimeoutMs"] as? NSNumber)?.doubleValue,
435
+ let milliseconds = milliseconds(from: value) {
436
+ sdk.attTimeoutMs = milliseconds
437
+ }
438
+ if let domains = config["brandedDomains"] as? [String] {
439
+ sdk.brandedDomains = domains
440
+ }
441
+ if let paths = config["pushDeepLinkPaths"] as? [[String]] {
442
+ for path in paths {
443
+ registerPushDeepLinkPath(path)
444
+ }
445
+ }
446
+ // `collectOaid` and `metaAppId` apply to Android only;
447
+ // `autoHandleDeepLinks` is handled in JavaScript.
448
+ }
449
+
450
+ @MainActor
451
+ private static func registerDeepLinkListenerIfNeeded() {
452
+ let state = BridgeState.shared
453
+ guard !state.isDeepLinkListenerRegistered else { return }
454
+ state.isDeepLinkListenerRegistered = true
455
+ Adshift.shared.onDeepLinkReceived { response in
456
+ deliverDeepLink(serialize(response))
457
+ }
458
+ }
459
+
460
+ @MainActor
461
+ private static func deliverDeepLink(_ payload: [String: Any]) {
462
+ if BridgeState.shared.emitter?.emitDeepLink(payload) == true { return }
463
+ let state = BridgeState.shared
464
+ while state.pendingDeepLinks.count >= BridgeState.pendingDeepLinkLimit {
465
+ state.pendingDeepLinks.removeFirst()
466
+ }
467
+ state.pendingDeepLinks.append(payload)
468
+ }
469
+
470
+ @MainActor
471
+ private static func registerPushDeepLinkPath(_ path: [String]) {
472
+ guard !path.isEmpty, !path.contains(where: \.isEmpty) else { return }
473
+ guard BridgeState.shared.pushDeepLinkPaths.insert(path).inserted else { return }
474
+ Adshift.shared.addPushNotificationDeepLinkPath(path)
475
+ }
476
+
477
+ // MARK: - Pure helpers
478
+
479
+ private static func startResult(response: [String: Any]?, error: Error?) -> [String: Any] {
480
+ if let error {
481
+ if case AdShiftError.alreadyStarted = error {
482
+ return ["success": true]
284
483
  }
484
+ let mapped = mapError(error)
485
+ var result: [String: Any] = [
486
+ "success": false,
487
+ "errorCode": mapped.code,
488
+ "errorMessage": mapped.message,
489
+ ]
490
+ if let nativeCode = mapped.nativeCode {
491
+ result["nativeCode"] = nativeCode
492
+ }
493
+ if let nativeDomain = mapped.nativeDomain {
494
+ result["nativeDomain"] = nativeDomain
495
+ }
496
+ return result
285
497
  }
498
+ var result: [String: Any] = ["success": true]
499
+ result["apiKeyValidationStatus"] = (response?["api_key_validation_status"] as? String) ?? "pending"
500
+ if let sdkVersion = response?["sdk_version"] as? String {
501
+ result["sdkVersion"] = sdkVersion
502
+ }
503
+ return result
286
504
  }
287
-
288
- /// Registers deep link event callback for NativeEventEmitter
289
- @objc public func setDeepLinkEventCallback(_ callback: @escaping DeepLinkEventCallback) {
290
- self.deepLinkEventCallback = callback
291
-
292
- // Register with native SDK only once
293
- if !isDeepLinkListenerRegistered {
294
- Task { @MainActor in
295
- Adshift.shared.onDeepLinkReceived { [weak self] response in
296
- guard let self = self, let callback = self.deepLinkEventCallback else { return }
297
- let serialized = self.serializeDeepLinkResponse(response)
298
- callback(serialized)
505
+
506
+ private static func boolValue(_ value: Any?) -> Bool? {
507
+ (value as? NSNumber)?.boolValue
508
+ }
509
+
510
+ private static func milliseconds(from value: Double) -> Int? {
511
+ guard value.isFinite, value >= 0 else { return nil }
512
+ return Int(min(value, Double(Int32.max)).rounded())
513
+ }
514
+
515
+ /// Restricts event values to strings, numbers and booleans.
516
+ ///
517
+ /// Booleans arrive as `NSNumber` and are converted to `Bool`; other numbers
518
+ /// stay `NSNumber`. Null, array and dictionary values are dropped.
519
+ private static func coerceEventValues(_ values: [String: Any]) -> [String: Any] {
520
+ var result: [String: Any] = [:]
521
+ result.reserveCapacity(values.count)
522
+ for (key, value) in values {
523
+ switch value {
524
+ case let string as String:
525
+ result[key] = string
526
+ case let number as NSNumber:
527
+ if CFGetTypeID(number) == CFBooleanGetTypeID() {
528
+ result[key] = number.boolValue
529
+ } else {
530
+ result[key] = number
299
531
  }
532
+ case is NSNull:
533
+ continue
534
+ default:
535
+ log.debug("Dropped event value of unsupported type for key \(key, privacy: .public)")
300
536
  }
301
- isDeepLinkListenerRegistered = true
302
537
  }
538
+ return result
303
539
  }
304
-
305
- /// Clears deep link event callback
306
- @objc public func clearDeepLinkEventCallback() {
307
- deepLinkEventCallback = nil
540
+
541
+ private static func consent(from dictionary: [String: Any]) -> AdShiftConsent {
542
+ guard boolValue(dictionary["isUserSubjectToGDPR"]) == true else {
543
+ return AdShiftConsent.forNonGDPRUser()
544
+ }
545
+ return AdShiftConsent.forGDPRUser(
546
+ hasConsentForDataUsage: boolValue(dictionary["hasConsentForDataUsage"]),
547
+ hasConsentForAdsPersonalization: boolValue(dictionary["hasConsentForAdsPersonalization"]),
548
+ hasConsentForAdStorage: boolValue(dictionary["hasConsentForAdStorage"])
549
+ )
308
550
  }
309
-
310
- // MARK: - Private Helpers
311
-
312
- /// Maps string event name to ASInAppEventType enum
313
- private func mapStringToEventType(_ eventName: String) -> ASInAppEventType {
551
+
552
+ private static func serialize(_ snapshot: ConsentSnapshot) -> [String: Any] {
553
+ var result: [String: Any] = [
554
+ "source": snapshot.source.rawValue.lowercased(),
555
+ "tcStringPresent": snapshot.tcStringPresent,
556
+ "gppPresent": snapshot.gppPresent,
557
+ "cmpDetected": snapshot.cmpDetected,
558
+ "appliedAtMillis": snapshot.appliedAtMillis,
559
+ ]
560
+ if let gdprApplies = snapshot.gdprApplies {
561
+ result["gdprApplies"] = gdprApplies
562
+ }
563
+ if let adUserDataEnabled = snapshot.adUserDataEnabled {
564
+ result["adUserDataEnabled"] = adUserDataEnabled
565
+ }
566
+ if let adPersonalizationEnabled = snapshot.adPersonalizationEnabled {
567
+ result["adPersonalizationEnabled"] = adPersonalizationEnabled
568
+ }
569
+ if let adStorageEnabled = snapshot.adStorageEnabled {
570
+ result["adStorageEnabled"] = adStorageEnabled
571
+ }
572
+ result["adIdentifiersAllowed"] = BridgeRules.adIdentifiersAllowed(
573
+ adStorageEnabled: snapshot.adStorageEnabled,
574
+ adUserDataEnabled: snapshot.adUserDataEnabled
575
+ )
576
+ return result
577
+ }
578
+
579
+ private struct AdRevenueInput {
580
+ let data: ASAdRevenueData
581
+ let additionalParameters: [String: Any]?
582
+ }
583
+
584
+ private static func adRevenueInput(from dictionary: [String: Any]) -> Result<AdRevenueInput, BridgeError> {
585
+ guard let monetizationNetwork = dictionary["monetizationNetwork"] as? String,
586
+ !monetizationNetwork.isEmpty else {
587
+ return .failure(.invalidArgument("monetizationNetwork is required"))
588
+ }
589
+ guard let mediationRawValue = dictionary["mediationNetwork"] as? String,
590
+ !mediationRawValue.isEmpty else {
591
+ return .failure(.invalidArgument("mediationNetwork is required"))
592
+ }
593
+ guard let currency = dictionary["currency"] as? String, !currency.isEmpty else {
594
+ return .failure(.invalidArgument("currency is required"))
595
+ }
596
+ guard currency.count == 3 else {
597
+ return .failure(.invalidArgument("currency must be a 3-letter ISO 4217 code"))
598
+ }
599
+ guard let revenue = (dictionary["revenue"] as? NSNumber)?.doubleValue else {
600
+ return .failure(.invalidArgument("revenue is required"))
601
+ }
602
+ guard revenue.isFinite, revenue > 0 else {
603
+ return .failure(.invalidArgument("revenue must be a positive number"))
604
+ }
605
+
606
+ let data = ASAdRevenueData(
607
+ monetizationNetwork: monetizationNetwork,
608
+ mediationNetwork: ASMediationNetwork(rawValue: mediationRawValue) ?? .other,
609
+ currencyIso4217Code: currency,
610
+ revenue: revenue
611
+ )
612
+
613
+ // Keys written by the SDK from `ASAdRevenueData` take precedence over client parameters.
614
+ let sdkOwnedKeys: Set<String> = [
615
+ ASInAppEventParameterName.revenue,
616
+ ASInAppEventParameterName.currency,
617
+ ASInAppEventParameterName.adRevenueSource,
618
+ ASInAppEventParameterName.adRevenueNetworkName,
619
+ ]
620
+ var additional: [String: Any] = [:]
621
+ if let extra = dictionary["additionalParameters"] as? [String: Any] {
622
+ additional = coerceEventValues(extra).filter { !sdkOwnedKeys.contains($0.key) }
623
+ }
624
+ if let adUnitId = dictionary["adUnitId"] as? String {
625
+ additional[ASInAppEventParameterName.adRevenueAdUnitId] = adUnitId
626
+ }
627
+ if let precision = dictionary["precision"] as? String {
628
+ additional[ASInAppEventParameterName.adRevenuePrecision] = precision
629
+ }
630
+
631
+ return .success(AdRevenueInput(
632
+ data: data,
633
+ additionalParameters: additional.isEmpty ? nil : additional
634
+ ))
635
+ }
636
+
637
+ private static func eventType(for eventName: String) -> ASInAppEventType {
314
638
  switch eventName {
315
639
  case "as_purchase": return .purchase
316
640
  case "as_login": return .login
@@ -341,73 +665,47 @@ public typealias DeepLinkEventCallback = ([String: Any]) -> Void
341
665
  case "as_location_coordinates": return .locationCoordinates
342
666
  case "as_order_id": return .orderId
343
667
  case "as_customer_segment": return .customerSegment
668
+ case "as_ad_revenue": return .adRevenue
344
669
  default: return .customEvent(eventName)
345
670
  }
346
671
  }
347
-
348
- /// Serializes DeeplinkResponse to dictionary for React Native
349
- private func serializeDeepLinkResponse(_ response: DeeplinkResponse) -> [String: Any] {
350
- var result: [String: Any] = [:]
351
-
352
- // Deep link URL
353
- if let deeplink = response.deeplink {
354
- result["deepLink"] = deeplink
355
- }
356
-
357
- // Deep link value (for routing)
358
- if let value = response.deep_link_value {
359
- result["deepLinkValue"] = value
360
- }
361
-
362
- // Sub parameters
363
- if let sub1 = response.deep_link_sub1 { result["deepLinkSub1"] = sub1 }
364
- if let sub2 = response.deep_link_sub2 { result["deepLinkSub2"] = sub2 }
365
- if let sub3 = response.deep_link_sub3 { result["deepLinkSub3"] = sub3 }
366
- if let sub4 = response.deep_link_sub4 { result["deepLinkSub4"] = sub4 }
367
- if let sub5 = response.deep_link_sub5 { result["deepLinkSub5"] = sub5 }
368
-
369
- // Parameters
370
- if let params = response.params, !params.isEmpty {
371
- result["params"] = params
372
- }
373
-
374
- // Is deferred
375
- result["isDeferred"] = response.isDeferred ?? false
376
-
377
- // Status
378
- if let status = response.status {
379
- switch status {
380
- case .found:
381
- result["status"] = "found"
382
- case .notFound:
383
- result["status"] = "notFound"
384
- case .error:
385
- result["status"] = "error"
386
- @unknown default:
387
- result["status"] = response.deeplink != nil ? "found" : "notFound"
388
- }
389
- } else {
390
- result["status"] = response.deeplink != nil ? "found" : "notFound"
391
- }
392
-
393
- // Error message
394
- if let error = response.error {
395
- result["status"] = "error"
396
- switch error {
397
- case .decodingError:
398
- result["errorMessage"] = "Decoding error"
399
- case .invalidURL:
400
- result["errorMessage"] = "Invalid URL"
401
- case .deepLinkNotFound:
402
- result["errorMessage"] = "Deep link not found"
403
- case .systemError(let message):
404
- result["errorMessage"] = message
405
- @unknown default:
406
- result["errorMessage"] = "Unknown error"
407
- }
672
+
673
+ /// Serialises a deep link response for JavaScript.
674
+ private static func serialize(_ response: DeeplinkResponse) -> [String: Any] {
675
+ BridgeRules.deepLinkPayload(
676
+ deepLink: response.deeplink,
677
+ deepLinkValue: response.deep_link_value,
678
+ subs: [
679
+ response.deep_link_sub1,
680
+ response.deep_link_sub2,
681
+ response.deep_link_sub3,
682
+ response.deep_link_sub4,
683
+ response.deep_link_sub5,
684
+ ],
685
+ params: response.params,
686
+ reportedIsDeferred: response.isDeferred,
687
+ reportedStatus: statusName(response.status),
688
+ errorMessage: response.error.map(message(for:))
689
+ )
690
+ }
691
+
692
+ private static func statusName(_ status: DeepLinkStatus?) -> String? {
693
+ switch status {
694
+ case .found?: return "found"
695
+ case .notFound?: return "notFound"
696
+ case .error?: return "error"
697
+ case nil: return nil
698
+ @unknown default: return nil
408
699
  }
409
-
410
- return result
411
700
  }
412
- }
413
701
 
702
+ private static func message(for error: DeepLinkError) -> String {
703
+ switch error {
704
+ case .decodingError: return "Decoding error"
705
+ case .invalidURL: return "Invalid URL"
706
+ case .deepLinkNotFound: return "Deep link not found"
707
+ case .systemError(let message): return message
708
+ @unknown default: return "Unknown error"
709
+ }
710
+ }
711
+ }