@kerdly/expo 0.0.0-stage → 0.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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -2
  3. package/android/build.gradle +61 -0
  4. package/android/src/main/AndroidManifest.xml +19 -0
  5. package/android/src/main/java/com/kerdly/expo/KerdlySdkModule.kt +326 -0
  6. package/android/vendor/kerdly-sdk/.kerdly-sync.json +8 -0
  7. package/android/vendor/kerdly-sdk/consumer-rules.pro +15 -0
  8. package/android/vendor/kerdly-sdk/kerdly-sdk.properties +2 -0
  9. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/Kerdly.kt +343 -0
  10. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/KerdlyTypes.kt +89 -0
  11. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Attribution.kt +39 -0
  12. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Batch.kt +159 -0
  13. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Core.kt +991 -0
  14. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeepLinks.kt +114 -0
  15. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeferredLinks.kt +111 -0
  16. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeviceContext.kt +137 -0
  17. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/EventQueue.kt +135 -0
  18. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Events.kt +314 -0
  19. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Json.kt +116 -0
  20. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Logger.kt +49 -0
  21. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Options.kt +47 -0
  22. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Ports.kt +83 -0
  23. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/PublicIp.kt +120 -0
  24. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Referrers.kt +137 -0
  25. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/RemoteConfig.kt +100 -0
  26. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Storage.kt +271 -0
  27. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidPlatform.kt +274 -0
  28. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidRuntime.kt +187 -0
  29. package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/PlayReferrerReader.kt +97 -0
  30. package/app.plugin.js +2 -0
  31. package/build/Kerdly.d.ts +106 -0
  32. package/build/Kerdly.d.ts.map +1 -0
  33. package/build/Kerdly.js +494 -0
  34. package/build/Kerdly.js.map +1 -0
  35. package/build/index.d.ts +4 -0
  36. package/build/index.d.ts.map +1 -0
  37. package/build/index.js +2 -0
  38. package/build/index.js.map +1 -0
  39. package/build/log.d.ts +13 -0
  40. package/build/log.d.ts.map +1 -0
  41. package/build/log.js +45 -0
  42. package/build/log.js.map +1 -0
  43. package/build/native.d.ts +74 -0
  44. package/build/native.d.ts.map +1 -0
  45. package/build/native.js +56 -0
  46. package/build/native.js.map +1 -0
  47. package/build/normalize.d.ts +8 -0
  48. package/build/normalize.d.ts.map +1 -0
  49. package/build/normalize.js +86 -0
  50. package/build/normalize.js.map +1 -0
  51. package/build/types.d.ts +134 -0
  52. package/build/types.d.ts.map +1 -0
  53. package/build/types.js +3 -0
  54. package/build/types.js.map +1 -0
  55. package/build/validation.d.ts +70 -0
  56. package/build/validation.d.ts.map +1 -0
  57. package/build/validation.js +349 -0
  58. package/build/validation.js.map +1 -0
  59. package/build/version.d.ts +4 -0
  60. package/build/version.d.ts.map +1 -0
  61. package/build/version.js +5 -0
  62. package/build/version.js.map +1 -0
  63. package/expo-module.config.json +9 -0
  64. package/ios/KerdlySDK/.kerdly-sync.json +7 -0
  65. package/ios/KerdlySDK/Core/Dependencies.swift +163 -0
  66. package/ios/KerdlySDK/Core/KerdlyCore+API.swift +117 -0
  67. package/ios/KerdlySDK/Core/KerdlyCore+Collectors.swift +410 -0
  68. package/ios/KerdlySDK/Core/KerdlyCore+DeferredLinks.swift +220 -0
  69. package/ios/KerdlySDK/Core/KerdlyCore+Delivery.swift +424 -0
  70. package/ios/KerdlySDK/Core/KerdlyCore.swift +557 -0
  71. package/ios/KerdlySDK/Core/Support.swift +95 -0
  72. package/ios/KerdlySDK/Logic/Backoff.swift +22 -0
  73. package/ios/KerdlySDK/Logic/Batch.swift +180 -0
  74. package/ios/KerdlySDK/Logic/Context.swift +85 -0
  75. package/ios/KerdlySDK/Logic/DeepLinks.swift +93 -0
  76. package/ios/KerdlySDK/Logic/DeferredLinks.swift +239 -0
  77. package/ios/KerdlySDK/Logic/Environment.swift +39 -0
  78. package/ios/KerdlySDK/Logic/EventQueue.swift +85 -0
  79. package/ios/KerdlySDK/Logic/EventValidator.swift +84 -0
  80. package/ios/KerdlySDK/Logic/Events.swift +102 -0
  81. package/ios/KerdlySDK/Logic/IPv6Address.swift +26 -0
  82. package/ios/KerdlySDK/Logic/InstallIdentity.swift +106 -0
  83. package/ios/KerdlySDK/Logic/JSONValue.swift +198 -0
  84. package/ios/KerdlySDK/Logic/Purchases.swift +84 -0
  85. package/ios/KerdlySDK/Logic/RemoteConfig.swift +185 -0
  86. package/ios/KerdlySDK/Logic/Skan.swift +343 -0
  87. package/ios/KerdlySDK/Logic/StandardEvents.swift +126 -0
  88. package/ios/KerdlySDK/Platform/AdSignals.swift +19 -0
  89. package/ios/KerdlySDK/Platform/DeferredLinkBundle.swift +25 -0
  90. package/ios/KerdlySDK/Platform/DeviceInfo.swift +82 -0
  91. package/ios/KerdlySDK/Platform/Lifecycle.swift +74 -0
  92. package/ios/KerdlySDK/Platform/PublicIp.swift +33 -0
  93. package/ios/KerdlySDK/Platform/SkanWriter.swift +70 -0
  94. package/ios/KerdlySDK/Platform/StoreKitAdapter.swift +185 -0
  95. package/ios/KerdlySDK/Platform/SystemStores.swift +200 -0
  96. package/ios/KerdlySDK/Platform/Tracking.swift +124 -0
  97. package/ios/KerdlySDK/Public/Kerdly.swift +202 -0
  98. package/ios/KerdlySDK/Public/KerdlyTypes.swift +130 -0
  99. package/ios/KerdlySDK/Resources/PrivacyInfo.xcprivacy +95 -0
  100. package/ios/KerdlySDK/Storage/PersistedState.swift +175 -0
  101. package/ios/KerdlySDK/Storage/StateStore.swift +36 -0
  102. package/ios/KerdlySdk.podspec +45 -0
  103. package/ios/KerdlySdkModule.swift +332 -0
  104. package/package.json +92 -4
  105. package/plugin/withKerdly.js +163 -0
  106. package/src/Kerdly.ts +524 -0
  107. package/src/index.ts +23 -0
  108. package/src/log.ts +49 -0
  109. package/src/native.ts +150 -0
  110. package/src/normalize.ts +82 -0
  111. package/src/types.ts +183 -0
  112. package/src/validation.ts +343 -0
  113. package/src/version.ts +5 -0
