@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
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { DEFAULT_ENDPOINT, Kerdly } from './Kerdly';
|
|
2
|
+
export type { KerdlyApi, KerdlyDeferredLinkAnswer } from './Kerdly';
|
|
3
|
+
export type {
|
|
4
|
+
KerdlyAndroidPurchase,
|
|
5
|
+
KerdlyAttStatus,
|
|
6
|
+
KerdlyAttribution,
|
|
7
|
+
KerdlyAttributionListener,
|
|
8
|
+
KerdlyConfigureOptions,
|
|
9
|
+
KerdlyConsent,
|
|
10
|
+
KerdlyDeepLink,
|
|
11
|
+
KerdlyDeepLinkSource,
|
|
12
|
+
KerdlyEnvironment,
|
|
13
|
+
KerdlyEventProperties,
|
|
14
|
+
KerdlyEventValue,
|
|
15
|
+
KerdlyIosPurchase,
|
|
16
|
+
KerdlyLogLevel,
|
|
17
|
+
KerdlyNetworkSend,
|
|
18
|
+
KerdlyPurchase,
|
|
19
|
+
KerdlyPurchaseEvent,
|
|
20
|
+
KerdlyRegistrationEvent,
|
|
21
|
+
KerdlyRevenueEvent,
|
|
22
|
+
KerdlySubscription,
|
|
23
|
+
} from './types';
|
package/src/log.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { KerdlyLogLevel } from './types';
|
|
2
|
+
|
|
3
|
+
const RANK: Record<KerdlyLogLevel, number> = { none: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
4
|
+
|
|
5
|
+
let threshold: KerdlyLogLevel = 'warn';
|
|
6
|
+
|
|
7
|
+
export function setLogLevel(level: KerdlyLogLevel): void {
|
|
8
|
+
threshold = level;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isLogLevel(value: unknown): value is KerdlyLogLevel {
|
|
12
|
+
return typeof value === 'string' && Object.prototype.hasOwnProperty.call(RANK, value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isDev(): boolean {
|
|
16
|
+
return typeof __DEV__ !== 'undefined' && __DEV__ === true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Development-only warning (never in release builds), muted by `logLevel: 'none' | 'error'`.
|
|
21
|
+
* This package never throws into the app, so this is how misuse is surfaced.
|
|
22
|
+
*/
|
|
23
|
+
export function devWarn(message: string, ...details: unknown[]): void {
|
|
24
|
+
if (!isDev() || RANK[threshold] < RANK.warn) return;
|
|
25
|
+
try {
|
|
26
|
+
console.warn(`[Kerdly] ${message}`, ...details);
|
|
27
|
+
} catch {
|
|
28
|
+
// console itself must never break the app
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Development-only error, for exceptions thrown by the app's own callbacks. */
|
|
33
|
+
export function devError(message: string, ...details: unknown[]): void {
|
|
34
|
+
if (!isDev() || RANK[threshold] < RANK.error) return;
|
|
35
|
+
try {
|
|
36
|
+
console.error(`[Kerdly] ${message}`, ...details);
|
|
37
|
+
} catch {
|
|
38
|
+
// console itself must never break the app
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const warnedKeys = new Set<string>();
|
|
43
|
+
|
|
44
|
+
/** `devWarn`, at most once per `key` for the lifetime of the JS runtime. */
|
|
45
|
+
export function devWarnOnce(key: string, message: string, ...details: unknown[]): void {
|
|
46
|
+
if (warnedKeys.has(key)) return;
|
|
47
|
+
warnedKeys.add(key);
|
|
48
|
+
devWarn(message, ...details);
|
|
49
|
+
}
|
package/src/native.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { requireOptionalNativeModule } from 'expo-modules-core';
|
|
2
|
+
|
|
3
|
+
import { devWarn, devWarnOnce } from './log';
|
|
4
|
+
import type { KerdlyDeepLinkSource, KerdlyEnvironment, KerdlyEventValue, KerdlyLogLevel } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The JS <-> native contract. ios/KerdlySdkModule.swift and
|
|
8
|
+
* android/src/main/java/com/kerdly/expo/KerdlySdkModule.kt implement exactly these functions (all
|
|
9
|
+
* `AsyncFunction`s on the main queue, so native calls run in JS call order) and the
|
|
10
|
+
* `onAttribution` event. Payloads coming back from native are `unknown` here and normalised in
|
|
11
|
+
* normalize.ts.
|
|
12
|
+
*/
|
|
13
|
+
export const NATIVE_MODULE_NAME = 'KerdlySdk';
|
|
14
|
+
export const ATTRIBUTION_EVENT = 'onAttribution';
|
|
15
|
+
|
|
16
|
+
export interface NativeConfigureOptions {
|
|
17
|
+
key: string;
|
|
18
|
+
endpoint: string;
|
|
19
|
+
environment: KerdlyEnvironment;
|
|
20
|
+
collectAdvertisingId: boolean;
|
|
21
|
+
/** Read by iOS only. */
|
|
22
|
+
skanWriter: boolean;
|
|
23
|
+
/** Read by Android only. */
|
|
24
|
+
metaAppId?: string;
|
|
25
|
+
logLevel: KerdlyLogLevel;
|
|
26
|
+
wrapper: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Union of both platforms' purchase fields; each bridge reads its own. */
|
|
30
|
+
export interface NativePurchase {
|
|
31
|
+
originalTransactionId?: string;
|
|
32
|
+
transactionId?: string;
|
|
33
|
+
productId?: string;
|
|
34
|
+
appAccountToken?: string;
|
|
35
|
+
purchaseToken?: string;
|
|
36
|
+
orderId?: string;
|
|
37
|
+
products?: string[];
|
|
38
|
+
purchaseTime?: number;
|
|
39
|
+
obfuscatedAccountId?: string;
|
|
40
|
+
obfuscatedProfileId?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface NativeNetworkSend {
|
|
44
|
+
network: string;
|
|
45
|
+
event: string;
|
|
46
|
+
eventId?: string;
|
|
47
|
+
value?: number;
|
|
48
|
+
currency?: string;
|
|
49
|
+
flag?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface KerdlySdkNativeModule {
|
|
53
|
+
configure(options: NativeConfigureOptions): Promise<void>;
|
|
54
|
+
setUserId(userId: string | null): Promise<void>;
|
|
55
|
+
track(name: string, properties: Record<string, KerdlyEventValue>): Promise<void>;
|
|
56
|
+
// Standard events: the native signatures' arguments in their order, null = omitted.
|
|
57
|
+
trackRegistration(method: string | null, properties: Record<string, KerdlyEventValue>): Promise<void>;
|
|
58
|
+
trackStartTrial(
|
|
59
|
+
productId: string | null,
|
|
60
|
+
value: number | null,
|
|
61
|
+
currency: string | null,
|
|
62
|
+
transactionId: string | null,
|
|
63
|
+
properties: Record<string, KerdlyEventValue>
|
|
64
|
+
): Promise<void>;
|
|
65
|
+
trackSubscribe(
|
|
66
|
+
productId: string | null,
|
|
67
|
+
value: number | null,
|
|
68
|
+
currency: string | null,
|
|
69
|
+
transactionId: string | null,
|
|
70
|
+
properties: Record<string, KerdlyEventValue>
|
|
71
|
+
): Promise<void>;
|
|
72
|
+
trackPurchase(
|
|
73
|
+
productId: string | null,
|
|
74
|
+
value: number | null,
|
|
75
|
+
currency: string | null,
|
|
76
|
+
quantity: number | null,
|
|
77
|
+
transactionId: string | null,
|
|
78
|
+
properties: Record<string, KerdlyEventValue>
|
|
79
|
+
): Promise<void>;
|
|
80
|
+
setConsent(analytics: boolean | null, ads: boolean | null): Promise<void>;
|
|
81
|
+
handleUrl(url: string, source: KerdlyDeepLinkSource | null): Promise<unknown>;
|
|
82
|
+
setAppAccountToken(token: string | null): Promise<void>;
|
|
83
|
+
setPartnerIds(ids: Record<string, string>): Promise<void>;
|
|
84
|
+
notifyPurchase(purchase: NativePurchase | null): Promise<void>;
|
|
85
|
+
recordNetworkSend(send: NativeNetworkSend): Promise<void>;
|
|
86
|
+
getAttribution(): Promise<unknown>;
|
|
87
|
+
requestTrackingAuthorization(): Promise<unknown>;
|
|
88
|
+
flush(): Promise<void>;
|
|
89
|
+
getInstallId(): Promise<unknown>;
|
|
90
|
+
debugFetchDeferredLinks(tiktokAppId: string | null, storeAppId: string | null): Promise<unknown>;
|
|
91
|
+
addListener(eventName: typeof ATTRIBUTION_EVENT, listener: (payload: unknown) => void): {
|
|
92
|
+
remove(): void;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type NativeMethod = Exclude<keyof KerdlySdkNativeModule, 'addListener'>;
|
|
97
|
+
|
|
98
|
+
// undefined = not looked up yet; null = not available (Expo Go, web, app not rebuilt).
|
|
99
|
+
let cached: KerdlySdkNativeModule | null | undefined;
|
|
100
|
+
|
|
101
|
+
export function getNativeModule(): KerdlySdkNativeModule | null {
|
|
102
|
+
if (cached !== undefined) return cached;
|
|
103
|
+
try {
|
|
104
|
+
cached = requireOptionalNativeModule<KerdlySdkNativeModule>(NATIVE_MODULE_NAME) ?? null;
|
|
105
|
+
} catch {
|
|
106
|
+
cached = null;
|
|
107
|
+
}
|
|
108
|
+
if (cached === null) {
|
|
109
|
+
devWarnOnce(
|
|
110
|
+
'native-missing',
|
|
111
|
+
`The native module '${NATIVE_MODULE_NAME}' is not available, so every Kerdly call is a no-op. ` +
|
|
112
|
+
'Rebuild the native app after installing @kerdly/expo (npx expo prebuild, then ' +
|
|
113
|
+
'npx expo run:ios / run:android, or an EAS build). Expo Go and web do not include it.'
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return cached;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Calls a native function. Never throws and never rejects: a missing module or method, a
|
|
121
|
+
* synchronous throw and a rejected promise all resolve to `undefined` (with a development warning).
|
|
122
|
+
*/
|
|
123
|
+
export function callNative<M extends NativeMethod>(
|
|
124
|
+
method: M,
|
|
125
|
+
...args: Parameters<KerdlySdkNativeModule[M]>
|
|
126
|
+
): Promise<Awaited<ReturnType<KerdlySdkNativeModule[M]>> | undefined> {
|
|
127
|
+
const native = getNativeModule();
|
|
128
|
+
if (!native) return Promise.resolve(undefined);
|
|
129
|
+
try {
|
|
130
|
+
const fn = native[method] as unknown;
|
|
131
|
+
if (typeof fn !== 'function') {
|
|
132
|
+
devWarnOnce(
|
|
133
|
+
`native-method-${method}`,
|
|
134
|
+
`The native module '${NATIVE_MODULE_NAME}' has no function '${method}'. ` +
|
|
135
|
+
'The JS and native parts of @kerdly/expo are out of sync: rebuild the native app.'
|
|
136
|
+
);
|
|
137
|
+
return Promise.resolve(undefined);
|
|
138
|
+
}
|
|
139
|
+
const result = (fn as (...a: unknown[]) => unknown).apply(native, args);
|
|
140
|
+
return Promise.resolve(result as Awaited<ReturnType<KerdlySdkNativeModule[M]>>).catch(
|
|
141
|
+
(error: unknown) => {
|
|
142
|
+
devWarn(`Native ${method} failed:`, error);
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
devWarn(`Native ${method} threw:`, error);
|
|
148
|
+
return Promise.resolve(undefined);
|
|
149
|
+
}
|
|
150
|
+
}
|
package/src/normalize.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isPlainObject } from './validation';
|
|
2
|
+
import type { KerdlyAttribution, KerdlyDeepLink } from './types';
|
|
3
|
+
|
|
4
|
+
// The bridges send camelCase keys. snake_case (the protocol's JSON names) is accepted too, so a
|
|
5
|
+
// payload that is the collector's raw attribution object still normalises.
|
|
6
|
+
|
|
7
|
+
function str(source: Record<string, unknown>, camel: string, snake?: string): string | null {
|
|
8
|
+
const value = source[camel] ?? (snake === undefined ? undefined : source[snake]);
|
|
9
|
+
if (typeof value === 'string') return value;
|
|
10
|
+
if (typeof value === 'number' && Number.isFinite(value)) return String(value);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function millis(value: unknown): number | null {
|
|
15
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
16
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
17
|
+
const asNumber = Number(value);
|
|
18
|
+
if (Number.isFinite(asNumber)) return asNumber;
|
|
19
|
+
const parsed = Date.parse(value);
|
|
20
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function rawObject(value: unknown): Record<string, unknown> | null {
|
|
26
|
+
if (isPlainObject(value)) return value;
|
|
27
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
28
|
+
try {
|
|
29
|
+
const parsed: unknown = JSON.parse(value);
|
|
30
|
+
return isPlainObject(parsed) ? parsed : null;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function normalizeDeepLink(payload: unknown): KerdlyDeepLink | null {
|
|
39
|
+
if (!isPlainObject(payload)) return null;
|
|
40
|
+
const url = str(payload, 'url');
|
|
41
|
+
if (url === null) return null;
|
|
42
|
+
return {
|
|
43
|
+
url,
|
|
44
|
+
cpp: str(payload, 'cpp'),
|
|
45
|
+
ppid: str(payload, 'ppid'),
|
|
46
|
+
clickId: str(payload, 'clickId', 'kerdly_c'),
|
|
47
|
+
visitId: str(payload, 'visitId', 'kerdly_v'),
|
|
48
|
+
campaignIds: str(payload, 'campaignIds', 'campaign_ids'),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* iOS sends `raw` as an object, Android as the JSON string (Kotlin `KerdlyAttribution.raw: String`);
|
|
54
|
+
* both become an object here.
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeAttribution(payload: unknown): KerdlyAttribution | null {
|
|
57
|
+
if (!isPlainObject(payload)) return null;
|
|
58
|
+
const state = str(payload, 'state');
|
|
59
|
+
const network = str(payload, 'network');
|
|
60
|
+
const status = str(payload, 'status');
|
|
61
|
+
const method = str(payload, 'method');
|
|
62
|
+
if (state === null || network === null || status === null || method === null) return null;
|
|
63
|
+
const { raw: rawField, ...fields } = payload;
|
|
64
|
+
return {
|
|
65
|
+
state,
|
|
66
|
+
network,
|
|
67
|
+
status,
|
|
68
|
+
method,
|
|
69
|
+
campaignId: str(payload, 'campaignId', 'campaign_id'),
|
|
70
|
+
campaign: str(payload, 'campaign'),
|
|
71
|
+
adsetId: str(payload, 'adsetId', 'adset_id'),
|
|
72
|
+
adset: str(payload, 'adset'),
|
|
73
|
+
adId: str(payload, 'adId', 'ad_id'),
|
|
74
|
+
ad: str(payload, 'ad'),
|
|
75
|
+
keywordId: str(payload, 'keywordId', 'keyword_id'),
|
|
76
|
+
keyword: str(payload, 'keyword'),
|
|
77
|
+
linkId: str(payload, 'linkId', 'link_id'),
|
|
78
|
+
cppId: str(payload, 'cppId', 'cpp_id'),
|
|
79
|
+
decidedAt: millis(payload.decidedAt ?? payload.decided_at),
|
|
80
|
+
raw: rawObject(rawField) ?? fields,
|
|
81
|
+
};
|
|
82
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Public types of @kerdly/expo. The shapes mirror the Swift/Kotlin types of the native SDKs.
|
|
2
|
+
|
|
3
|
+
/** `auto` lets the native SDK decide */
|
|
4
|
+
export type KerdlyEnvironment = 'auto' | 'production' | 'sandbox' | 'development';
|
|
5
|
+
|
|
6
|
+
export type KerdlyLogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
7
|
+
|
|
8
|
+
/** App Tracking Transparency status. Android always reports `not_applicable`. */
|
|
9
|
+
export type KerdlyAttStatus =
|
|
10
|
+
| 'authorized'
|
|
11
|
+
| 'denied'
|
|
12
|
+
| 'restricted'
|
|
13
|
+
| 'not_determined'
|
|
14
|
+
| 'not_applicable';
|
|
15
|
+
|
|
16
|
+
/** Where a deep link came from: the URL that launched the app, or one received while running. */
|
|
17
|
+
export type KerdlyDeepLinkSource = 'initial' | 'runtime';
|
|
18
|
+
|
|
19
|
+
export interface KerdlyConfigureOptions {
|
|
20
|
+
/** The app's public key, `pk_live_…` or `pk_test_…`. */
|
|
21
|
+
key: string;
|
|
22
|
+
/** Base URL of the collector; `/v1/sdk/batch` etc. are appended by the native SDK. Default `https://app.kerdly.com/api`. */
|
|
23
|
+
endpoint?: string;
|
|
24
|
+
/** Default `auto`. */
|
|
25
|
+
environment?: KerdlyEnvironment;
|
|
26
|
+
/** Read IDFA (only when ATT is authorized) / GAID. Default `true`. */
|
|
27
|
+
collectAdvertisingId?: boolean;
|
|
28
|
+
/** iOS only: let the SDK write SKAdNetwork / AdAttributionKit conversion values. Default `false`. */
|
|
29
|
+
skanWriter?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Android only: the Facebook app id, which enables the Meta Install Referrer read. When omitted,
|
|
32
|
+
* the `com.kerdly.sdk.META_APP_ID` manifest meta-data (written by the config plugin's `metaAppId`)
|
|
33
|
+
* is used.
|
|
34
|
+
*/
|
|
35
|
+
metaAppId?: string;
|
|
36
|
+
/** Native SDK log level, and the threshold for this package's development warnings. Default `warn`. */
|
|
37
|
+
logLevel?: KerdlyLogLevel;
|
|
38
|
+
/**
|
|
39
|
+
* Forward React Native `Linking` URLs to `handleUrl` automatically: the initial URL once
|
|
40
|
+
* (source `initial`) and every `url` event (source `runtime`). Default `true`.
|
|
41
|
+
*/
|
|
42
|
+
autoDeepLinks?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What `handleUrl` parsed from a deep link's query string. */
|
|
46
|
+
export interface KerdlyDeepLink {
|
|
47
|
+
url: string;
|
|
48
|
+
cpp: string | null;
|
|
49
|
+
ppid: string | null;
|
|
50
|
+
/** The click id of the Kerdly link that opened the app (`kerdly_c`). */
|
|
51
|
+
clickId: string | null;
|
|
52
|
+
/** The web visit that link continues (`kerdly_v`). */
|
|
53
|
+
visitId: string | null;
|
|
54
|
+
campaignIds: string | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface KerdlyConsent {
|
|
58
|
+
analytics?: boolean;
|
|
59
|
+
ads?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Custom event property value. */
|
|
63
|
+
export type KerdlyEventValue = string | number | boolean;
|
|
64
|
+
|
|
65
|
+
/** Custom event properties. `undefined` values are skipped. */
|
|
66
|
+
export type KerdlyEventProperties = Record<string, KerdlyEventValue | undefined>;
|
|
67
|
+
|
|
68
|
+
/** `Kerdly.trackRegistration` (standard event `registration`). Every field is optional. */
|
|
69
|
+
export interface KerdlyRegistrationEvent {
|
|
70
|
+
/** How the user signed up: `anonymous`, `apple`, `google`, `email`, … (cut to 64 characters). */
|
|
71
|
+
method?: string | null;
|
|
72
|
+
/** Extra custom props, under the custom-event rules. */
|
|
73
|
+
properties?: KerdlyEventProperties;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* `Kerdly.trackStartTrial` and `Kerdly.trackSubscribe` (standard events `start_trial` and `subscribe`,
|
|
78
|
+
*Every field is optional.
|
|
79
|
+
*/
|
|
80
|
+
export interface KerdlyRevenueEvent {
|
|
81
|
+
/** The store product id (cut to 128 characters). */
|
|
82
|
+
productId?: string | null;
|
|
83
|
+
/** The price the user paid in `currency`: a finite number ≥ 0 (0 for a free trial). Dropped without a valid `currency`. */
|
|
84
|
+
value?: number | null;
|
|
85
|
+
/** ISO 4217 code, three letters; upper-cased. */
|
|
86
|
+
currency?: string | null;
|
|
87
|
+
/** The store transaction id (cut to 128 characters). */
|
|
88
|
+
transactionId?: string | null;
|
|
89
|
+
/** Extra custom props, under the custom-event rules. */
|
|
90
|
+
properties?: KerdlyEventProperties;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** `Kerdly.trackPurchase` (standard event `purchase`). Every field is optional. */
|
|
94
|
+
export interface KerdlyPurchaseEvent extends KerdlyRevenueEvent {
|
|
95
|
+
/** An integer ≥ 1. */
|
|
96
|
+
quantity?: number | null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** iOS (StoreKit) purchase, as reported by the paywall SDK. */
|
|
100
|
+
export interface KerdlyIosPurchase {
|
|
101
|
+
originalTransactionId?: string | null;
|
|
102
|
+
transactionId?: string | null;
|
|
103
|
+
productId?: string | null;
|
|
104
|
+
/** The StoreKit `appAccountToken` (a UUID string). */
|
|
105
|
+
appAccountToken?: string | null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Android (Play Billing) purchase. */
|
|
109
|
+
export interface KerdlyAndroidPurchase {
|
|
110
|
+
purchaseToken: string;
|
|
111
|
+
orderId?: string | null;
|
|
112
|
+
products?: string[];
|
|
113
|
+
/** Milliseconds since epoch. */
|
|
114
|
+
purchaseTime?: number | null;
|
|
115
|
+
obfuscatedAccountId?: string | null;
|
|
116
|
+
obfuscatedProfileId?: string | null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Either platform's purchase shape; each native SDK reads the fields of its own platform. */
|
|
120
|
+
export type KerdlyPurchase = KerdlyIosPurchase | KerdlyAndroidPurchase;
|
|
121
|
+
|
|
122
|
+
/** A conversion event the app sent to an ad network itself (Meta SDK, TikTok SDK, …). */
|
|
123
|
+
export interface KerdlyNetworkSend {
|
|
124
|
+
network: string;
|
|
125
|
+
event: string;
|
|
126
|
+
eventId?: string | null;
|
|
127
|
+
value?: number | null;
|
|
128
|
+
currency?: string | null;
|
|
129
|
+
flag?: string | null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The attribution object ofUnknown future values are passed through as strings. */
|
|
133
|
+
export interface KerdlyAttribution {
|
|
134
|
+
state: 'provisional' | 'final' | (string & {});
|
|
135
|
+
network:
|
|
136
|
+
| 'apple_ads'
|
|
137
|
+
| 'meta'
|
|
138
|
+
| 'tiktok'
|
|
139
|
+
| 'google_ads'
|
|
140
|
+
| 'reddit'
|
|
141
|
+
| 'snap'
|
|
142
|
+
| 'web'
|
|
143
|
+
| 'organic'
|
|
144
|
+
| 'unknown'
|
|
145
|
+
| (string & {});
|
|
146
|
+
status:
|
|
147
|
+
| 'measured'
|
|
148
|
+
| 'probabilistic'
|
|
149
|
+
| 'view_through'
|
|
150
|
+
| 'organic_measured'
|
|
151
|
+
| 'organic_assumed'
|
|
152
|
+
| (string & {});
|
|
153
|
+
method:
|
|
154
|
+
| 'asa_token'
|
|
155
|
+
| 'play_referrer'
|
|
156
|
+
| 'play_referrer_link'
|
|
157
|
+
| 'meta_install_referrer'
|
|
158
|
+
| 'cpp_deeplink'
|
|
159
|
+
| 'visit_chain'
|
|
160
|
+
| 'ip_match'
|
|
161
|
+
| 'none'
|
|
162
|
+
| (string & {});
|
|
163
|
+
campaignId: string | null;
|
|
164
|
+
campaign: string | null;
|
|
165
|
+
adsetId: string | null;
|
|
166
|
+
adset: string | null;
|
|
167
|
+
adId: string | null;
|
|
168
|
+
ad: string | null;
|
|
169
|
+
keywordId: string | null;
|
|
170
|
+
keyword: string | null;
|
|
171
|
+
linkId: string | null;
|
|
172
|
+
cppId: string | null;
|
|
173
|
+
/** Milliseconds since epoch. */
|
|
174
|
+
decidedAt: number | null;
|
|
175
|
+
/** The whole attribution JSON object as the collector sent it. */
|
|
176
|
+
raw: Record<string, unknown>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type KerdlyAttributionListener = (attribution: KerdlyAttribution) => void;
|
|
180
|
+
|
|
181
|
+
export interface KerdlySubscription {
|
|
182
|
+
remove(): void;
|
|
183
|
+
}
|