@appfunnel-dev/sdk 2.0.0-canary.3 → 2.0.0-canary.4
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/dist/index.cjs +37 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +37 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -113,8 +113,16 @@ interface FunnelEventDataMap {
|
|
|
113
113
|
priceId?: string;
|
|
114
114
|
productName?: string;
|
|
115
115
|
surface?: string;
|
|
116
|
+
amount?: number;
|
|
117
|
+
currency?: string;
|
|
118
|
+
eventId?: string;
|
|
119
|
+
};
|
|
120
|
+
'checkout.payment_added': {
|
|
121
|
+
productId?: string;
|
|
122
|
+
amount?: number;
|
|
123
|
+
currency?: string;
|
|
124
|
+
eventId?: string;
|
|
116
125
|
};
|
|
117
|
-
'checkout.payment_added': Record<string, never>;
|
|
118
126
|
'checkout.failed': {
|
|
119
127
|
category: string;
|
|
120
128
|
declineCode?: string;
|
|
@@ -126,6 +134,13 @@ interface FunnelEventDataMap {
|
|
|
126
134
|
currency?: string;
|
|
127
135
|
email?: string;
|
|
128
136
|
eventId?: string;
|
|
137
|
+
productId?: string;
|
|
138
|
+
};
|
|
139
|
+
'subscription.created': {
|
|
140
|
+
amount?: number;
|
|
141
|
+
currency?: string;
|
|
142
|
+
productId?: string;
|
|
143
|
+
eventId?: string;
|
|
129
144
|
};
|
|
130
145
|
'experiment.exposure': {
|
|
131
146
|
experimentId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -113,8 +113,16 @@ interface FunnelEventDataMap {
|
|
|
113
113
|
priceId?: string;
|
|
114
114
|
productName?: string;
|
|
115
115
|
surface?: string;
|
|
116
|
+
amount?: number;
|
|
117
|
+
currency?: string;
|
|
118
|
+
eventId?: string;
|
|
119
|
+
};
|
|
120
|
+
'checkout.payment_added': {
|
|
121
|
+
productId?: string;
|
|
122
|
+
amount?: number;
|
|
123
|
+
currency?: string;
|
|
124
|
+
eventId?: string;
|
|
116
125
|
};
|
|
117
|
-
'checkout.payment_added': Record<string, never>;
|
|
118
126
|
'checkout.failed': {
|
|
119
127
|
category: string;
|
|
120
128
|
declineCode?: string;
|
|
@@ -126,6 +134,13 @@ interface FunnelEventDataMap {
|
|
|
126
134
|
currency?: string;
|
|
127
135
|
email?: string;
|
|
128
136
|
eventId?: string;
|
|
137
|
+
productId?: string;
|
|
138
|
+
};
|
|
139
|
+
'subscription.created': {
|
|
140
|
+
amount?: number;
|
|
141
|
+
currency?: string;
|
|
142
|
+
productId?: string;
|
|
143
|
+
eventId?: string;
|
|
129
144
|
};
|
|
130
145
|
'experiment.exposure': {
|
|
131
146
|
experimentId: string;
|
package/dist/index.js
CHANGED
|
@@ -1120,12 +1120,25 @@ var FALLBACK_DRIVER = createMockDriver();
|
|
|
1120
1120
|
function useCheckout(opts = {}) {
|
|
1121
1121
|
const driver = useDriver();
|
|
1122
1122
|
const tracker = useTrackerRef();
|
|
1123
|
+
const catalog = useCatalog();
|
|
1123
1124
|
const nav = useNavigation();
|
|
1124
1125
|
const [status, setStatus] = useState("idle");
|
|
1125
1126
|
const [error, setError] = useState(null);
|
|
1126
1127
|
const intent = opts.intent ?? "purchase";
|
|
1127
1128
|
const kind = opts.kind;
|
|
1128
1129
|
const advance = opts.advanceOnSuccess ?? true;
|
|
1130
|
+
const productFacts = useCallback(
|
|
1131
|
+
(product) => {
|
|
1132
|
+
const resolved = product ? catalog.get(product) : void 0;
|
|
1133
|
+
return {
|
|
1134
|
+
productId: resolved?.catalogKey ?? product,
|
|
1135
|
+
amount: resolved ? resolved.priceMinor / 100 : void 0,
|
|
1136
|
+
currency: resolved?.currency,
|
|
1137
|
+
isSubscription: resolved ? resolved.period !== "one-time" : kind === "subscription" || kind === "upgrade"
|
|
1138
|
+
};
|
|
1139
|
+
},
|
|
1140
|
+
[catalog, kind]
|
|
1141
|
+
);
|
|
1129
1142
|
const recovering = useRef(false);
|
|
1130
1143
|
const failRef = useRef(() => {
|
|
1131
1144
|
});
|
|
@@ -1133,18 +1146,24 @@ function useCheckout(opts = {}) {
|
|
|
1133
1146
|
async () => ({ ok: false })
|
|
1134
1147
|
);
|
|
1135
1148
|
const succeed = useCallback(
|
|
1136
|
-
(result) => {
|
|
1149
|
+
(result, product) => {
|
|
1137
1150
|
setStatus("success");
|
|
1151
|
+
const { productId, isSubscription } = productFacts(product);
|
|
1152
|
+
const amount = result.amountMinor != null ? result.amountMinor / 100 : void 0;
|
|
1138
1153
|
tracker.track("purchase.complete", {
|
|
1139
|
-
amount
|
|
1154
|
+
amount,
|
|
1140
1155
|
currency: result.currency,
|
|
1156
|
+
productId,
|
|
1141
1157
|
eventId: result.eventId
|
|
1142
1158
|
// server-minted (browser↔CAPI dedup); undefined if none
|
|
1143
1159
|
});
|
|
1160
|
+
if (isSubscription) {
|
|
1161
|
+
tracker.track("subscription.created", { amount, currency: result.currency, productId, eventId: result.eventId });
|
|
1162
|
+
}
|
|
1144
1163
|
opts.onSuccess?.(result);
|
|
1145
1164
|
if (advance) nav.next();
|
|
1146
1165
|
},
|
|
1147
|
-
[tracker, nav, advance, opts]
|
|
1166
|
+
[tracker, nav, advance, opts, productFacts]
|
|
1148
1167
|
);
|
|
1149
1168
|
const succeedRef = useRef(succeed);
|
|
1150
1169
|
succeedRef.current = succeed;
|
|
@@ -1152,11 +1171,18 @@ function useCheckout(opts = {}) {
|
|
|
1152
1171
|
(product, surface) => {
|
|
1153
1172
|
setStatus("loading");
|
|
1154
1173
|
setError(null);
|
|
1155
|
-
|
|
1174
|
+
const { productId, amount, currency } = productFacts(product);
|
|
1175
|
+
tracker.track("checkout.start", { productId, amount, currency, surface, eventId: newEventId() });
|
|
1156
1176
|
},
|
|
1157
|
-
[tracker]
|
|
1177
|
+
[tracker, productFacts]
|
|
1178
|
+
);
|
|
1179
|
+
const paymentAdded = useCallback(
|
|
1180
|
+
(product) => {
|
|
1181
|
+
const { productId, amount, currency } = productFacts(product);
|
|
1182
|
+
tracker.track("checkout.payment_added", { productId, amount, currency, eventId: newEventId() });
|
|
1183
|
+
},
|
|
1184
|
+
[tracker, productFacts]
|
|
1158
1185
|
);
|
|
1159
|
-
const paymentAdded = useCallback(() => tracker.track("checkout.payment_added", {}), [tracker]);
|
|
1160
1186
|
const hostInSheet = (surface) => surface === "sheet" || isInlineSurface(surface) && !!PROVIDER_PROFILES[driver.provider]?.surfaces.sheet;
|
|
1161
1187
|
const startRecovery = (product, surface) => {
|
|
1162
1188
|
recovering.current = true;
|
|
@@ -1167,9 +1193,9 @@ function useCheckout(opts = {}) {
|
|
|
1167
1193
|
surface: "sheet",
|
|
1168
1194
|
intent,
|
|
1169
1195
|
kind,
|
|
1170
|
-
onSuccess: (r) => succeedRef.current(r),
|
|
1196
|
+
onSuccess: (r) => succeedRef.current(r, product),
|
|
1171
1197
|
onError: (e) => failRef.current(e, product),
|
|
1172
|
-
onPaymentAdded: () => paymentAdded()
|
|
1198
|
+
onPaymentAdded: () => paymentAdded(product)
|
|
1173
1199
|
});
|
|
1174
1200
|
} else {
|
|
1175
1201
|
void attemptRef.current(product, surface);
|
|
@@ -1223,7 +1249,7 @@ function useCheckout(opts = {}) {
|
|
|
1223
1249
|
begin(product, surface);
|
|
1224
1250
|
try {
|
|
1225
1251
|
const result = await driver.start({ product, intent, surface, kind });
|
|
1226
|
-
if (result.ok) succeedRef.current(result);
|
|
1252
|
+
if (result.ok) succeedRef.current(result, product);
|
|
1227
1253
|
else failRef.current(result.error ?? checkoutError("unknown", "Checkout failed"), product);
|
|
1228
1254
|
return result;
|
|
1229
1255
|
} catch (e) {
|
|
@@ -1242,9 +1268,9 @@ function useCheckout(opts = {}) {
|
|
|
1242
1268
|
recovering.current = false;
|
|
1243
1269
|
begin(product, surface);
|
|
1244
1270
|
},
|
|
1245
|
-
onSuccess: (result) => succeedRef.current(result),
|
|
1271
|
+
onSuccess: (result) => succeedRef.current(result, product),
|
|
1246
1272
|
onError: (err) => failRef.current(err, product),
|
|
1247
|
-
onPaymentAdded: () => paymentAdded()
|
|
1273
|
+
onPaymentAdded: () => paymentAdded(product)
|
|
1248
1274
|
}),
|
|
1249
1275
|
[begin, paymentAdded]
|
|
1250
1276
|
);
|