@kerdly/expo 0.0.0-stage → 0.1.1

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 +110 -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 +236 -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 +96 -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 +96 -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 +182 -0
  112. package/src/validation.ts +343 -0
  113. package/src/version.ts +5 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kerdly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,236 @@
1
- # Temporary Holding Version
1
+ # @kerdly/expo
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Kerdly SDK for Expo and React Native apps. It runs the native Kerdly SDKs for
4
+ [iOS](https://github.com/Kerdly/kerdly-sdk/blob/main/ios/README.md) and [Android](https://github.com/Kerdly/kerdly-sdk/blob/main/android/README.md) inside your app, adds a config plugin, and
5
+ captures deep links automatically.
6
+
7
+ [Kerdly](https://kerdly.com) is profit analytics for subscription apps: it ties each install to the ad
8
+ that brought it and to the store revenue it earns. The full guide is at
9
+ [kerdly.com/docs/sdks/expo](https://kerdly.com/docs/sdks/expo).
10
+
11
+ It needs a development or production build (`npx expo prebuild` / EAS Build). Expo Go and web do
12
+ not contain the native code: there every call is a no-op, with one development warning. It needs
13
+ Expo SDK 52 or newer (native modules as event emitters) and is developed against SDK 57.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ npx expo install @kerdly/expo
19
+ ```
20
+
21
+ Add the config plugin to `app.json` / `app.config.ts`, then run `npx expo prebuild` (or build with EAS):
22
+
23
+ ```json
24
+ {
25
+ "expo": {
26
+ "plugins": [
27
+ [
28
+ "@kerdly/expo",
29
+ {
30
+ "metaAppId": "1234567890123456",
31
+ "userTrackingPermission": "Lets us measure which of our ads brought you here.",
32
+ "skanEndpoint": "https://kerdly-skan.com"
33
+ }
34
+ ]
35
+ ]
36
+ }
37
+ }
38
+ ```
39
+
40
+ | Option | Platform | Writes |
41
+ |---|---|---|
42
+ | `metaAppId` | Android | `<meta-data android:name="com.kerdly.sdk.META_APP_ID" android:value="@string/kerdly_meta_app_id">` plus that string resource. A string resource because a numeric literal in `android:value` is compiled as a number, not a string. Removed again when the option is dropped. |
43
+ | `userTrackingPermission` | iOS | `NSUserTrackingUsageDescription`, the App Tracking Transparency prompt text. Needed for `requestTrackingAuthorization()`. |
44
+ | `skanEndpoint` | iOS | `NSAdvertisingAttributionReportEndpoint`, the https origin that receives copies of SKAdNetwork postbacks. |
45
+
46
+ The plugin only sets keys it is given and never removes an Info.plist key, so values set in
47
+ `ios.infoPlist` survive. Running it twice changes nothing. `Kerdly.configure({ metaAppId })` overrides
48
+ the plugin's `metaAppId`.
49
+
50
+ The module's Android manifest adds `INTERNET`, `com.google.android.gms.permission.AD_ID` and
51
+ `<queries>` for `com.facebook.katana`, `com.instagram.android` and `com.facebook.lite` (Meta Install
52
+ Referrer). An app that must not read the advertising id removes `AD_ID` (Expo's
53
+ `android.blockedPermissions`) and passes `collectAdvertisingId: false`.
54
+
55
+ ## Configure
56
+
57
+ Call `configure` once, as early as possible: at module scope of the root file (`app/_layout.tsx`
58
+ with Expo Router, `App.tsx` otherwise), not inside a component.
59
+
60
+ ```ts
61
+ import { Kerdly } from '@kerdly/expo';
62
+
63
+ Kerdly.configure({
64
+ key: 'pk_live_…', // the app's public key (pk_test_… for test builds)
65
+ // endpoint: 'https://app.kerdly.com/api', // default
66
+ // environment: 'auto', // 'production' | 'sandbox' | 'development'
67
+ // collectAdvertisingId: true,
68
+ // skanWriter: false, // iOS: write SKAdNetwork conversion values
69
+ // metaAppId: '…', // Android; defaults to the plugin's metaAppId
70
+ // logLevel: 'warn', // 'none' | 'error' | 'warn' | 'info' | 'debug'
71
+ // autoDeepLinks: true,
72
+ });
73
+ ```
74
+
75
+ A second `configure` is ignored. Calls made before `configure` are held and run after it.
76
+
77
+ No function throws and no promise rejects. Invalid input is dropped with a development warning
78
+ (`console.warn`, only when `__DEV__`, silenced by `logLevel: 'none' | 'error'`).
79
+
80
+ ## API
81
+
82
+ | Call | Does |
83
+ |---|---|
84
+ | `await Kerdly.configure(options)` | Starts the native SDK; resolves once the native `configure` has run. |
85
+ | `Kerdly.setUserId(id \| null)` | The app's user id, attached to every later event (`$identify` on change). |
86
+ | `Kerdly.track(name, props?)` | A custom event. `name` and prop keys match `^[a-z][a-z0-9_]{0,39}$`; at most 25 props; values are strings (truncated to 256), finite numbers or booleans. An invalid name drops the event; invalid props are dropped one by one. |
87
+ | `Kerdly.trackRegistration({ method?, properties? })` | Standard event `registration`: the user signed up (`method`: `anonymous`, `apple`, `google`, `email`, …). See [Standard events](#standard-events). |
88
+ | `Kerdly.trackStartTrial({ productId?, value?, currency?, transactionId?, properties? })` | Standard event `start_trial` (`value: 0` for a free trial). |
89
+ | `Kerdly.trackSubscribe({ productId?, value?, currency?, transactionId?, properties? })` | Standard event `subscribe`. |
90
+ | `Kerdly.trackPurchase({ productId?, value?, currency?, quantity?, transactionId?, properties? })` | Standard event `purchase`, a one-time purchase. |
91
+ | `Kerdly.setConsent({ analytics?, ads? })` | An omitted flag keeps its value. `analytics: false` keeps only the SDK's own events; `ads: false` stops IDFA / GAID reads. |
92
+ | `await Kerdly.handleUrl(url)` | Records `$deeplink` and returns `{ url, cpp, ppid, clickId, visitId, campaignIds }` (each `null` when absent), or `null`. |
93
+ | `Kerdly.setAppAccountToken(token \| null)` | iOS: the StoreKit `appAccountToken` UUID. Android: the Play `obfuscatedAccountId` the purchases carry. |
94
+ | `Kerdly.setPartnerIds({ meta_anon_id: '…' })` | Ids other SDKs own; merged, an empty value removes a key. |
95
+ | `Kerdly.notifyPurchase(purchase?)` | `$purchase_link`, once per transaction / token. iOS shape `{ originalTransactionId, transactionId, productId, appAccountToken }`; Android shape `{ purchaseToken, orderId, products, purchaseTime, obfuscatedAccountId, obfuscatedProfileId }`. Each platform reads its own fields. On iOS, calling it with no purchase sweeps `Transaction.currentEntitlements`; Android needs `purchaseToken`. |
96
+ | `Kerdly.recordNetworkSend({ network, event, eventId?, value?, currency?, flag? })` | `$network_send`: a conversion the app sent to an ad network itself. |
97
+ | `await Kerdly.getAttribution()` | The install's attribution (`network`, `campaign`, …; `raw` holds every field), or `null` until it is known. |
98
+ | `Kerdly.addAttributionListener(fn)` | Calls `fn` with the current attribution at once (when known) and on every change, like the native `onAttribution`. Returns `{ remove() }`. |
99
+ | `await Kerdly.requestTrackingAuthorization()` | iOS: shows the ATT prompt once the app is active and resolves the status. Android: `"not_applicable"`. |
100
+ | `await Kerdly.flush()` | Asks the native SDK to send its queue now. |
101
+ | `await Kerdly.getInstallId()` | The install id (lowercase UUID), or `null` before `configure`. |
102
+
103
+ ### Standard events
104
+
105
+ `trackRegistration`, `trackStartTrial`, `trackSubscribe` and `trackPurchase` send Kerdly's standard
106
+ events with typed fields. Every field is optional, and a malformed field is dropped with a development
107
+ warning, never the event:
108
+
109
+ - `productId`, `transactionId`: non-empty strings, cut to 128 characters; `method`: cut to 64.
110
+ - `value`: what the user paid in `currency`, a finite number ≥ 0 (`0` for a free trial).
111
+ - `currency`: three letters (ISO 4217), upper-cased. Without a valid `currency` the `value` is
112
+ dropped, because a value without a currency means nothing to an ad network.
113
+ - `quantity`: an integer ≥ 1.
114
+ - `properties`: extra custom props under the `track` rules. A key that is one of the event's typed
115
+ props (`value`, `product_id`, …) is dropped: set it through the typed field. A field the event
116
+ does not have (say `quantity` on `trackSubscribe`, or a snake_case `product_id`) is reported and
117
+ ignored.
118
+
119
+ ```ts
120
+ Kerdly.trackRegistration({ method: 'apple' });
121
+ Kerdly.trackStartTrial({ productId: 'car_weekly_pro', value: 0, currency: 'USD', transactionId });
122
+ Kerdly.trackSubscribe({ productId: 'car_weekly_pro', value: 7.99, currency: 'USD', transactionId, properties: { plan: 'weekly' } });
123
+ ```
124
+
125
+ `track('start_trial', …)` also works and gets the same checks.
126
+
127
+ ### Deep links
128
+
129
+ With `autoDeepLinks: true` (the default) `configure` forwards React Native `Linking` URLs to the
130
+ native `handleUrl`: the initial URL once per JS runtime, and every `url` event. `expo-dev-client`
131
+ launcher URLs (`<scheme>://expo-development-client/…`) are skipped. Do not also call `handleUrl` for
132
+ those URLs; use it for links that never reach `Linking` (for example a deferred link from another
133
+ SDK), or turn `autoDeepLinks` off and call it yourself.
134
+
135
+ The automatic capture tells the native SDK which URL it is: `initial` for the launch URL, `runtime`
136
+ for a later `url` event. A URL passed to `Kerdly.handleUrl` yourself leaves that to the native SDK: the
137
+ first URL after launch, before the app went to the background, counts as `initial` (iOS also
138
+ requires it within 60 s of `configure`).
139
+
140
+ ### Attribution
141
+
142
+ ```tsx
143
+ const [attribution, setAttribution] = useState<KerdlyAttribution | null>(null);
144
+
145
+ useEffect(() => {
146
+ const sub = Kerdly.addAttributionListener(setAttribution);
147
+ return () => sub.remove();
148
+ }, []);
149
+ ```
150
+
151
+ ## Superwall hand-off
152
+
153
+ Tell the SDK which account token the purchases will carry, then link each completed transaction
154
+ (`expo-superwall`):
155
+
156
+ ```tsx
157
+ import { useEffect } from 'react';
158
+ import { Platform } from 'react-native';
159
+ import { useSuperwallEvents, useUser } from 'expo-superwall';
160
+ import { Kerdly } from '@kerdly/expo';
161
+
162
+ export function KerdlySuperwallBridge() {
163
+ const { user } = useUser();
164
+ const alias = user?.aliasId; // "$SuperwallAlias:3F2504E0-4F89-41D3-9A0C-0305E82C3301"
165
+
166
+ useEffect(() => {
167
+ if (!alias) return;
168
+ const aliasUuid = alias.replace(/^\$SuperwallAlias:/, '');
169
+ // iOS takes the StoreKit appAccountToken (a UUID); Android takes the Play obfuscatedAccountId,
170
+ // which (per the native Android SDK) is the alias string itself before identify.
171
+ Kerdly.setAppAccountToken(Platform.OS === 'ios' ? aliasUuid : alias);
172
+ Kerdly.setPartnerIds({ superwall_alias: alias });
173
+ }, [alias]);
174
+
175
+ useSuperwallEvents({
176
+ onSuperwallEvent: ({ event }) => {
177
+ if (event.event !== 'transactionComplete') return;
178
+ const tx = event.transaction;
179
+ if (Platform.OS === 'ios') {
180
+ Kerdly.notifyPurchase({
181
+ originalTransactionId: tx?.originalTransactionIdentifier,
182
+ transactionId: tx?.storeTransactionId,
183
+ productId: event.product.productIdentifier,
184
+ appAccountToken: tx?.appAccountToken,
185
+ });
186
+ } else if (tx?.purchaseToken) {
187
+ Kerdly.notifyPurchase({
188
+ purchaseToken: tx.purchaseToken,
189
+ orderId: tx.storeTransactionId,
190
+ products: [event.product.productIdentifier],
191
+ });
192
+ }
193
+ },
194
+ });
195
+
196
+ return null;
197
+ }
198
+ ```
199
+
200
+ Render it inside `<SuperwallProvider>`. On iOS, `Kerdly.notifyPurchase()` with no argument (after a
201
+ restore, say) sweeps the current entitlements instead.
202
+
203
+ ## Recording sends to ad networks
204
+
205
+ When the app reports a conversion to Meta or TikTok through their SDKs, record the same send right
206
+ after it, with the same event id the network gets, so Kerdly can show both sides:
207
+
208
+ ```ts
209
+ const eventId = `${originalTransactionId}:trial_start`;
210
+
211
+ // your existing Meta call (react-native-fbsdk-next, for example), sent with eventId
212
+ Kerdly.recordNetworkSend({
213
+ network: 'meta',
214
+ event: 'StartTrial',
215
+ eventId,
216
+ value: 0,
217
+ currency: 'USD',
218
+ flag: 'meta_start_trial_enabled', // the feature flag that allowed the send, if any
219
+ });
220
+
221
+ // your existing TikTok call, sent with eventId
222
+ Kerdly.recordNetworkSend({ network: 'tiktok', event: 'Subscribe', eventId, value: 9.99, currency: 'USD' });
223
+ ```
224
+
225
+ ## Data and privacy
226
+
227
+ The native SDKs do the collecting. See [iOS: Data and privacy](https://github.com/Kerdly/kerdly-sdk/blob/main/ios/README.md#data-and-privacy) and
228
+ [Android: Data and privacy](https://github.com/Kerdly/kerdly-sdk/blob/main/android/README.md#data-and-privacy) for your App Store and Google Play
229
+ answers.
230
+
231
+ ## Troubleshooting
232
+
233
+ - `logLevel: 'debug'` turns on native logs (`[Kerdly]` in the Xcode console and logcat) and
234
+ development warnings for invalid input.
235
+ - Questions or problems: [open an issue](https://github.com/Kerdly/kerdly-sdk/issues) or contact
236
+ Kerdly support. Never post your keys.
@@ -0,0 +1,61 @@
1
+ plugins {
2
+ id 'com.android.library'
3
+ id 'expo-module-gradle-plugin'
4
+ }
5
+
6
+ def packageJson = new groovy.json.JsonSlurper().parse(file('../package.json'))
7
+
8
+ group = 'com.kerdly.expo'
9
+ version = packageJson.version
10
+
11
+ // The native Android SDK (package com.kerdly.sdk) is vendored into vendor/kerdly-sdk by
12
+ // scripts/sync-native.mjs (npm `prepare`/`prepack`) and compiled into this module with the bridge.
13
+ def vendoredSdk = file('vendor/kerdly-sdk')
14
+ def sdkPropertiesFile = new File(vendoredSdk, 'kerdly-sdk.properties')
15
+ if (!sdkPropertiesFile.exists()) {
16
+ throw new GradleException(
17
+ "[@kerdly/expo] ${vendoredSdk} is missing. Run `npm run sync-native` in the @kerdly/expo " +
18
+ "package (it copies ../android/kerdly-sdk), or install a packed/published build of the package."
19
+ )
20
+ }
21
+ def sdkProperties = new Properties()
22
+ sdkPropertiesFile.withInputStream { sdkProperties.load(it) }
23
+
24
+ android {
25
+ // The SDK's own namespace, so the vendored sources find com.kerdly.sdk.BuildConfig (and R) exactly as
26
+ // in the standalone library. The bridge classes live in package com.kerdly.expo.
27
+ namespace 'com.kerdly.sdk'
28
+
29
+ buildFeatures {
30
+ buildConfig true
31
+ }
32
+
33
+ defaultConfig {
34
+ versionCode 1
35
+ versionName packageJson.version
36
+ // As in kerdly-sdk/build.gradle.kts: the native SDK version, sent in `sdk.version` and `X-Kerdly-Sdk`.
37
+ buildConfigField 'String', 'KERDLY_VERSION', "\"${sdkProperties.getProperty('KERDLY_VERSION')}\""
38
+ // The SDK's consumer R8 rules, when it ships any.
39
+ def sdkRules = new File(vendoredSdk, 'consumer-rules.pro')
40
+ if (sdkRules.exists()) {
41
+ consumerProguardFiles sdkRules
42
+ }
43
+ }
44
+
45
+ sourceSets {
46
+ main {
47
+ java.srcDirs += ['vendor/kerdly-sdk/java', 'vendor/kerdly-sdk/kotlin']
48
+ res.srcDirs += ['vendor/kerdly-sdk/res']
49
+ assets.srcDirs += ['vendor/kerdly-sdk/assets']
50
+ resources.srcDirs += ['vendor/kerdly-sdk/resources']
51
+ // The SDK's manifest entries are declared in src/main/AndroidManifest.xml (the sync script
52
+ // fails when they drift apart).
53
+ }
54
+ }
55
+ }
56
+
57
+ dependencies {
58
+ // The vendored SDK's dependencies (kerdly-sdk/build.gradle.kts; the sync script checks they match).
59
+ implementation 'com.android.installreferrer:installreferrer:2.2'
60
+ implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
61
+ }
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- The vendored com.kerdly.sdk sources need these entries (mirrors android/kerdly-sdk/src/main/AndroidManifest.xml
3
+ of the native SDK; scripts/sync-native.mjs fails when they drift apart). Merged into the app's manifest. -->
4
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
5
+
6
+ <uses-permission android:name="android.permission.INTERNET" />
7
+
8
+ <!-- Google advertising id (GAID) on Android 13+. Apps that must not read it remove it with
9
+ tools:node="remove" (or expo's android.blockedPermissions) and pass collectAdvertisingId: false. -->
10
+ <uses-permission android:name="com.google.android.gms.permission.AD_ID" />
11
+
12
+ <!-- Package visibility (Android 11+) for the Meta Install Referrer content providers. -->
13
+ <queries>
14
+ <package android:name="com.facebook.katana" />
15
+ <package android:name="com.instagram.android" />
16
+ <package android:name="com.facebook.lite" />
17
+ </queries>
18
+
19
+ </manifest>
@@ -0,0 +1,326 @@
1
+ package com.kerdly.expo
2
+
3
+ import android.content.Context
4
+ import android.content.pm.PackageManager
5
+ import android.os.Build
6
+ import android.util.Log
7
+ import com.kerdly.sdk.Kerdly
8
+ import com.kerdly.sdk.KerdlyAttribution
9
+ import com.kerdly.sdk.KerdlyDeepLink
10
+ import com.kerdly.sdk.KerdlyEnvironment
11
+ import com.kerdly.sdk.KerdlyLogLevel
12
+ import com.kerdly.sdk.KerdlyNetworkSend
13
+ import com.kerdly.sdk.KerdlyOptions
14
+ import com.kerdly.sdk.KerdlyPurchase
15
+ import expo.modules.kotlin.functions.Queues
16
+ import expo.modules.kotlin.modules.Module
17
+ import expo.modules.kotlin.modules.ModuleDefinition
18
+ import expo.modules.kotlin.records.Field
19
+ import expo.modules.kotlin.records.Record
20
+ import java.lang.ref.WeakReference
21
+
22
+ /**
23
+ * The Expo bridge over the native Android SDK. The com.kerdly.sdk sources are
24
+ * vendored into this module by scripts/sync-native.mjs.
25
+ *
26
+ * Every function is an AsyncFunction on the main queue, so native calls run in the order JS made
27
+ * them (configure first) and `configure` runs on the main thread like in a native app.
28
+ */
29
+ class KerdlySdkModule : Module() {
30
+ override fun definition() = ModuleDefinition {
31
+ Name("KerdlySdk")
32
+
33
+ Events(ATTRIBUTION_EVENT)
34
+
35
+ OnCreate {
36
+ AttributionRelay.attach(this@KerdlySdkModule)
37
+ }
38
+
39
+ OnDestroy {
40
+ AttributionRelay.detach(this@KerdlySdkModule)
41
+ }
42
+
43
+ AsyncFunction("configure") { options: ConfigureOptions ->
44
+ val context = appContext.reactContext?.applicationContext
45
+ if (context == null) {
46
+ Log.w(TAG, "configure: no Android context; the SDK was not configured")
47
+ } else if (options.key.isEmpty() || options.endpoint.isEmpty()) {
48
+ Log.w(TAG, "configure: key and endpoint are required; the SDK was not configured")
49
+ } else {
50
+ Kerdly.configure(
51
+ context,
52
+ KerdlyOptions(
53
+ key = options.key,
54
+ endpoint = options.endpoint,
55
+ environment = environment(options.environment),
56
+ collectAdvertisingId = options.collectAdvertisingId,
57
+ // The config plugin's `metaAppId` lands in the manifest; use it when JS passes none.
58
+ metaAppId = options.metaAppId?.takeIf { it.isNotEmpty() } ?: manifestMetaAppId(context),
59
+ logLevel = logLevel(options.logLevel),
60
+ wrapper = options.wrapper,
61
+ ),
62
+ )
63
+ }
64
+ }.runOnQueue(Queues.MAIN)
65
+
66
+ AsyncFunction("setUserId") { userId: String? ->
67
+ Kerdly.setUserId(userId)
68
+ }.runOnQueue(Queues.MAIN)
69
+
70
+ AsyncFunction("track") { name: String, properties: Map<String, Any?> ->
71
+ Kerdly.track(name, properties)
72
+ }.runOnQueue(Queues.MAIN)
73
+
74
+ // Standard events. JS passes every typed field, null when omitted, in the order
75
+ // of the native signature; the SDK validates them again.
76
+ AsyncFunction("trackRegistration") { method: String?, properties: Map<String, Any?> ->
77
+ Kerdly.trackRegistration(method = method, properties = properties)
78
+ }.runOnQueue(Queues.MAIN)
79
+
80
+ AsyncFunction("trackStartTrial") {
81
+ productId: String?, value: Double?, currency: String?, transactionId: String?,
82
+ properties: Map<String, Any?> ->
83
+ Kerdly.trackStartTrial(
84
+ productId = productId,
85
+ value = value,
86
+ currency = currency,
87
+ transactionId = transactionId,
88
+ properties = properties,
89
+ )
90
+ }.runOnQueue(Queues.MAIN)
91
+
92
+ AsyncFunction("trackSubscribe") {
93
+ productId: String?, value: Double?, currency: String?, transactionId: String?,
94
+ properties: Map<String, Any?> ->
95
+ Kerdly.trackSubscribe(
96
+ productId = productId,
97
+ value = value,
98
+ currency = currency,
99
+ transactionId = transactionId,
100
+ properties = properties,
101
+ )
102
+ }.runOnQueue(Queues.MAIN)
103
+
104
+ AsyncFunction("trackPurchase") {
105
+ productId: String?, value: Double?, currency: String?, quantity: Int?, transactionId: String?,
106
+ properties: Map<String, Any?> ->
107
+ Kerdly.trackPurchase(
108
+ productId = productId,
109
+ value = value,
110
+ currency = currency,
111
+ quantity = quantity,
112
+ transactionId = transactionId,
113
+ properties = properties,
114
+ )
115
+ }.runOnQueue(Queues.MAIN)
116
+
117
+ AsyncFunction("setConsent") { analytics: Boolean?, ads: Boolean? ->
118
+ Kerdly.setConsent(analytics, ads)
119
+ }.runOnQueue(Queues.MAIN)
120
+
121
+ // The second argument is the source the JS layer knows ("initial" for Linking's initial URL,
122
+ // "runtime" for its `url` events, or null); the SDK infers it only when it is null.
123
+ AsyncFunction("handleUrl") { url: String, source: String? ->
124
+ Kerdly.handleUrl(url, source)?.let { toMap(it) }
125
+ }.runOnQueue(Queues.MAIN)
126
+
127
+ AsyncFunction("setAppAccountToken") { token: String? ->
128
+ Kerdly.setAppAccountToken(token)
129
+ }.runOnQueue(Queues.MAIN)
130
+
131
+ AsyncFunction("setPartnerIds") { ids: Map<String, String> ->
132
+ Kerdly.setPartnerIds(ids)
133
+ }.runOnQueue(Queues.MAIN)
134
+
135
+ // Accepts either platform's shape; only the Android fields are read. Android has no
136
+ // entitlement sweep, so a purchase without purchaseToken is ignored.
137
+ AsyncFunction("notifyPurchase") { purchase: PurchaseRecord? ->
138
+ val token = purchase?.purchaseToken?.takeIf { it.isNotEmpty() }
139
+ if (purchase == null || token == null) {
140
+ Log.w(TAG, "notifyPurchase: purchaseToken is required on Android; ignored")
141
+ } else {
142
+ Kerdly.notifyPurchase(
143
+ KerdlyPurchase(
144
+ purchaseToken = token,
145
+ orderId = purchase.orderId,
146
+ products = purchase.products ?: emptyList(),
147
+ purchaseTime = purchase.purchaseTime?.toLong(),
148
+ obfuscatedAccountId = purchase.obfuscatedAccountId,
149
+ obfuscatedProfileId = purchase.obfuscatedProfileId,
150
+ ),
151
+ )
152
+ }
153
+ }.runOnQueue(Queues.MAIN)
154
+
155
+ AsyncFunction("recordNetworkSend") { send: NetworkSendRecord ->
156
+ if (send.network.isEmpty() || send.event.isEmpty()) {
157
+ Log.w(TAG, "recordNetworkSend: network and event are required; ignored")
158
+ } else {
159
+ Kerdly.recordNetworkSend(
160
+ KerdlyNetworkSend(
161
+ network = send.network,
162
+ event = send.event,
163
+ eventId = send.eventId,
164
+ value = send.value,
165
+ currency = send.currency,
166
+ flag = send.flag,
167
+ ),
168
+ )
169
+ }
170
+ }.runOnQueue(Queues.MAIN)
171
+
172
+ AsyncFunction("getAttribution") {
173
+ Kerdly.attribution?.let { toMap(it) }
174
+ }.runOnQueue(Queues.MAIN)
175
+
176
+ // App Tracking Transparency is iOS-only (the JS layer does not even call this on Android).
177
+ AsyncFunction("requestTrackingAuthorization") {
178
+ "not_applicable"
179
+ }
180
+
181
+ AsyncFunction("flush") {
182
+ Kerdly.flush()
183
+ }.runOnQueue(Queues.MAIN)
184
+
185
+ AsyncFunction("getInstallId") {
186
+ Kerdly.installId
187
+ }.runOnQueue(Queues.MAIN)
188
+ }
189
+
190
+ companion object {
191
+ private const val TAG = "Kerdly"
192
+ const val ATTRIBUTION_EVENT = "onAttribution"
193
+ const val META_APP_ID_KEY = "com.kerdly.sdk.META_APP_ID"
194
+
195
+ fun environment(name: String): KerdlyEnvironment = when (name) {
196
+ "production" -> KerdlyEnvironment.PRODUCTION
197
+ "sandbox" -> KerdlyEnvironment.SANDBOX
198
+ "development" -> KerdlyEnvironment.DEVELOPMENT
199
+ else -> KerdlyEnvironment.AUTO
200
+ }
201
+
202
+ fun logLevel(name: String): KerdlyLogLevel = when (name) {
203
+ "none" -> KerdlyLogLevel.NONE
204
+ "error" -> KerdlyLogLevel.ERROR
205
+ "info" -> KerdlyLogLevel.INFO
206
+ "debug" -> KerdlyLogLevel.DEBUG
207
+ else -> KerdlyLogLevel.WARN
208
+ }
209
+
210
+ /**
211
+ * `com.kerdly.sdk.META_APP_ID` from the app manifest. The config plugin writes it as a string
212
+ * resource; a hand-written numeric literal arrives as a number, hence `get` + `toString`.
213
+ */
214
+ @Suppress("DEPRECATION")
215
+ fun manifestMetaAppId(context: Context): String? = try {
216
+ val packageManager = context.packageManager
217
+ val info = if (Build.VERSION.SDK_INT >= 33) {
218
+ packageManager.getApplicationInfo(
219
+ context.packageName,
220
+ PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()),
221
+ )
222
+ } else {
223
+ packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA)
224
+ }
225
+ info.metaData?.get(META_APP_ID_KEY)?.toString()?.takeIf { it.isNotEmpty() }
226
+ } catch (error: Exception) {
227
+ Log.w(TAG, "Could not read $META_APP_ID_KEY from the manifest", error)
228
+ null
229
+ }
230
+
231
+ fun toMap(link: KerdlyDeepLink): Map<String, Any?> = mapOf(
232
+ "url" to link.url,
233
+ "cpp" to link.cpp,
234
+ "ppid" to link.ppid,
235
+ "clickId" to link.clickId,
236
+ "visitId" to link.visitId,
237
+ "campaignIds" to link.campaignIds,
238
+ )
239
+
240
+ /** `raw` stays the JSON string the SDK holds; the JS layer parses it. */
241
+ fun toMap(attribution: KerdlyAttribution): Map<String, Any?> = mapOf(
242
+ "state" to attribution.state,
243
+ "network" to attribution.network,
244
+ "status" to attribution.status,
245
+ "method" to attribution.method,
246
+ "campaignId" to attribution.campaignId,
247
+ "campaign" to attribution.campaign,
248
+ "adsetId" to attribution.adsetId,
249
+ "adset" to attribution.adset,
250
+ "adId" to attribution.adId,
251
+ "ad" to attribution.ad,
252
+ "keywordId" to attribution.keywordId,
253
+ "keyword" to attribution.keyword,
254
+ "linkId" to attribution.linkId,
255
+ "cppId" to attribution.cppId,
256
+ "decidedAt" to attribution.decidedAt?.toDouble(),
257
+ "raw" to attribution.raw,
258
+ )
259
+ }
260
+ }
261
+
262
+ /**
263
+ * `Kerdly.onAttribution` has no unregister, so the listener is registered once per process and
264
+ * routed to the live module instance (a JS reload creates a new one).
265
+ */
266
+ private object AttributionRelay {
267
+ private var module: WeakReference<KerdlySdkModule>? = null
268
+ private var registered = false
269
+
270
+ fun attach(module: KerdlySdkModule) {
271
+ val needsRegistration = synchronized(this) {
272
+ this.module = WeakReference(module)
273
+ val first = !registered
274
+ registered = true
275
+ first
276
+ }
277
+ if (needsRegistration) {
278
+ Kerdly.onAttribution { attribution -> deliver(attribution) }
279
+ }
280
+ }
281
+
282
+ fun detach(module: KerdlySdkModule) {
283
+ synchronized(this) {
284
+ if (this.module?.get() === module) this.module = null
285
+ }
286
+ }
287
+
288
+ private fun deliver(attribution: KerdlyAttribution) {
289
+ val target = synchronized(this) { module?.get() } ?: return
290
+ try {
291
+ target.sendEvent(KerdlySdkModule.ATTRIBUTION_EVENT, KerdlySdkModule.toMap(attribution))
292
+ } catch (error: Exception) {
293
+ Log.w("Kerdly", "Could not deliver the attribution event", error)
294
+ }
295
+ }
296
+ }
297
+
298
+ // Arguments (src/native.ts is the JS side of this contract).
299
+
300
+ class ConfigureOptions : Record {
301
+ @Field val key: String = ""
302
+ @Field val endpoint: String = ""
303
+ @Field val environment: String = "auto"
304
+ @Field val collectAdvertisingId: Boolean = true
305
+ @Field val metaAppId: String? = null
306
+ @Field val logLevel: String = "warn"
307
+ @Field val wrapper: String? = null
308
+ }
309
+
310
+ class PurchaseRecord : Record {
311
+ @Field val purchaseToken: String? = null
312
+ @Field val orderId: String? = null
313
+ @Field val products: List<String>? = null
314
+ @Field val purchaseTime: Double? = null
315
+ @Field val obfuscatedAccountId: String? = null
316
+ @Field val obfuscatedProfileId: String? = null
317
+ }
318
+
319
+ class NetworkSendRecord : Record {
320
+ @Field val network: String = ""
321
+ @Field val event: String = ""
322
+ @Field val eventId: String? = null
323
+ @Field val value: Double? = null
324
+ @Field val currency: String? = null
325
+ @Field val flag: String? = null
326
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "source": "android/kerdly-sdk",
3
+ "sdkVersion": "0.1.0",
4
+ "commit": "f2a51b419ea0d62132c54a2b04a735c48ba2a18d",
5
+ "dirty": false,
6
+ "files": 22,
7
+ "sha256": "2514a911896ca9fd67412cbbd8064fc37841d020fa489df0eca4dfd3a6126af3"
8
+ }