@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.
- package/LICENSE +21 -0
- package/README.md +235 -2
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +19 -0
- package/android/src/main/java/com/kerdly/expo/KerdlySdkModule.kt +326 -0
- package/android/vendor/kerdly-sdk/.kerdly-sync.json +8 -0
- package/android/vendor/kerdly-sdk/consumer-rules.pro +15 -0
- package/android/vendor/kerdly-sdk/kerdly-sdk.properties +2 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/Kerdly.kt +343 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/KerdlyTypes.kt +89 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Attribution.kt +39 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Batch.kt +159 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Core.kt +991 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeepLinks.kt +114 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeferredLinks.kt +111 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/DeviceContext.kt +137 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/EventQueue.kt +135 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Events.kt +314 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Json.kt +116 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Logger.kt +49 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Options.kt +47 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Ports.kt +83 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/PublicIp.kt +120 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Referrers.kt +137 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/RemoteConfig.kt +100 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/Storage.kt +271 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidPlatform.kt +274 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/AndroidRuntime.kt +187 -0
- package/android/vendor/kerdly-sdk/kotlin/com/kerdly/sdk/internal/android/PlayReferrerReader.kt +97 -0
- package/app.plugin.js +2 -0
- package/build/Kerdly.d.ts +106 -0
- package/build/Kerdly.d.ts.map +1 -0
- package/build/Kerdly.js +494 -0
- package/build/Kerdly.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -0
- package/build/log.d.ts +13 -0
- package/build/log.d.ts.map +1 -0
- package/build/log.js +45 -0
- package/build/log.js.map +1 -0
- package/build/native.d.ts +74 -0
- package/build/native.d.ts.map +1 -0
- package/build/native.js +56 -0
- package/build/native.js.map +1 -0
- package/build/normalize.d.ts +8 -0
- package/build/normalize.d.ts.map +1 -0
- package/build/normalize.js +86 -0
- package/build/normalize.js.map +1 -0
- package/build/types.d.ts +134 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/validation.d.ts +70 -0
- package/build/validation.d.ts.map +1 -0
- package/build/validation.js +349 -0
- package/build/validation.js.map +1 -0
- package/build/version.d.ts +4 -0
- package/build/version.d.ts.map +1 -0
- package/build/version.js +5 -0
- package/build/version.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/KerdlySDK/.kerdly-sync.json +7 -0
- package/ios/KerdlySDK/Core/Dependencies.swift +163 -0
- package/ios/KerdlySDK/Core/KerdlyCore+API.swift +117 -0
- package/ios/KerdlySDK/Core/KerdlyCore+Collectors.swift +410 -0
- package/ios/KerdlySDK/Core/KerdlyCore+DeferredLinks.swift +220 -0
- package/ios/KerdlySDK/Core/KerdlyCore+Delivery.swift +424 -0
- package/ios/KerdlySDK/Core/KerdlyCore.swift +557 -0
- package/ios/KerdlySDK/Core/Support.swift +95 -0
- package/ios/KerdlySDK/Logic/Backoff.swift +22 -0
- package/ios/KerdlySDK/Logic/Batch.swift +180 -0
- package/ios/KerdlySDK/Logic/Context.swift +85 -0
- package/ios/KerdlySDK/Logic/DeepLinks.swift +93 -0
- package/ios/KerdlySDK/Logic/DeferredLinks.swift +239 -0
- package/ios/KerdlySDK/Logic/Environment.swift +39 -0
- package/ios/KerdlySDK/Logic/EventQueue.swift +85 -0
- package/ios/KerdlySDK/Logic/EventValidator.swift +84 -0
- package/ios/KerdlySDK/Logic/Events.swift +102 -0
- package/ios/KerdlySDK/Logic/IPv6Address.swift +26 -0
- package/ios/KerdlySDK/Logic/InstallIdentity.swift +106 -0
- package/ios/KerdlySDK/Logic/JSONValue.swift +198 -0
- package/ios/KerdlySDK/Logic/Purchases.swift +84 -0
- package/ios/KerdlySDK/Logic/RemoteConfig.swift +185 -0
- package/ios/KerdlySDK/Logic/Skan.swift +343 -0
- package/ios/KerdlySDK/Logic/StandardEvents.swift +126 -0
- package/ios/KerdlySDK/Platform/AdSignals.swift +19 -0
- package/ios/KerdlySDK/Platform/DeferredLinkBundle.swift +25 -0
- package/ios/KerdlySDK/Platform/DeviceInfo.swift +82 -0
- package/ios/KerdlySDK/Platform/Lifecycle.swift +74 -0
- package/ios/KerdlySDK/Platform/PublicIp.swift +33 -0
- package/ios/KerdlySDK/Platform/SkanWriter.swift +70 -0
- package/ios/KerdlySDK/Platform/StoreKitAdapter.swift +185 -0
- package/ios/KerdlySDK/Platform/SystemStores.swift +200 -0
- package/ios/KerdlySDK/Platform/Tracking.swift +124 -0
- package/ios/KerdlySDK/Public/Kerdly.swift +202 -0
- package/ios/KerdlySDK/Public/KerdlyTypes.swift +130 -0
- package/ios/KerdlySDK/Resources/PrivacyInfo.xcprivacy +95 -0
- package/ios/KerdlySDK/Storage/PersistedState.swift +175 -0
- package/ios/KerdlySDK/Storage/StateStore.swift +36 -0
- package/ios/KerdlySdk.podspec +45 -0
- package/ios/KerdlySdkModule.swift +332 -0
- package/package.json +92 -4
- package/plugin/withKerdly.js +163 -0
- package/src/Kerdly.ts +524 -0
- package/src/index.ts +23 -0
- package/src/log.ts +49 -0
- package/src/native.ts +150 -0
- package/src/normalize.ts +82 -0
- package/src/types.ts +183 -0
- package/src/validation.ts +343 -0
- package/src/version.ts +5 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Everything the SDK remembers between launches (`Application Support/kerdly/state.json`).
|
|
4
|
+
///
|
|
5
|
+
/// The file is included in device backups, so a backup restored onto another phone brings it back
|
|
6
|
+
/// along with the UserDefaults copy of the id, and the restore mints a new install id. Fields are
|
|
7
|
+
/// therefore split: install-scoped ones reset whenever the install id changes (and at every
|
|
8
|
+
/// `$install`); user-scoped ones (the app's user id, consent and ids) carry over.
|
|
9
|
+
struct PersistedState: Codable, Equatable, Sendable {
|
|
10
|
+
var installId: String
|
|
11
|
+
|
|
12
|
+
// MARK: Install-scoped
|
|
13
|
+
|
|
14
|
+
/// The last `seq` used; the next event gets `seq + 1`.
|
|
15
|
+
var seq: Int64 = 0
|
|
16
|
+
/// ms; the launch that enqueued this install's `$install`.
|
|
17
|
+
var firstLaunchAt: Int64?
|
|
18
|
+
/// ms; the Documents directory's creation date.
|
|
19
|
+
var installedAt: Int64?
|
|
20
|
+
var lastAckedContextHash: String?
|
|
21
|
+
/// Original transaction ids (and notify-only transaction ids) already sent as `$purchase_link`.
|
|
22
|
+
var reportedPurchaseIds: [String] = []
|
|
23
|
+
/// AdServices token signals enqueued for this install (at most 3).
|
|
24
|
+
var asaAttempts = 0
|
|
25
|
+
/// A token signal is wanted: from the `$install` launch until one is sent (within 48 h of the
|
|
26
|
+
/// first launch), or a response's `needs`.
|
|
27
|
+
var asaDue = false
|
|
28
|
+
/// Failed token requests in the current round (a launch or a foreground); the round gives up
|
|
29
|
+
/// after 3, and the next launch or foreground starts another.
|
|
30
|
+
var asaFailures = 0
|
|
31
|
+
var appTransactionSent = false
|
|
32
|
+
/// Highest SKAN fine value Apple accepted.
|
|
33
|
+
var skanFloor: Int?
|
|
34
|
+
/// Attribution-bearing `$deeplink` events not yet accepted by the server.
|
|
35
|
+
var pendingDeepLinks: [QueuedEvent] = []
|
|
36
|
+
var attribution: JSONValue?
|
|
37
|
+
var lastAttStatus: String?
|
|
38
|
+
/// SHA-256 of the last IDFA sent, so it is signalled only when it changes.
|
|
39
|
+
var idfaHash: String?
|
|
40
|
+
var backoffAttempt = 0
|
|
41
|
+
/// ms; no automatic flush before this.
|
|
42
|
+
var retryAt: Int64?
|
|
43
|
+
/// `retryAt` came from the server's `Retry-After` (an explicit `flush()` honours it too).
|
|
44
|
+
var retryAtFromServer = false
|
|
45
|
+
/// Deferred deep links: asked only for an install whose `$install` was fresh or a
|
|
46
|
+
/// reinstall, never a restore.
|
|
47
|
+
var ddlEligible = false
|
|
48
|
+
/// Per network (`meta`, `tiktok`): the answer is in, or how many tries failed in transit.
|
|
49
|
+
var ddl: [String: DdlNetworkState] = [:]
|
|
50
|
+
|
|
51
|
+
// MARK: User-scoped
|
|
52
|
+
|
|
53
|
+
var userId: String?
|
|
54
|
+
var consentAnalytics = true
|
|
55
|
+
var consentAds = true
|
|
56
|
+
/// Lowercase UUID string.
|
|
57
|
+
var appAccountToken: String?
|
|
58
|
+
var partnerIds: [String: String] = [:]
|
|
59
|
+
|
|
60
|
+
init(installId: String) {
|
|
61
|
+
self.installId = installId
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Keeps the user-scoped fields, resets the rest for `installId`.
|
|
65
|
+
func reset(for installId: String) -> PersistedState {
|
|
66
|
+
var next = PersistedState(installId: installId)
|
|
67
|
+
next.userId = userId
|
|
68
|
+
next.consentAnalytics = consentAnalytics
|
|
69
|
+
next.consentAds = consentAds
|
|
70
|
+
next.appAccountToken = appAccountToken
|
|
71
|
+
next.partnerIds = partnerIds
|
|
72
|
+
return next
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static let maxReportedPurchaseIds = 500
|
|
76
|
+
static let maxPendingDeepLinks = 20
|
|
77
|
+
|
|
78
|
+
mutating func markReported(_ keys: [String]) {
|
|
79
|
+
for key in keys where !reportedPurchaseIds.contains(key) {
|
|
80
|
+
reportedPurchaseIds.append(key)
|
|
81
|
+
}
|
|
82
|
+
if reportedPurchaseIds.count > Self.maxReportedPurchaseIds {
|
|
83
|
+
reportedPurchaseIds.removeFirst(reportedPurchaseIds.count - Self.maxReportedPurchaseIds)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
enum CodingKeys: String, CodingKey {
|
|
88
|
+
case installId = "install_id"
|
|
89
|
+
case seq
|
|
90
|
+
case firstLaunchAt = "first_launch_at"
|
|
91
|
+
case installedAt = "installed_at"
|
|
92
|
+
case lastAckedContextHash = "last_acked_context_hash"
|
|
93
|
+
case reportedPurchaseIds = "reported_purchase_ids"
|
|
94
|
+
case asaAttempts = "asa_attempts"
|
|
95
|
+
case asaDue = "asa_due"
|
|
96
|
+
case asaFailures = "asa_failures"
|
|
97
|
+
case appTransactionSent = "app_transaction_sent"
|
|
98
|
+
case skanFloor = "skan_floor"
|
|
99
|
+
case pendingDeepLinks = "pending_deep_links"
|
|
100
|
+
case attribution
|
|
101
|
+
case lastAttStatus = "last_att_status"
|
|
102
|
+
case idfaHash = "idfa_hash"
|
|
103
|
+
case backoffAttempt = "backoff_attempt"
|
|
104
|
+
case retryAt = "retry_at"
|
|
105
|
+
case retryAtFromServer = "retry_at_from_server"
|
|
106
|
+
case ddlEligible = "ddl_eligible"
|
|
107
|
+
case ddl
|
|
108
|
+
case userId = "user_id"
|
|
109
|
+
case consentAnalytics = "consent_analytics"
|
|
110
|
+
case consentAds = "consent_ads"
|
|
111
|
+
case appAccountToken = "app_account_token"
|
|
112
|
+
case partnerIds = "partner_ids"
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// Lenient: a missing or unreadable field takes its default, so a newer or older file still loads.
|
|
116
|
+
init(from decoder: Decoder) throws {
|
|
117
|
+
let c = try decoder.container(keyedBy: CodingKeys.self)
|
|
118
|
+
installId = try c.decode(String.self, forKey: .installId)
|
|
119
|
+
func get<T: Decodable>(_ key: CodingKeys, _ fallback: T) -> T {
|
|
120
|
+
((try? c.decodeIfPresent(T.self, forKey: key)) ?? nil) ?? fallback
|
|
121
|
+
}
|
|
122
|
+
seq = get(.seq, 0)
|
|
123
|
+
firstLaunchAt = get(.firstLaunchAt, nil)
|
|
124
|
+
installedAt = get(.installedAt, nil)
|
|
125
|
+
lastAckedContextHash = get(.lastAckedContextHash, nil)
|
|
126
|
+
reportedPurchaseIds = get(.reportedPurchaseIds, [])
|
|
127
|
+
asaAttempts = get(.asaAttempts, 0)
|
|
128
|
+
asaDue = get(.asaDue, false)
|
|
129
|
+
asaFailures = get(.asaFailures, 0)
|
|
130
|
+
appTransactionSent = get(.appTransactionSent, false)
|
|
131
|
+
skanFloor = get(.skanFloor, nil)
|
|
132
|
+
pendingDeepLinks = get(.pendingDeepLinks, [])
|
|
133
|
+
attribution = get(.attribution, nil)
|
|
134
|
+
lastAttStatus = get(.lastAttStatus, nil)
|
|
135
|
+
idfaHash = get(.idfaHash, nil)
|
|
136
|
+
backoffAttempt = get(.backoffAttempt, 0)
|
|
137
|
+
retryAt = get(.retryAt, nil)
|
|
138
|
+
retryAtFromServer = get(.retryAtFromServer, false)
|
|
139
|
+
ddlEligible = get(.ddlEligible, false)
|
|
140
|
+
ddl = get(.ddl, [:])
|
|
141
|
+
userId = get(.userId, nil)
|
|
142
|
+
consentAnalytics = get(.consentAnalytics, true)
|
|
143
|
+
consentAds = get(.consentAds, true)
|
|
144
|
+
appAccountToken = get(.appAccountToken, nil)
|
|
145
|
+
partnerIds = get(.partnerIds, [:])
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// One network's deferred-link progress for this install.
|
|
150
|
+
struct DdlNetworkState: Codable, Equatable, Sendable {
|
|
151
|
+
/// The network answered (a link, none, a refusal) or the SDK gave up: never asked again.
|
|
152
|
+
var done = false
|
|
153
|
+
/// Tries that failed in transit (no answer, 429, 5xx); the SDK gives up after 3.
|
|
154
|
+
var failures = 0
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// The queue file (`Application Support/kerdly/queue.json`), tagged with the install id it belongs to.
|
|
158
|
+
struct QueueFile: Codable, Equatable, Sendable {
|
|
159
|
+
var version = 1
|
|
160
|
+
var installId: String
|
|
161
|
+
var events: [QueuedEvent]
|
|
162
|
+
|
|
163
|
+
enum CodingKeys: String, CodingKey {
|
|
164
|
+
case version = "v"
|
|
165
|
+
case installId = "install_id"
|
|
166
|
+
case events
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/// Where the SDK's files live, and how they are read and written.
|
|
171
|
+
enum StateFiles {
|
|
172
|
+
static let state = "state.json"
|
|
173
|
+
static let queue = "queue.json"
|
|
174
|
+
static let config = "config.json"
|
|
175
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Reads and writes the SDK's three JSON files through `FileStoring` (atomic writes).
|
|
4
|
+
struct StateStore: Sendable {
|
|
5
|
+
let files: FileStoring
|
|
6
|
+
|
|
7
|
+
func loadState() -> PersistedState? {
|
|
8
|
+
files.read(StateFiles.state).flatMap { KerdlyJSON.decode(PersistedState.self, from: $0) }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@discardableResult
|
|
12
|
+
func save(_ state: PersistedState) -> Bool {
|
|
13
|
+
guard let data = KerdlyJSON.encode(state) else { return false }
|
|
14
|
+
return files.write(data, to: StateFiles.state)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
func loadQueue() -> QueueFile? {
|
|
18
|
+
files.read(StateFiles.queue).flatMap { KerdlyJSON.decode(QueueFile.self, from: $0) }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@discardableResult
|
|
22
|
+
func save(queue: [QueuedEvent], installId: String) -> Bool {
|
|
23
|
+
guard let data = KerdlyJSON.encode(QueueFile(installId: installId, events: queue)) else { return false }
|
|
24
|
+
return files.write(data, to: StateFiles.queue)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func loadConfig() -> ConfigCache? {
|
|
28
|
+
files.read(StateFiles.config).flatMap { KerdlyJSON.decode(ConfigCache.self, from: $0) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@discardableResult
|
|
32
|
+
func save(config: ConfigCache) -> Bool {
|
|
33
|
+
guard let data = KerdlyJSON.encode(config) else { return false }
|
|
34
|
+
return files.write(data, to: StateFiles.config)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
# The native KerdlySDK sources are vendored here by scripts/sync-native.mjs (npm `prepare`/`prepack`)
|
|
6
|
+
# from ../ios/Sources/KerdlySDK. CocoaPods cannot compile files outside the pod directory, so a
|
|
7
|
+
# missing copy is a broken install: fail now with the fix instead of with "cannot find 'Kerdly'".
|
|
8
|
+
vendored_sdk = File.join(__dir__, 'KerdlySDK')
|
|
9
|
+
if Dir.glob(File.join(vendored_sdk, '**', '*.swift')).empty?
|
|
10
|
+
raise "[@kerdly/expo] #{vendored_sdk} is missing. Run `npm run sync-native` in the @kerdly/expo " \
|
|
11
|
+
'package (it copies ../ios/Sources/KerdlySDK), or install a packed/published build of the package.'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Pod::Spec.new do |s|
|
|
15
|
+
s.name = 'KerdlySdk'
|
|
16
|
+
s.version = package['version']
|
|
17
|
+
s.summary = 'Expo bridge for the Kerdly attribution SDK (vendored KerdlySDK)'
|
|
18
|
+
s.description = package['description']
|
|
19
|
+
s.license = package['license']
|
|
20
|
+
s.author = package['author']
|
|
21
|
+
s.homepage = package['homepage']
|
|
22
|
+
s.platforms = { :ios => '15.1' }
|
|
23
|
+
s.swift_version = '5.9'
|
|
24
|
+
s.source = { git: 'https://github.com/Kerdly/kerdly-sdk.git', tag: package['version'] }
|
|
25
|
+
s.static_framework = true
|
|
26
|
+
|
|
27
|
+
s.dependency 'ExpoModulesCore'
|
|
28
|
+
|
|
29
|
+
# The bridge and the vendored SDK compile into this one module, so KerdlySdkModule.swift calls `Kerdly`
|
|
30
|
+
# without `import KerdlySDK`.
|
|
31
|
+
s.source_files = '*.swift', 'KerdlySDK/**/*.swift'
|
|
32
|
+
|
|
33
|
+
# The SDK's privacy manifest (required-reason APIs, tracking domains), as a resource bundle so
|
|
34
|
+
# Xcode aggregates it into the app's privacy report.
|
|
35
|
+
s.resource_bundles = { 'KerdlySDKPrivacy' => ['KerdlySDK/**/PrivacyInfo.xcprivacy'] }
|
|
36
|
+
|
|
37
|
+
# The SDK imports AdAttributionKit (iOS 17.4+) behind availability checks; weak-link it so the app
|
|
38
|
+
# still launches on older iOS versions.
|
|
39
|
+
s.weak_frameworks = 'AdAttributionKit'
|
|
40
|
+
|
|
41
|
+
s.pod_target_xcconfig = {
|
|
42
|
+
'DEFINES_MODULE' => 'YES',
|
|
43
|
+
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
|
44
|
+
}
|
|
45
|
+
end
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
// The Expo bridge over the native KerdlySDK.
|
|
5
|
+
//
|
|
6
|
+
// The KerdlySDK sources are vendored into this pod by scripts/sync-native.mjs (ios/KerdlySDK/), so `Kerdly`,
|
|
7
|
+
// `KerdlyOptions`, … are declared in this module and need no `import KerdlySDK`. Because module-local
|
|
8
|
+
// declarations shadow imported ones, every ExpoModulesCore name below is module-qualified: a type
|
|
9
|
+
// the SDK adds later (say, an `Events` enum) can never capture the DSL.
|
|
10
|
+
//
|
|
11
|
+
// Every function is an AsyncFunction on the main queue: native calls run in the order JS made them
|
|
12
|
+
// (configure first), on the thread the SDK expects for `configure`.
|
|
13
|
+
|
|
14
|
+
public final class KerdlySdkModule: ExpoModulesCore.Module {
|
|
15
|
+
static let attributionEvent = "onAttribution"
|
|
16
|
+
|
|
17
|
+
public func definition() -> ExpoModulesCore.ModuleDefinition {
|
|
18
|
+
ExpoModulesCore.Name("KerdlySdk")
|
|
19
|
+
|
|
20
|
+
ExpoModulesCore.Events(KerdlySdkModule.attributionEvent)
|
|
21
|
+
|
|
22
|
+
ExpoModulesCore.OnCreate {
|
|
23
|
+
KerdlyExpoAttributionRelay.shared.attach(self)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
ExpoModulesCore.OnDestroy {
|
|
27
|
+
KerdlyExpoAttributionRelay.shared.detach(self)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ExpoModulesCore.AsyncFunction("configure") { (options: KerdlyExpoConfigureOptions) in
|
|
31
|
+
guard !options.key.isEmpty, let endpoint = URL(string: options.endpoint) else {
|
|
32
|
+
NSLog("[Kerdly] configure: missing key or invalid endpoint; the SDK was not configured")
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
var kerdlyOptions = KerdlyOptions(key: options.key, endpoint: endpoint)
|
|
36
|
+
kerdlyOptions.environment = KerdlyEnvironment(rawValue: options.environment) ?? .auto
|
|
37
|
+
kerdlyOptions.collectAdvertisingId = options.collectAdvertisingId
|
|
38
|
+
kerdlyOptions.skanWriter = options.skanWriter
|
|
39
|
+
kerdlyOptions.logLevel = KerdlySdkModule.logLevel(options.logLevel)
|
|
40
|
+
kerdlyOptions.wrapper = options.wrapper
|
|
41
|
+
Kerdly.configure(kerdlyOptions)
|
|
42
|
+
}
|
|
43
|
+
.runOnQueue(.main)
|
|
44
|
+
|
|
45
|
+
ExpoModulesCore.AsyncFunction("setUserId") { (userId: String?) in
|
|
46
|
+
Kerdly.setUserId(userId)
|
|
47
|
+
}
|
|
48
|
+
.runOnQueue(.main)
|
|
49
|
+
|
|
50
|
+
ExpoModulesCore.AsyncFunction("track") { (name: String, properties: [String: Any]) in
|
|
51
|
+
Kerdly.track(name, properties: properties)
|
|
52
|
+
}
|
|
53
|
+
.runOnQueue(.main)
|
|
54
|
+
|
|
55
|
+
// Standard events. JS passes every typed field, null when omitted, in the order
|
|
56
|
+
// of the native signature; the SDK validates them again.
|
|
57
|
+
ExpoModulesCore.AsyncFunction("trackRegistration") { (method: String?, properties: [String: Any]) in
|
|
58
|
+
Kerdly.trackRegistration(method: method, properties: properties)
|
|
59
|
+
}
|
|
60
|
+
.runOnQueue(.main)
|
|
61
|
+
|
|
62
|
+
ExpoModulesCore.AsyncFunction("trackStartTrial") {
|
|
63
|
+
(productId: String?, value: Double?, currency: String?, transactionId: String?, properties: [String: Any]) in
|
|
64
|
+
Kerdly.trackStartTrial(
|
|
65
|
+
productId: productId,
|
|
66
|
+
value: value,
|
|
67
|
+
currency: currency,
|
|
68
|
+
transactionId: transactionId,
|
|
69
|
+
properties: properties
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
.runOnQueue(.main)
|
|
73
|
+
|
|
74
|
+
ExpoModulesCore.AsyncFunction("trackSubscribe") {
|
|
75
|
+
(productId: String?, value: Double?, currency: String?, transactionId: String?, properties: [String: Any]) in
|
|
76
|
+
Kerdly.trackSubscribe(
|
|
77
|
+
productId: productId,
|
|
78
|
+
value: value,
|
|
79
|
+
currency: currency,
|
|
80
|
+
transactionId: transactionId,
|
|
81
|
+
properties: properties
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
.runOnQueue(.main)
|
|
85
|
+
|
|
86
|
+
ExpoModulesCore.AsyncFunction("trackPurchase") {
|
|
87
|
+
(productId: String?, value: Double?, currency: String?, quantity: Int?, transactionId: String?,
|
|
88
|
+
properties: [String: Any]) in
|
|
89
|
+
Kerdly.trackPurchase(
|
|
90
|
+
productId: productId,
|
|
91
|
+
value: value,
|
|
92
|
+
currency: currency,
|
|
93
|
+
quantity: quantity,
|
|
94
|
+
transactionId: transactionId,
|
|
95
|
+
properties: properties
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
.runOnQueue(.main)
|
|
99
|
+
|
|
100
|
+
ExpoModulesCore.AsyncFunction("setConsent") { (analytics: Bool?, ads: Bool?) in
|
|
101
|
+
Kerdly.setConsent(analytics: analytics, ads: ads)
|
|
102
|
+
}
|
|
103
|
+
.runOnQueue(.main)
|
|
104
|
+
|
|
105
|
+
// The second argument is the source the JS layer knows ("initial" for Linking's initial URL,
|
|
106
|
+
// "runtime" for its `url` events, or null); the SDK infers it only when it is null.
|
|
107
|
+
ExpoModulesCore.AsyncFunction("handleUrl") { (urlString: String, source: String?) -> [String: Any]? in
|
|
108
|
+
guard let url = URL(string: urlString) else {
|
|
109
|
+
NSLog("[Kerdly] handleUrl: not a valid URL")
|
|
110
|
+
return nil
|
|
111
|
+
}
|
|
112
|
+
return Kerdly.handleUrl(url, source: source).map(KerdlySdkModule.dictionary(from:))
|
|
113
|
+
}
|
|
114
|
+
.runOnQueue(.main)
|
|
115
|
+
|
|
116
|
+
ExpoModulesCore.AsyncFunction("setAppAccountToken") { (token: String?) in
|
|
117
|
+
guard let token else {
|
|
118
|
+
Kerdly.setAppAccountToken(nil)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
// An unparsable token is ignored rather than clearing the stored one.
|
|
122
|
+
guard let uuid = UUID(uuidString: token) else {
|
|
123
|
+
NSLog("[Kerdly] setAppAccountToken: not a UUID; ignored")
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
Kerdly.setAppAccountToken(uuid)
|
|
127
|
+
}
|
|
128
|
+
.runOnQueue(.main)
|
|
129
|
+
|
|
130
|
+
ExpoModulesCore.AsyncFunction("setPartnerIds") { (ids: [String: String]) in
|
|
131
|
+
Kerdly.setPartnerIds(ids)
|
|
132
|
+
}
|
|
133
|
+
.runOnQueue(.main)
|
|
134
|
+
|
|
135
|
+
// Accepts either platform's shape; only the iOS fields are read. No purchase, or one without
|
|
136
|
+
// any iOS field (e.g. the Android shape), sweeps Transaction.currentEntitlements instead.
|
|
137
|
+
ExpoModulesCore.AsyncFunction("notifyPurchase") { (purchase: KerdlyExpoPurchase?) in
|
|
138
|
+
guard let purchase else {
|
|
139
|
+
Kerdly.notifyPurchase(nil)
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
let token = purchase.appAccountToken.flatMap { UUID(uuidString: $0) }
|
|
143
|
+
if purchase.originalTransactionId == nil, purchase.transactionId == nil, purchase.productId == nil, token == nil {
|
|
144
|
+
Kerdly.notifyPurchase(nil)
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
Kerdly.notifyPurchase(KerdlyPurchase(
|
|
148
|
+
originalTransactionId: purchase.originalTransactionId,
|
|
149
|
+
transactionId: purchase.transactionId,
|
|
150
|
+
productId: purchase.productId,
|
|
151
|
+
appAccountToken: token
|
|
152
|
+
))
|
|
153
|
+
}
|
|
154
|
+
.runOnQueue(.main)
|
|
155
|
+
|
|
156
|
+
ExpoModulesCore.AsyncFunction("recordNetworkSend") { (send: KerdlyExpoNetworkSend) in
|
|
157
|
+
guard !send.network.isEmpty, !send.event.isEmpty else {
|
|
158
|
+
NSLog("[Kerdly] recordNetworkSend: network and event are required; ignored")
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
Kerdly.recordNetworkSend(KerdlyNetworkSend(
|
|
162
|
+
network: send.network,
|
|
163
|
+
event: send.event,
|
|
164
|
+
eventId: send.eventId,
|
|
165
|
+
value: send.value,
|
|
166
|
+
currency: send.currency,
|
|
167
|
+
flag: send.flag
|
|
168
|
+
))
|
|
169
|
+
}
|
|
170
|
+
.runOnQueue(.main)
|
|
171
|
+
|
|
172
|
+
ExpoModulesCore.AsyncFunction("getAttribution") { () -> [String: Any]? in
|
|
173
|
+
Kerdly.attribution.map(KerdlySdkModule.dictionary(from:))
|
|
174
|
+
}
|
|
175
|
+
.runOnQueue(.main)
|
|
176
|
+
|
|
177
|
+
// The SDK waits for the app to be active and, without NSUserTrackingUsageDescription (the config
|
|
178
|
+
// plugin's userTrackingPermission), logs an error and reports the current status instead of prompting.
|
|
179
|
+
ExpoModulesCore.AsyncFunction("requestTrackingAuthorization") { (promise: ExpoModulesCore.Promise) in
|
|
180
|
+
Kerdly.requestTrackingAuthorization { status in
|
|
181
|
+
promise.resolve(status.rawValue)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
.runOnQueue(.main)
|
|
185
|
+
|
|
186
|
+
ExpoModulesCore.AsyncFunction("flush") {
|
|
187
|
+
Kerdly.flush()
|
|
188
|
+
}
|
|
189
|
+
.runOnQueue(.main)
|
|
190
|
+
|
|
191
|
+
ExpoModulesCore.AsyncFunction("getInstallId") { () -> String? in
|
|
192
|
+
Kerdly.installId
|
|
193
|
+
}
|
|
194
|
+
.runOnQueue(.main)
|
|
195
|
+
|
|
196
|
+
// Debug builds only: each network's raw answer to a deferred-deep-link request; sends nothing to
|
|
197
|
+
// Kerdly. A release build answers `error` for each network and asks nothing.
|
|
198
|
+
ExpoModulesCore.AsyncFunction("debugFetchDeferredLinks") {
|
|
199
|
+
(tiktokAppId: String?, storeAppId: String?, promise: ExpoModulesCore.Promise) in
|
|
200
|
+
Kerdly.debugFetchDeferredLinks(tiktokAppId: tiktokAppId, storeAppId: storeAppId) { answers in
|
|
201
|
+
promise.resolve(answers.map { answer -> [String: Any] in
|
|
202
|
+
var out: [String: Any] = ["network": answer.network, "status": answer.status]
|
|
203
|
+
if let url = answer.url { out["url"] = url }
|
|
204
|
+
if let clickTime = answer.clickTime { out["clickTime"] = clickTime }
|
|
205
|
+
if let httpStatus = answer.httpStatus { out["httpStatus"] = httpStatus }
|
|
206
|
+
if let detail = answer.detail { out["detail"] = detail }
|
|
207
|
+
return out
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
.runOnQueue(.main)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// MARK: - Mapping
|
|
215
|
+
|
|
216
|
+
static func logLevel(_ name: String) -> KerdlyLogLevel {
|
|
217
|
+
switch name {
|
|
218
|
+
case "none": return KerdlyLogLevel.none
|
|
219
|
+
case "error": return KerdlyLogLevel.error
|
|
220
|
+
case "info": return KerdlyLogLevel.info
|
|
221
|
+
case "debug": return KerdlyLogLevel.debug
|
|
222
|
+
default: return KerdlyLogLevel.warn
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private static func orNull(_ value: String?) -> Any {
|
|
227
|
+
if let value { return value }
|
|
228
|
+
return NSNull()
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static func dictionary(from link: KerdlyDeepLink) -> [String: Any] {
|
|
232
|
+
return [
|
|
233
|
+
"url": link.url.absoluteString,
|
|
234
|
+
"cpp": orNull(link.cpp),
|
|
235
|
+
"ppid": orNull(link.ppid),
|
|
236
|
+
"clickId": orNull(link.clickId),
|
|
237
|
+
"visitId": orNull(link.visitId),
|
|
238
|
+
"campaignIds": orNull(link.campaignIds),
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static func dictionary(from attribution: KerdlyAttribution) -> [String: Any] {
|
|
243
|
+
var decidedAt: Any = NSNull()
|
|
244
|
+
if let date = attribution.decidedAt {
|
|
245
|
+
decidedAt = (date.timeIntervalSince1970 * 1000).rounded()
|
|
246
|
+
}
|
|
247
|
+
return [
|
|
248
|
+
"state": attribution.state,
|
|
249
|
+
"network": attribution.network,
|
|
250
|
+
"status": attribution.status,
|
|
251
|
+
"method": attribution.method,
|
|
252
|
+
"campaignId": orNull(attribution.campaignId),
|
|
253
|
+
"campaign": orNull(attribution.campaign),
|
|
254
|
+
"adsetId": orNull(attribution.adsetId),
|
|
255
|
+
"adset": orNull(attribution.adset),
|
|
256
|
+
"adId": orNull(attribution.adId),
|
|
257
|
+
"ad": orNull(attribution.ad),
|
|
258
|
+
"keywordId": orNull(attribution.keywordId),
|
|
259
|
+
"keyword": orNull(attribution.keyword),
|
|
260
|
+
"linkId": orNull(attribution.linkId),
|
|
261
|
+
"cppId": orNull(attribution.cppId),
|
|
262
|
+
"decidedAt": decidedAt,
|
|
263
|
+
"raw": attribution.raw,
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/// `Kerdly.onAttribution` has no unregister, so the handler is registered once per process and routed
|
|
269
|
+
/// to the live module instance (a JS reload creates a new one).
|
|
270
|
+
private final class KerdlyExpoAttributionRelay: @unchecked Sendable {
|
|
271
|
+
static let shared = KerdlyExpoAttributionRelay()
|
|
272
|
+
|
|
273
|
+
private let lock = NSLock()
|
|
274
|
+
private weak var module: KerdlySdkModule?
|
|
275
|
+
private var registered = false
|
|
276
|
+
|
|
277
|
+
func attach(_ module: KerdlySdkModule) {
|
|
278
|
+
lock.lock()
|
|
279
|
+
self.module = module
|
|
280
|
+
let needsRegistration = !registered
|
|
281
|
+
registered = true
|
|
282
|
+
lock.unlock()
|
|
283
|
+
if needsRegistration {
|
|
284
|
+
Kerdly.onAttribution { [weak self] attribution in
|
|
285
|
+
self?.deliver(attribution)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
func detach(_ module: KerdlySdkModule) {
|
|
291
|
+
lock.lock()
|
|
292
|
+
if self.module === module {
|
|
293
|
+
self.module = nil
|
|
294
|
+
}
|
|
295
|
+
lock.unlock()
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private func deliver(_ attribution: KerdlyAttribution) {
|
|
299
|
+
lock.lock()
|
|
300
|
+
let module = self.module
|
|
301
|
+
lock.unlock()
|
|
302
|
+
module?.sendEvent(KerdlySdkModule.attributionEvent, KerdlySdkModule.dictionary(from: attribution))
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// MARK: - Arguments (src/native.ts is the JS side of this contract)
|
|
307
|
+
|
|
308
|
+
struct KerdlyExpoConfigureOptions: ExpoModulesCore.Record {
|
|
309
|
+
@ExpoModulesCore.Field var key: String = ""
|
|
310
|
+
@ExpoModulesCore.Field var endpoint: String = ""
|
|
311
|
+
@ExpoModulesCore.Field var environment: String = "auto"
|
|
312
|
+
@ExpoModulesCore.Field var collectAdvertisingId: Bool = true
|
|
313
|
+
@ExpoModulesCore.Field var skanWriter: Bool = false
|
|
314
|
+
@ExpoModulesCore.Field var logLevel: String = "warn"
|
|
315
|
+
@ExpoModulesCore.Field var wrapper: String? = nil
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
struct KerdlyExpoPurchase: ExpoModulesCore.Record {
|
|
319
|
+
@ExpoModulesCore.Field var originalTransactionId: String? = nil
|
|
320
|
+
@ExpoModulesCore.Field var transactionId: String? = nil
|
|
321
|
+
@ExpoModulesCore.Field var productId: String? = nil
|
|
322
|
+
@ExpoModulesCore.Field var appAccountToken: String? = nil
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
struct KerdlyExpoNetworkSend: ExpoModulesCore.Record {
|
|
326
|
+
@ExpoModulesCore.Field var network: String = ""
|
|
327
|
+
@ExpoModulesCore.Field var event: String = ""
|
|
328
|
+
@ExpoModulesCore.Field var eventId: String? = nil
|
|
329
|
+
@ExpoModulesCore.Field var value: Double? = nil
|
|
330
|
+
@ExpoModulesCore.Field var currency: String? = nil
|
|
331
|
+
@ExpoModulesCore.Field var flag: String? = nil
|
|
332
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,94 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kerdly/expo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Kerdly SDK for Expo and React Native: first-party install attribution, deep links, events and subscription purchases for iOS and Android, so you can see which ads pay back.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Kerdly",
|
|
7
|
+
"homepage": "https://kerdly.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Kerdly/kerdly-sdk.git",
|
|
11
|
+
"directory": "expo"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"kerdly",
|
|
15
|
+
"attribution",
|
|
16
|
+
"mobile-attribution",
|
|
17
|
+
"first-party-attribution",
|
|
18
|
+
"app-analytics",
|
|
19
|
+
"subscription-analytics",
|
|
20
|
+
"roas",
|
|
21
|
+
"ltv",
|
|
22
|
+
"ad-attribution",
|
|
23
|
+
"skadnetwork",
|
|
24
|
+
"deep-linking",
|
|
25
|
+
"deferred-deep-linking",
|
|
26
|
+
"apple-search-ads",
|
|
27
|
+
"install-referrer",
|
|
28
|
+
"react-native",
|
|
29
|
+
"expo",
|
|
30
|
+
"expo-module",
|
|
31
|
+
"config-plugin",
|
|
32
|
+
"ios",
|
|
33
|
+
"android"
|
|
34
|
+
],
|
|
35
|
+
"main": "build/index.js",
|
|
36
|
+
"types": "build/index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"build",
|
|
39
|
+
"src",
|
|
40
|
+
"plugin",
|
|
41
|
+
"app.plugin.js",
|
|
42
|
+
"expo-module.config.json",
|
|
43
|
+
"ios/KerdlySdk.podspec",
|
|
44
|
+
"ios/*.swift",
|
|
45
|
+
"ios/KerdlySDK",
|
|
46
|
+
"android/build.gradle",
|
|
47
|
+
"android/src/main",
|
|
48
|
+
"android/vendor",
|
|
49
|
+
"README.md",
|
|
50
|
+
"LICENSE"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsc -p tsconfig.build.json",
|
|
54
|
+
"clean": "node -e \"require('fs').rmSync('build',{recursive:true,force:true})\"",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"test": "jest",
|
|
57
|
+
"sync-native": "node scripts/sync-native.mjs",
|
|
58
|
+
"sync-native:check": "node scripts/sync-native.mjs --check",
|
|
59
|
+
"prepare": "node scripts/sync-native.mjs && npm run build",
|
|
60
|
+
"prepack": "node scripts/sync-native.mjs --strict && npm run build"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"expo": "*",
|
|
64
|
+
"expo-modules-core": "*",
|
|
65
|
+
"react-native": "*"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"expo": {
|
|
69
|
+
"optional": true
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@expo/config-plugins": "^57.0.10",
|
|
74
|
+
"@types/jest": "^30.0.0",
|
|
75
|
+
"@types/node": "^22.20.5",
|
|
76
|
+
"@types/react": "^19.1.1",
|
|
77
|
+
"expo-modules-core": "~57.0.22",
|
|
78
|
+
"jest": "^30.5.2",
|
|
79
|
+
"react": "^19.2.3",
|
|
80
|
+
"react-native": "0.87.1",
|
|
81
|
+
"ts-jest": "^29.4.14",
|
|
82
|
+
"typescript": "~6.0.3"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=20"
|
|
86
|
+
},
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"access": "public",
|
|
89
|
+
"provenance": true
|
|
90
|
+
},
|
|
91
|
+
"bugs": {
|
|
92
|
+
"url": "https://github.com/Kerdly/kerdly-sdk/issues"
|
|
93
|
+
}
|
|
94
|
+
}
|