@@ -0,0 +1,124 @@
1
+ import Foundation
2
+ import UIKit
3
+ import AppTrackingTransparency
4
+
5
+ final class SystemTracking: TrackingAuthorizing {
6
+ func status() -> KerdlyAttStatus {
7
+ Self.map(ATTrackingManager.trackingAuthorizationStatus)
8
+ }
9
+
10
+ func canPrompt() -> Bool {
11
+ Bundle.main.object(forInfoDictionaryKey: "NSUserTrackingUsageDescription") != nil
12
+ }
13
+
14
+ func request(_ completion: @escaping @Sendable (KerdlyAttStatus) -> Void) {
15
+ ATTrackingManager.requestTrackingAuthorization { status in
16
+ completion(Self.map(status))
17
+ }
18
+ }
19
+
20
+ static func map(_ status: ATTrackingManager.AuthorizationStatus) -> KerdlyAttStatus {
21
+ switch status {
22
+ case .authorized: return .authorized
23
+ case .denied: return .denied
24
+ case .restricted: return .restricted
25
+ case .notDetermined: return .notDetermined
26
+ @unknown default: return .notDetermined
27
+ }
28
+ }
29
+ }
30
+
31
+ /// `Kerdly.requestTrackingAuthorization`. iOS shows the ATT dialog only while the app is active; asked
32
+ /// earlier (a cold launch's first moments, a background launch) it returns `notDetermined` at once
33
+ /// and never asks again. So when the app is not active the request waits for
34
+ /// `didBecomeActiveNotification`. A caller still waiting after 5 s is released with the current
35
+ /// status, while the request stays armed: the dialog appears when the user opens the app, and the
36
+ /// SDK records the answer as `$consent`. Concurrent callers share one system request. The SDK never
37
+ /// calls this on its own.
38
+ @MainActor
39
+ final class TrackingPrompter {
40
+ private let releaseAfter: TimeInterval
41
+ private let tracking: TrackingAuthorizing
42
+ private let center: NotificationCenter
43
+ private let isActive: @MainActor () -> Bool
44
+ private let onDecision: @Sendable (KerdlyAttStatus) -> Void
45
+ private let log: KerdlyLogger
46
+ private var waiters: [Int: (KerdlyAttStatus) -> Void] = [:]
47
+ private var nextWaiter = 0
48
+ private var requesting = false
49
+ private var observer: NSObjectProtocol?
50
+
51
+ init(tracking: TrackingAuthorizing, center: NotificationCenter = .default,
52
+ isActive: @escaping @MainActor () -> Bool, log: KerdlyLogger, releaseAfter: TimeInterval = 5,
53
+ onDecision: @escaping @Sendable (KerdlyAttStatus) -> Void) {
54
+ self.releaseAfter = releaseAfter
55
+ self.tracking = tracking
56
+ self.center = center
57
+ self.isActive = isActive
58
+ self.log = log
59
+ self.onDecision = onDecision
60
+ }
61
+
62
+ var isArmed: Bool { observer != nil }
63
+
64
+ func request(_ completion: @escaping (KerdlyAttStatus) -> Void) {
65
+ let current = tracking.status()
66
+ guard current == .notDetermined else {
67
+ completion(current)
68
+ return
69
+ }
70
+ guard tracking.canPrompt() else {
71
+ log.error("requestTrackingAuthorization: NSUserTrackingUsageDescription is missing from Info.plist")
72
+ completion(current)
73
+ return
74
+ }
75
+ nextWaiter += 1
76
+ let id = nextWaiter
77
+ waiters[id] = completion
78
+ if requesting { return }
79
+ if isActive() {
80
+ fire()
81
+ return
82
+ }
83
+ arm()
84
+ DispatchQueue.main.asyncAfter(deadline: .now() + releaseAfter) { [weak self] in
85
+ MainActor.assumeIsolated {
86
+ guard let self, !self.requesting, let waiter = self.waiters.removeValue(forKey: id) else { return }
87
+ self.log.info("ATT request still waiting for the app to become active; released the caller")
88
+ waiter(self.tracking.status())
89
+ }
90
+ }
91
+ }
92
+
93
+ private func arm() {
94
+ guard observer == nil else { return }
95
+ log.info("ATT request deferred until the app is active")
96
+ observer = center.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil,
97
+ queue: .main) { [weak self] _ in
98
+ MainActor.assumeIsolated { self?.fire() }
99
+ }
100
+ }
101
+
102
+ private func fire() {
103
+ if let observer {
104
+ center.removeObserver(observer)
105
+ self.observer = nil
106
+ }
107
+ guard !requesting else { return }
108
+ requesting = true
109
+ tracking.request { [weak self] status in
110
+ guard let prompter = self else { return }
111
+ DispatchQueue.main.async {
112
+ MainActor.assumeIsolated { prompter.settle(status) }
113
+ }
114
+ }
115
+ }
116
+
117
+ private func settle(_ status: KerdlyAttStatus) {
118
+ requesting = false
119
+ let pending = waiters
120
+ waiters = [:]
121
+ pending.keys.sorted().forEach { pending[$0]?(status) }
122
+ onDecision(status)
123
+ }
124
+ }
@@ -0,0 +1,202 @@
1
+ import Foundation
2
+ import UIKit
3
+
4
+ /// The Kerdly attribution SDK. Every method is safe to call from any thread, before or after
5
+ /// `configure` (earlier calls are replayed once the SDK has started), and never throws into the app.
6
+ public enum Kerdly {
7
+ static var core: KerdlyCore { KerdlyCore.shared }
8
+
9
+ /// Starts the SDK. Synchronous and cheap: resolves the install id, loads the queue and enqueues
10
+ /// `$install` (when due) and `$open`; everything else runs on a background queue. Call it once,
11
+ /// early in `application(_:didFinishLaunchingWithOptions:)`.
12
+ public static func configure(_ options: KerdlyOptions) {
13
+ core.configure(options)
14
+ }
15
+
16
+ /// The install id (a lowercase UUID), nil until `configure` has resolved it.
17
+ public static var installId: String? {
18
+ core.installIdBox.get()
19
+ }
20
+
21
+ /// The app's user id, attached to every later event; nil on logout. Emits `$identify` on change.
22
+ public static func setUserId(_ userId: String?) {
23
+ core.apiSetUserId(userId)
24
+ }
25
+
26
+ /// A custom event. `name` matches `^[a-z][a-z0-9_]{0,39}$`; at most 25 properties whose keys match
27
+ /// the same pattern and whose values are strings (≤ 256 characters), finite numbers or booleans.
28
+ /// Anything else is dropped with a debug log. A standard event's name (`registration`,
29
+ /// `start_trial`, `subscribe`, `purchase`) gets its typed props checked as the typed methods do.
30
+ public static func track(_ name: String, properties: [String: Any] = [:]) {
31
+ core.apiTrack(name, properties: properties)
32
+ }
33
+
34
+ // MARK: Standard events
35
+ //
36
+ // Each enqueues an ordinary event (`registration`, `start_trial`, `subscribe`, `purchase`) with
37
+ // its typed props; nil arguments are left out. `productId` and `transactionId` are cut to 128
38
+ // characters, `method` to 64. `value` (what the user paid in `currency`; 0 for a free trial) must
39
+ // be finite and ≥ 0, and is dropped without a valid ISO 4217 `currency` (trimmed and
40
+ // upper-cased by the SDK). `quantity` must be ≥ 1. `properties` adds custom props under the
41
+ // `track` rules (the typed ones count toward the 25); an argument wins over a property of the
42
+ // same key. Anything dropped is logged at debug level.
43
+
44
+ /// `registration`. `method`: how the user signed up (`anonymous`, `apple`, `google`, `email`, …).
45
+ public static func trackRegistration(method: String? = nil, properties: [String: Any] = [:]) {
46
+ core.apiTrackRegistration(method: method, properties: properties)
47
+ }
48
+
49
+ /// `start_trial`: a trial began (`value` 0 for a free trial).
50
+ public static func trackStartTrial(productId: String? = nil, value: Double? = nil, currency: String? = nil,
51
+ transactionId: String? = nil, properties: [String: Any] = [:]) {
52
+ core.apiTrackStartTrial(productId: productId, value: value, currency: currency,
53
+ transactionId: transactionId, properties: properties)
54
+ }
55
+
56
+ /// `subscribe`: a paid subscription began.
57
+ public static func trackSubscribe(productId: String? = nil, value: Double? = nil, currency: String? = nil,
58
+ transactionId: String? = nil, properties: [String: Any] = [:]) {
59
+ core.apiTrackSubscribe(productId: productId, value: value, currency: currency,
60
+ transactionId: transactionId, properties: properties)
61
+ }
62
+
63
+ /// `purchase`: a one-time purchase.
64
+ public static func trackPurchase(productId: String? = nil, value: Double? = nil, currency: String? = nil,
65
+ quantity: Int? = nil, transactionId: String? = nil,
66
+ properties: [String: Any] = [:]) {
67
+ core.apiTrackPurchase(productId: productId, value: value, currency: currency, quantity: quantity,
68
+ transactionId: transactionId, properties: properties)
69
+ }
70
+
71
+ /// Consent flags (nil leaves a flag unchanged). `analytics == false` keeps only the reserved
72
+ /// install/attribution events; `ads == false` stops IDFA reads. Emits `$consent` on change.
73
+ public static func setConsent(analytics: Bool? = nil, ads: Bool? = nil) {
74
+ core.apiSetConsent(analytics: analytics, ads: ads)
75
+ }
76
+
77
+ /// Records a URL the app was opened with (`$deeplink`) and returns the params parsed from its
78
+ /// query string: `cpp`, `ppid`, `kerdly_c`, `kerdly_v`, `campaign_ids`. Call it from every URL entry
79
+ /// point (`application(_:open:options:)`, `scene(_:openURLContexts:)`, universal links).
80
+ ///
81
+ /// `source`: `"initial"` for the URL that launched the app, `"runtime"` for a later one. Nil (or
82
+ /// any other value) lets the SDK infer it: the first URL within a minute of `configure`, before
83
+ /// the app went to the background, is `initial`. An explicit `"initial"` uses up the inferred one,
84
+ /// so a later call without a source is `runtime`.
85
+ @discardableResult
86
+ public static func handleUrl(_ url: URL, source: String? = nil) -> KerdlyDeepLink? {
87
+ core.apiHandleUrl(url, source: source)
88
+ }
89
+
90
+ /// The `appAccountToken` the app's purchases carry (e.g. Superwall's alias UUID). Emits `$ids`.
91
+ public static func setAppAccountToken(_ token: UUID?) {
92
+ core.apiSetAppAccountToken(token)
93
+ }
94
+
95
+ /// Ids other SDKs in the app own (e.g. `meta_anon_id`, `superwall_alias`). Merged into the stored
96
+ /// map; an empty value removes its key. Emits `$ids` on change.
97
+ public static func setPartnerIds(_ ids: [String: String]) {
98
+ core.apiSetPartnerIds(ids)
99
+ }
100
+
101
+ /// A purchase the paywall just completed (its ids win over what StoreKit reports). With no
102
+ /// argument, sweeps `Transaction.currentEntitlements` instead. Each original transaction id is
103
+ /// reported once per install (`$purchase_link`).
104
+ public static func notifyPurchase(_ purchase: KerdlyPurchase? = nil) {
105
+ core.apiNotifyPurchase(purchase)
106
+ }
107
+
108
+ /// A send the app just made through an ad network's SDK (`$network_send`).
109
+ public static func recordNetworkSend(_ send: KerdlyNetworkSend) {
110
+ core.apiRecordNetworkSend(send)
111
+ }
112
+
113
+ /// The install's attribution, cached on the device; nil until the server has decided it.
114
+ public static var attribution: KerdlyAttribution? {
115
+ core.apiAttribution
116
+ }
117
+
118
+ /// Called on the main thread whenever the attribution is first known or changes (and at once if
119
+ /// it is already known).
120
+ public static func onAttribution(_ handler: @escaping (KerdlyAttribution) -> Void) {
121
+ core.addAttributionHandler(UncheckedSendable(handler))
122
+ }
123
+
124
+ /// Asks for App Tracking Transparency. Waits until the app is active (iOS shows the dialog only
125
+ /// then); a caller still waiting after 5 s gets the current status, and the dialog still appears
126
+ /// once the app becomes active. Needs `NSUserTrackingUsageDescription` in Info.plist. The SDK
127
+ /// never prompts on its own. `completion` runs on the main thread.
128
+ public static func requestTrackingAuthorization(_ completion: @escaping (KerdlyAttStatus) -> Void) {
129
+ let box = UncheckedSendable(completion)
130
+ if Thread.isMainThread {
131
+ MainActor.assumeIsolated {
132
+ TrackingPromptHost.prompter.request { status in box.value(status) }
133
+ }
134
+ } else {
135
+ DispatchQueue.main.async {
136
+ MainActor.assumeIsolated {
137
+ TrackingPromptHost.prompter.request { status in box.value(status) }
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ @available(iOS 13.0, *)
144
+ public static func requestTrackingAuthorization() async -> KerdlyAttStatus {
145
+ await withCheckedContinuation { continuation in
146
+ requestTrackingAuthorization { status in
147
+ continuation.resume(returning: status)
148
+ }
149
+ }
150
+ }
151
+
152
+ /// Sends queued events now (honouring a server `Retry-After`).
153
+ public static func flush() {
154
+ core.apiFlush()
155
+ }
156
+
157
+ /// Debug builds only: asks Meta (ids from the bundle's Facebook config) and TikTok
158
+ /// (`tiktokAppId`) for this device's deferred deep link, and returns each network's raw answer.
159
+ /// Sends nothing to Kerdly. Asks only when the `ads` consent is on and tracking is authorized. In
160
+ /// a release build it asks nothing and every answer is `error` ("debug builds only").
161
+ /// `completion` runs on the SDK's queue.
162
+ public static func debugFetchDeferredLinks(tiktokAppId: String?, storeAppId: String?,
163
+ completion: @escaping @Sendable ([KerdlyDeferredLinkAnswer]) -> Void) {
164
+ core.apiDebugFetchDeferredLinks(tiktokAppId: tiktokAppId, storeAppId: storeAppId) { answers in
165
+ completion(answers.map(KerdlyDeferredLinkAnswer.init))
166
+ }
167
+ }
168
+ }
169
+
170
+ /// One network's answer to a deferred-deep-link request.
171
+ public struct KerdlyDeferredLinkAnswer: Sendable, Equatable {
172
+ /// `meta` | `tiktok`.
173
+ public let network: String
174
+ /// `link` | `none` | `error` | `skipped_att` | `skipped_consent` | `not_configured`.
175
+ public let status: String
176
+ public let url: String?
177
+ public let clickTime: String?
178
+ public let httpStatus: Int?
179
+ public let detail: String?
180
+
181
+ init(_ answer: DdlAnswer) {
182
+ network = answer.network
183
+ status = answer.status.rawValue
184
+ url = answer.url
185
+ clickTime = answer.clickTime
186
+ httpStatus = answer.httpStatus
187
+ detail = answer.detail
188
+ }
189
+ }
190
+
191
+ /// The one ATT prompter, created on the main thread.
192
+ @MainActor
193
+ enum TrackingPromptHost {
194
+ static let prompter = TrackingPrompter(
195
+ tracking: KerdlyCore.shared.deps.tracking,
196
+ isActive: { UIApplication.shared.applicationState == .active },
197
+ log: KerdlyCore.shared.log,
198
+ onDecision: { _ in
199
+ let core = KerdlyCore.shared
200
+ core.queue.async { core.trackingDecided() }
201
+ })
202
+ }
@@ -0,0 +1,130 @@
1
+ import Foundation
2
+
3
+ // The public value types of the SDK. The Expo bridge maps them one to one.
4
+
5
+ /// `configure(environment:)`. `.auto` detects it on the device.
6
+ public enum KerdlyEnvironment: String, Sendable {
7
+ case auto, production, sandbox, development
8
+ }
9
+
10
+ /// `logLevel`. Every line is prefixed `[Kerdly]`.
11
+ public enum KerdlyLogLevel: Int, Sendable {
12
+ case none, error, warn, info, debug
13
+ }
14
+
15
+ /// App Tracking Transparency status, as the wire protocol spells it.
16
+ public enum KerdlyAttStatus: String, Sendable {
17
+ case authorized, denied, restricted
18
+ case notDetermined = "not_determined"
19
+ case notApplicable = "not_applicable"
20
+ }
21
+
22
+ public struct KerdlyOptions: Sendable {
23
+ /// The Kerdly collector: `https://app.kerdly.com/api`.
24
+ public static let defaultEndpoint = URL(string: "https://app.kerdly.com/api")!
25
+
26
+ /// `pk_live_…` / `pk_test_…`: the app's public SDK key.
27
+ public var key: String
28
+ /// Base URL; `/v1/sdk/batch` etc. are appended to it. Default: ``defaultEndpoint``.
29
+ public var endpoint: URL
30
+ public var environment: KerdlyEnvironment = .auto
31
+ /// IDFA, only ever read when ATT = authorized and `ads` consent is on.
32
+ public var collectAdvertisingId: Bool = true
33
+ /// Write SKAdNetwork / AdAttributionKit conversion values. Needs the remote
34
+ /// config's `skan.enabled` as well.
35
+ public var skanWriter: Bool = false
36
+ public var logLevel: KerdlyLogLevel = .warn
37
+ /// Set by wrappers such as the Expo bridge, e.g. `"expo/0.1.0"`.
38
+ public var wrapper: String? = nil
39
+
40
+ public init(key: String, endpoint: URL = KerdlyOptions.defaultEndpoint) {
41
+ self.key = key
42
+ self.endpoint = endpoint
43
+ }
44
+ }
45
+
46
+ /// What `handleUrl` parsed from a URL's query string. Each field is nil when absent.
47
+ public struct KerdlyDeepLink: Sendable, Equatable {
48
+ public let url: URL
49
+ public let cpp: String?, ppid: String?
50
+ /// The click id of the Kerdly link that opened the app (`kerdly_c`).
51
+ public let clickId: String?
52
+ /// The web visit that link continues (`kerdly_v`).
53
+ public let visitId: String?
54
+ public let campaignIds: String?
55
+
56
+ init(url: URL, cpp: String?, ppid: String?, clickId: String?, visitId: String?, campaignIds: String?) {
57
+ self.url = url
58
+ self.cpp = cpp
59
+ self.ppid = ppid
60
+ self.clickId = clickId
61
+ self.visitId = visitId
62
+ self.campaignIds = campaignIds
63
+ }
64
+ }
65
+
66
+ /// What the paywall SDK reports after a purchase (e.g. Superwall's `transactionComplete`).
67
+ public struct KerdlyPurchase: Sendable, Equatable {
68
+ public var originalTransactionId: String?
69
+ public var transactionId: String?
70
+ public var productId: String?
71
+ public var appAccountToken: UUID?
72
+
73
+ public init(originalTransactionId: String? = nil, transactionId: String? = nil,
74
+ productId: String? = nil, appAccountToken: UUID? = nil) {
75
+ self.originalTransactionId = originalTransactionId
76
+ self.transactionId = transactionId
77
+ self.productId = productId
78
+ self.appAccountToken = appAccountToken
79
+ }
80
+ }
81
+
82
+ /// A send the app just made through an ad network's SDK (`$network_send`).
83
+ public struct KerdlyNetworkSend: Sendable, Equatable {
84
+ public var network: String, event: String, eventId: String?
85
+ public var value: Double?, currency: String?, flag: String?
86
+
87
+ public init(network: String, event: String, eventId: String? = nil,
88
+ value: Double? = nil, currency: String? = nil, flag: String? = nil) {
89
+ self.network = network
90
+ self.event = event
91
+ self.eventId = eventId
92
+ self.value = value
93
+ self.currency = currency
94
+ self.flag = flag
95
+ }
96
+ }
97
+
98
+ /// The install's attribution.
99
+ public struct KerdlyAttribution {
100
+ public let state: String, network: String, status: String, method: String
101
+ public let campaignId: String?, campaign: String?, adsetId: String?, adset: String?
102
+ public let adId: String?, ad: String?, keywordId: String?, keyword: String?
103
+ public let linkId: String?, cppId: String?, decidedAt: Date?
104
+ /// The whole JSON object as the server sent it (JSON null is `NSNull`).
105
+ public let raw: [String: Any]
106
+
107
+ init(json: [String: JSONValue]) {
108
+ func string(_ key: String) -> String? { json[key]?.lenientStringValue }
109
+ state = string("state") ?? "unknown"
110
+ network = string("network") ?? "unknown"
111
+ status = string("status") ?? "unknown"
112
+ method = string("method") ?? "none"
113
+ campaignId = string("campaign_id")
114
+ campaign = string("campaign")
115
+ adsetId = string("adset_id")
116
+ adset = string("adset")
117
+ adId = string("ad_id")
118
+ ad = string("ad")
119
+ keywordId = string("keyword_id")
120
+ keyword = string("keyword")
121
+ linkId = string("link_id")
122
+ cppId = string("cpp_id")
123
+ if let ms = json["decided_at"]?.doubleValue {
124
+ decidedAt = Date(timeIntervalSince1970: ms / 1000)
125
+ } else {
126
+ decidedAt = nil
127
+ }
128
+ raw = JSONValue.object(json).anyValue as? [String: Any] ?? [:]
129
+ }
130
+ }
@@ -0,0 +1,95 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <!-- The SDK itself does not track. The IDFA is read only after the user authorized ATT. -->
6
+ <key>NSPrivacyTracking</key>
7
+ <true/>
8
+ <key>NSPrivacyTrackingDomains</key>
9
+ <array>
10
+ <string>ep1.facebook.com</string>
11
+ </array>
12
+ <key>NSPrivacyCollectedDataTypes</key>
13
+ <array>
14
+ <!-- The SDK's install id (Keychain + UserDefaults) and the IDFV. -->
15
+ <dict>
16
+ <key>NSPrivacyCollectedDataType</key>
17
+ <string>NSPrivacyCollectedDataTypeDeviceID</string>
18
+ <key>NSPrivacyCollectedDataTypeLinked</key>
19
+ <true/>
20
+ <key>NSPrivacyCollectedDataTypeTracking</key>
21
+ <false/>
22
+ <key>NSPrivacyCollectedDataTypePurposes</key>
23
+ <array>
24
+ <string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
25
+ <string>NSPrivacyCollectedDataTypePurposeDeveloperAdvertising</string>
26
+ </array>
27
+ </dict>
28
+ <!-- App opens, deep links and the app's custom events. -->
29
+ <dict>
30
+ <key>NSPrivacyCollectedDataType</key>
31
+ <string>NSPrivacyCollectedDataTypeProductInteraction</string>
32
+ <key>NSPrivacyCollectedDataTypeLinked</key>
33
+ <true/>
34
+ <key>NSPrivacyCollectedDataTypeTracking</key>
35
+ <false/>
36
+ <key>NSPrivacyCollectedDataTypePurposes</key>
37
+ <array>
38
+ <string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
39
+ </array>
40
+ </dict>
41
+ <!-- StoreKit transaction ids and the AppTransaction ($purchase_link, app_transaction). -->
42
+ <dict>
43
+ <key>NSPrivacyCollectedDataType</key>
44
+ <string>NSPrivacyCollectedDataTypePurchaseHistory</string>
45
+ <key>NSPrivacyCollectedDataTypeLinked</key>
46
+ <true/>
47
+ <key>NSPrivacyCollectedDataTypeTracking</key>
48
+ <false/>
49
+ <key>NSPrivacyCollectedDataTypePurposes</key>
50
+ <array>
51
+ <string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
52
+ <string>NSPrivacyCollectedDataTypePurposeDeveloperAdvertising</string>
53
+ </array>
54
+ </dict>
55
+ <!-- The Apple Ads (AdServices) token, ad click/visit ids from deep links, and the IDFA
56
+ (only when ATT is authorized), used to attribute installs to ads and report conversions
57
+ to the ad networks. -->
58
+ <dict>
59
+ <key>NSPrivacyCollectedDataType</key>
60
+ <string>NSPrivacyCollectedDataTypeAdvertisingData</string>
61
+ <key>NSPrivacyCollectedDataTypeLinked</key>
62
+ <true/>
63
+ <key>NSPrivacyCollectedDataTypeTracking</key>
64
+ <true/>
65
+ <key>NSPrivacyCollectedDataTypePurposes</key>
66
+ <array>
67
+ <string>NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising</string>
68
+ <string>NSPrivacyCollectedDataTypePurposeDeveloperAdvertising</string>
69
+ <string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
70
+ </array>
71
+ </dict>
72
+ </array>
73
+ <key>NSPrivacyAccessedAPITypes</key>
74
+ <array>
75
+ <!-- The UserDefaults copy of the install id (read and written by this app only). -->
76
+ <dict>
77
+ <key>NSPrivacyAccessedAPIType</key>
78
+ <string>NSPrivacyAccessedAPICategoryUserDefaults</string>
79
+ <key>NSPrivacyAccessedAPITypeReasons</key>
80
+ <array>
81
+ <string>CA92.1</string>
82
+ </array>
83
+ </dict>
84
+ <!-- The Documents directory's creation date, inside the app container (the install moment). -->
85
+ <dict>
86
+ <key>NSPrivacyAccessedAPIType</key>
87
+ <string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
88
+ <key>NSPrivacyAccessedAPITypeReasons</key>
89
+ <array>
90
+ <string>C617.1</string>
91
+ </array>
92
+ </dict>
93
+ </array>
94
+ </dict>
95
+ </plist>