@ondropp/dropplink-react-native 0.0.0-stage → 0.2.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.
- package/README.md +333 -2
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/app/ondropp/dropplink/reactnative/RNDropplinkModule.kt +158 -0
- package/android/src/main/java/app/ondropp/dropplink/reactnative/RNDropplinkPackage.kt +27 -0
- package/dropplink-react-native.podspec +28 -0
- package/ios/RNDropplink.m +40 -0
- package/ios/RNDropplink.swift +159 -0
- package/lib/module/Dropplink.js +163 -0
- package/lib/module/Dropplink.js.map +1 -0
- package/lib/module/NativeDropplink.js +17 -0
- package/lib/module/NativeDropplink.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useDropplinkDeepLink.js +19 -0
- package/lib/module/useDropplinkDeepLink.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Dropplink.d.ts +58 -0
- package/lib/typescript/src/Dropplink.d.ts.map +1 -0
- package/lib/typescript/src/NativeDropplink.d.ts +40 -0
- package/lib/typescript/src/NativeDropplink.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +62 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/useDropplinkDeepLink.d.ts +7 -0
- package/lib/typescript/src/useDropplinkDeepLink.d.ts.map +1 -0
- package/package.json +119 -4
- package/src/Dropplink.ts +202 -0
- package/src/NativeDropplink.ts +48 -0
- package/src/index.ts +12 -0
- package/src/types.ts +66 -0
- package/src/useDropplinkDeepLink.ts +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,121 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ondropp/dropplink-react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Dropplink install attribution and deep links for React Native. A thin bridge over the native Android and iOS SDKs.",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"ondropp-dropplink-react-native-source": "./src/index.ts",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"*.podspec",
|
|
21
|
+
"!ios/build",
|
|
22
|
+
"!android/build",
|
|
23
|
+
"!android/gradle",
|
|
24
|
+
"!android/gradlew",
|
|
25
|
+
"!android/gradlew.bat",
|
|
26
|
+
"!android/local.properties",
|
|
27
|
+
"!**/__tests__",
|
|
28
|
+
"!**/__fixtures__",
|
|
29
|
+
"!**/__mocks__",
|
|
30
|
+
"!**/.*"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"prepare": "bob build",
|
|
34
|
+
"typecheck": "tsc",
|
|
35
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"clean": "rm -rf lib android/build"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"react-native",
|
|
41
|
+
"ios",
|
|
42
|
+
"android",
|
|
43
|
+
"attribution",
|
|
44
|
+
"deep-link",
|
|
45
|
+
"deferred-deep-link",
|
|
46
|
+
"dropplink"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/ondropp/dropplink-sdks.git",
|
|
51
|
+
"directory": "react-native"
|
|
52
|
+
},
|
|
53
|
+
"author": "Dropplink",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"homepage": "https://github.com/ondropp/dropplink-sdks/tree/main/react-native#readme",
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"registry": "https://registry.npmjs.org/",
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@eslint/compat": "^2.1.0",
|
|
62
|
+
"@eslint/eslintrc": "^3.3.6",
|
|
63
|
+
"@eslint/js": "^9.39.5",
|
|
64
|
+
"@react-native/babel-preset": "0.86.2",
|
|
65
|
+
"@react-native/eslint-config": "0.86.2",
|
|
66
|
+
"@types/jest": "^30.0.0",
|
|
67
|
+
"@types/react": "^19.2.0",
|
|
68
|
+
"eslint": "^9.39.5",
|
|
69
|
+
"eslint-config-prettier": "^10.1.8",
|
|
70
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
71
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
72
|
+
"jest": "^30.5.0",
|
|
73
|
+
"prettier": "^3.9.6",
|
|
74
|
+
"react": "19.2.3",
|
|
75
|
+
"react-native": "0.86.2",
|
|
76
|
+
"react-native-builder-bob": "^0.43.0",
|
|
77
|
+
"typescript": "^6.0.3"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"react": "*",
|
|
81
|
+
"react-native": ">=0.76.0"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">= 22.11.0"
|
|
85
|
+
},
|
|
86
|
+
"react-native-builder-bob": {
|
|
87
|
+
"source": "src",
|
|
88
|
+
"output": "lib",
|
|
89
|
+
"targets": [
|
|
90
|
+
[
|
|
91
|
+
"module",
|
|
92
|
+
{
|
|
93
|
+
"esm": true
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
"typescript",
|
|
98
|
+
{
|
|
99
|
+
"project": "tsconfig.build.json"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"jest": {
|
|
105
|
+
"testEnvironment": "node",
|
|
106
|
+
"roots": [
|
|
107
|
+
"<rootDir>/src"
|
|
108
|
+
],
|
|
109
|
+
"modulePathIgnorePatterns": [
|
|
110
|
+
"<rootDir>/lib/",
|
|
111
|
+
"<rootDir>/example/"
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"prettier": {
|
|
115
|
+
"quoteProps": "consistent",
|
|
116
|
+
"singleQuote": true,
|
|
117
|
+
"tabWidth": 2,
|
|
118
|
+
"trailingComma": "es5",
|
|
119
|
+
"useTabs": false
|
|
120
|
+
}
|
|
121
|
+
}
|
package/src/Dropplink.ts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Linking, NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
+
import NativeDropplink, { DEEP_LINK_EVENT, type Spec } from './NativeDropplink';
|
|
3
|
+
import type {
|
|
4
|
+
Attribution,
|
|
5
|
+
DeepLink,
|
|
6
|
+
DeepLinkListener,
|
|
7
|
+
DropplinkConfig,
|
|
8
|
+
EventProps,
|
|
9
|
+
IdentifyTraits,
|
|
10
|
+
Revenue,
|
|
11
|
+
Subscription,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
const LINKING_ERROR =
|
|
15
|
+
`'@ondropp/dropplink-react-native' doesn't seem to be linked. Make sure:\n\n` +
|
|
16
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
17
|
+
'- You rebuilt the app after installing the package\n' +
|
|
18
|
+
'- You are not using Expo Go (use a development build)\n';
|
|
19
|
+
|
|
20
|
+
function native(): Spec {
|
|
21
|
+
if (!NativeDropplink) throw new Error(LINKING_ERROR);
|
|
22
|
+
return NativeDropplink;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Events and users must never throw into the host app (docs/sdk-spec.md section 2), not even when
|
|
26
|
+
// the module isn't linked: warn once in development and drop the call.
|
|
27
|
+
let warnedUnavailable = false;
|
|
28
|
+
function safely(call: (module: Spec) => void): void {
|
|
29
|
+
try {
|
|
30
|
+
call(native());
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (!warnedUnavailable && typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
33
|
+
warnedUnavailable = true;
|
|
34
|
+
console.warn('Dropplink:', e instanceof Error ? e.message : e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let emitter: NativeEventEmitter | undefined;
|
|
40
|
+
let listenerCount = 0;
|
|
41
|
+
let initialUrlHandled = false;
|
|
42
|
+
|
|
43
|
+
// Native maps cross the bridge with nulls for absent fields; normalise them to the TS types.
|
|
44
|
+
|
|
45
|
+
function toDeepLink(raw: Record<string, unknown>): DeepLink {
|
|
46
|
+
return {
|
|
47
|
+
path: String(raw.path ?? '/'),
|
|
48
|
+
params: (raw.params as Record<string, string> | null) ?? {},
|
|
49
|
+
url: (raw.url as string | null | undefined) ?? null,
|
|
50
|
+
isDeferred: raw.isDeferred === true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function toAttribution(raw: Object | null): Attribution | null {
|
|
55
|
+
if (raw == null) return null;
|
|
56
|
+
const out: Record<string, unknown> = {};
|
|
57
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
58
|
+
if (value != null) out[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return out as Attribution;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const Dropplink = {
|
|
64
|
+
/**
|
|
65
|
+
* Starts the SDK. Call once, as early as possible (top of `index.js`). Later calls are ignored
|
|
66
|
+
* by the native SDK, as are calls after a native `Dropplink.initialize` in MainApplication /
|
|
67
|
+
* AppDelegate.
|
|
68
|
+
*/
|
|
69
|
+
initialize(config: DropplinkConfig): Promise<void> {
|
|
70
|
+
return native().initializeSdk({
|
|
71
|
+
keyId: config.keyId,
|
|
72
|
+
secret: config.secret,
|
|
73
|
+
debug: config.debug ?? false,
|
|
74
|
+
baseUrl: config.baseUrl ?? null,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Receives every deep link: the deferred one after a fresh install and App Link / Universal
|
|
80
|
+
* Link opens. The native SDK holds a link that arrives before the first listener is added and
|
|
81
|
+
* delivers it then.
|
|
82
|
+
*/
|
|
83
|
+
addDeepLinkListener(listener: DeepLinkListener): Subscription {
|
|
84
|
+
const module = native();
|
|
85
|
+
emitter ??= new NativeEventEmitter(module);
|
|
86
|
+
const sub = emitter.addListener(DEEP_LINK_EVENT, (raw) =>
|
|
87
|
+
listener(toDeepLink(raw as Record<string, unknown>))
|
|
88
|
+
);
|
|
89
|
+
if (listenerCount++ === 0) module.setDeepLinkListenerEnabled(true);
|
|
90
|
+
|
|
91
|
+
let removed = false;
|
|
92
|
+
return {
|
|
93
|
+
remove() {
|
|
94
|
+
if (removed) return;
|
|
95
|
+
removed = true;
|
|
96
|
+
sub.remove();
|
|
97
|
+
if (--listenerCount === 0) module.setDeepLinkListenerEnabled(false);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Reports an App Link / Universal Link the OS opened the app with. The result arrives on the
|
|
104
|
+
* deep-link listener. Non-http(s) URLs are ignored natively.
|
|
105
|
+
*/
|
|
106
|
+
handleDeepLink(url: string): Promise<void> {
|
|
107
|
+
return native().handleDeepLink(url);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/** The last attribution the server returned, or `null` before the first successful init. */
|
|
111
|
+
async getAttribution(): Promise<Attribution | null> {
|
|
112
|
+
return toAttribution(await native().getAttribution());
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/** This install's id, for the dashboard's Install debugger. */
|
|
116
|
+
async getInstallId(): Promise<string | null> {
|
|
117
|
+
return (await native().getInstallId()) ?? null;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Forwards React Native `Linking` URLs (the launch URL and every later `url` event) to
|
|
122
|
+
* `handleDeepLink`, so App Links / Universal Links work with one call. Returns an unsubscribe
|
|
123
|
+
* function. The launch URL is forwarded once per JS context, however often this is called.
|
|
124
|
+
*/
|
|
125
|
+
listenToLinking(): () => void {
|
|
126
|
+
const forward = (url: string | null | undefined) => {
|
|
127
|
+
if (url) Dropplink.handleDeepLink(url).catch(() => {});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// The launch URL is a one-off for this JS context, not tied to the subscription: forward it
|
|
131
|
+
// even if unsubscribed meanwhile (e.g. a StrictMode mount/unmount/mount).
|
|
132
|
+
if (!initialUrlHandled) {
|
|
133
|
+
initialUrlHandled = true;
|
|
134
|
+
Linking.getInitialURL()
|
|
135
|
+
.then(forward)
|
|
136
|
+
.catch(() => {});
|
|
137
|
+
}
|
|
138
|
+
const sub = Linking.addEventListener('url', ({ url }) => forward(url));
|
|
139
|
+
return () => sub.remove();
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Records an in-app event, e.g. `track('add_to_cart', { props: { sku: 'A1' } })`. The native SDK
|
|
144
|
+
* validates it (invalid events are dropped with a debug log), queues it on disk and sends it in
|
|
145
|
+
* the background. Never throws.
|
|
146
|
+
*/
|
|
147
|
+
track(
|
|
148
|
+
name: string,
|
|
149
|
+
options?: { props?: EventProps; revenue?: Revenue }
|
|
150
|
+
): void {
|
|
151
|
+
const revenue = options?.revenue;
|
|
152
|
+
safely((m) =>
|
|
153
|
+
m.track(
|
|
154
|
+
name,
|
|
155
|
+
options?.props ?? null,
|
|
156
|
+
revenue
|
|
157
|
+
? {
|
|
158
|
+
amount: revenue.amount,
|
|
159
|
+
currency: revenue.currency,
|
|
160
|
+
orderId: revenue.orderId ?? null,
|
|
161
|
+
}
|
|
162
|
+
: null
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Links the brand's own user id to this install. Call after sign-up / login; calling again with
|
|
169
|
+
* the same id is a no-op natively, so calling it on every launch is fine. `email` and `phone`
|
|
170
|
+
* are hashed on the device. Never throws.
|
|
171
|
+
*/
|
|
172
|
+
identify(userId: string, traits?: IdentifyTraits): void {
|
|
173
|
+
safely((m) =>
|
|
174
|
+
m.identify(userId, traits?.email ?? null, traits?.phone ?? null)
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/** Unlinks the user; later events carry no user. Never throws. */
|
|
179
|
+
logout(): void {
|
|
180
|
+
safely((m) => m.logout());
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* `false` clears the native event queue and stops events and identify until set back to `true`
|
|
185
|
+
* (for consent). Persisted natively across launches. Attribution and deep links keep working.
|
|
186
|
+
*/
|
|
187
|
+
setTrackingEnabled(enabled: boolean): void {
|
|
188
|
+
safely((m) => m.setTrackingEnabled(enabled));
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The current setting (default `true`). Resolves `false` if the native module isn't linked or
|
|
193
|
+
* fails, since nothing is tracked then. Never rejects.
|
|
194
|
+
*/
|
|
195
|
+
async isTrackingEnabled(): Promise<boolean> {
|
|
196
|
+
try {
|
|
197
|
+
return (await native().isTrackingEnabled()) === true;
|
|
198
|
+
} catch {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The native module's interface. Implemented by `RNDropplinkModule` (Kotlin) and `RNDropplink`
|
|
5
|
+
* (Swift) as classic native modules, which RN 0.76+ serves through the TurboModule interop layer.
|
|
6
|
+
* See README "Architecture".
|
|
7
|
+
*/
|
|
8
|
+
export interface Spec extends TurboModule {
|
|
9
|
+
/** `baseUrl: null` lets the native SDK apply its default. `platformWrapper` is set natively. */
|
|
10
|
+
initializeSdk(config: {
|
|
11
|
+
keyId: string;
|
|
12
|
+
secret: string;
|
|
13
|
+
debug: boolean;
|
|
14
|
+
baseUrl: string | null;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
handleDeepLink(url: string): Promise<void>;
|
|
17
|
+
getAttribution(): Promise<Object | null>;
|
|
18
|
+
getInstallId(): Promise<string | null>;
|
|
19
|
+
/**
|
|
20
|
+
* `true` installs the native deep-link listener (delivering any link the native SDK buffered),
|
|
21
|
+
* `false` removes it so the native SDK buffers again.
|
|
22
|
+
*/
|
|
23
|
+
setDeepLinkListenerEnabled(enabled: boolean): void;
|
|
24
|
+
|
|
25
|
+
// Events and users (docs/sdk-spec.md section 11). Fire-and-forget: the native SDK validates,
|
|
26
|
+
// queues and sends. `null` stands for an omitted optional argument.
|
|
27
|
+
/** `props` values keep their JS type (string, number, boolean, null); native drops the rest. */
|
|
28
|
+
track(
|
|
29
|
+
name: string,
|
|
30
|
+
props: Object | null,
|
|
31
|
+
revenue: { amount: number; currency: string; orderId: string | null } | null
|
|
32
|
+
): void;
|
|
33
|
+
identify(userId: string, email: string | null, phone: string | null): void;
|
|
34
|
+
logout(): void;
|
|
35
|
+
setTrackingEnabled(enabled: boolean): void;
|
|
36
|
+
isTrackingEnabled(): Promise<boolean>;
|
|
37
|
+
|
|
38
|
+
// Required by NativeEventEmitter.
|
|
39
|
+
addListener(eventName: string): void;
|
|
40
|
+
removeListeners(count: number): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const MODULE_NAME = 'RNDropplink';
|
|
44
|
+
export const DEEP_LINK_EVENT = 'DropplinkDeepLink';
|
|
45
|
+
|
|
46
|
+
// `get` (not `getEnforcing`) so importing the package never throws, e.g. in Jest or on web.
|
|
47
|
+
// TurboModuleRegistry falls back to NativeModules and the interop layer by itself.
|
|
48
|
+
export default TurboModuleRegistry.get<Spec>(MODULE_NAME);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Dropplink } from './Dropplink';
|
|
2
|
+
export { useDropplinkDeepLink } from './useDropplinkDeepLink';
|
|
3
|
+
export type {
|
|
4
|
+
Attribution,
|
|
5
|
+
DeepLink,
|
|
6
|
+
DeepLinkListener,
|
|
7
|
+
DropplinkConfig,
|
|
8
|
+
EventProps,
|
|
9
|
+
IdentifyTraits,
|
|
10
|
+
Revenue,
|
|
11
|
+
Subscription,
|
|
12
|
+
} from './types';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Options for {@link Dropplink.initialize}. See docs/sdk-spec.md section 2. */
|
|
2
|
+
export type DropplinkConfig = {
|
|
3
|
+
/** `ak_…` SDK key id for this platform, from the Dropplink dashboard. */
|
|
4
|
+
keyId: string;
|
|
5
|
+
/** The key's secret. Load it from build config; never commit it. */
|
|
6
|
+
secret: string;
|
|
7
|
+
/** Turns on native logging (tag `Dropplink`). Never ship `true`. Default `false`. */
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
/** Defaults to `https://attribution.ondropp.app` (the native SDK's default). */
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A resolved deep link: the deferred one after a fresh install (`isDeferred: true`, `url: null`)
|
|
15
|
+
* or an App Link / Universal Link open (`isDeferred: false`, `url` set).
|
|
16
|
+
*/
|
|
17
|
+
export type DeepLink = {
|
|
18
|
+
path: string;
|
|
19
|
+
params: Record<string, string>;
|
|
20
|
+
url: string | null;
|
|
21
|
+
isDeferred: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** The last attribution the server returned. */
|
|
25
|
+
export type Attribution = {
|
|
26
|
+
type: 'attributed' | 'organic';
|
|
27
|
+
method: 'install_referrer' | 'fingerprint' | 'none';
|
|
28
|
+
clickId?: string;
|
|
29
|
+
linkId?: string;
|
|
30
|
+
campaignId?: string;
|
|
31
|
+
creatorId?: string;
|
|
32
|
+
source?: string;
|
|
33
|
+
confidence?: number;
|
|
34
|
+
/** ISO 8601 timestamp. */
|
|
35
|
+
attributedAt?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type DeepLinkListener = (link: DeepLink) => void;
|
|
39
|
+
|
|
40
|
+
export type Subscription = { remove(): void };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Properties for {@link Dropplink.track}. At most 20; keys `^[A-Za-z0-9_]{1,40}$`. The native SDK
|
|
44
|
+
* drops invalid keys and values (and anything that looks like an email or phone number).
|
|
45
|
+
*/
|
|
46
|
+
export type EventProps = Record<string, string | number | boolean | null>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Revenue the app reports with an event, shown as app-reported in the dashboard. Purchases that pay
|
|
50
|
+
* creators should come from the brand's server (`/v1/s2s/events`) instead.
|
|
51
|
+
*/
|
|
52
|
+
export type Revenue = {
|
|
53
|
+
/** Finite and >= 0; rounded to 2 decimals natively. */
|
|
54
|
+
amount: number;
|
|
55
|
+
/** ISO 4217 code, e.g. `INR`. */
|
|
56
|
+
currency: string;
|
|
57
|
+
/** 1–128 chars. */
|
|
58
|
+
orderId?: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Optional traits for {@link Dropplink.identify}. Hashed (SHA-256) on the device before sending. */
|
|
62
|
+
export type IdentifyTraits = {
|
|
63
|
+
email?: string;
|
|
64
|
+
/** E.164, e.g. `+919812345678`. */
|
|
65
|
+
phone?: string;
|
|
66
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { Dropplink } from './Dropplink';
|
|
3
|
+
import type { DeepLinkListener } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calls `handler` for every Dropplink deep link while the component is mounted. The latest
|
|
7
|
+
* `handler` is always used, so it doesn't need to be memoised.
|
|
8
|
+
*/
|
|
9
|
+
export function useDropplinkDeepLink(handler: DeepLinkListener): void {
|
|
10
|
+
const ref = useRef(handler);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
ref.current = handler;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const sub = Dropplink.addDeepLinkListener((link) => ref.current(link));
|
|
17
|
+
return () => sub.remove();
|
|
18
|
+
}, []);
|
|
19
|
+
}
|