hosted: track successful subscription checkout (#92)
This commit is contained in:
parent
a10f4d82a0
commit
d2fc85342a
@ -29,6 +29,9 @@ function SubscribePageContent() {
|
|||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const [isAttaching, setIsAttaching] = useState(false);
|
const [isAttaching, setIsAttaching] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const checkoutCompleted =
|
||||||
|
typeof window !== "undefined" &&
|
||||||
|
new URLSearchParams(window.location.search).get("checkout") === "success";
|
||||||
|
|
||||||
const customerQuery = useCustomer({
|
const customerQuery = useCustomer({
|
||||||
queryOptions: {
|
queryOptions: {
|
||||||
@ -48,9 +51,12 @@ function SubscribePageContent() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (subscribeRouteState === "redirectToApp") {
|
if (subscribeRouteState === "redirectToApp") {
|
||||||
|
if (checkoutCompleted) {
|
||||||
|
captureClientEvent("billing:checkout_success");
|
||||||
|
}
|
||||||
void navigate({ to: "/", replace: true });
|
void navigate({ to: "/", replace: true });
|
||||||
}
|
}
|
||||||
}, [navigate, subscribeRouteState]);
|
}, [checkoutCompleted, navigate, subscribeRouteState]);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
subscribeRouteState === "loading" ||
|
subscribeRouteState === "loading" ||
|
||||||
@ -100,7 +106,7 @@ function SubscribePageContent() {
|
|||||||
await customerQuery.attach({
|
await customerQuery.attach({
|
||||||
planId: AUTUMN_PAID_PLAN_ID,
|
planId: AUTUMN_PAID_PLAN_ID,
|
||||||
redirectMode: "always",
|
redirectMode: "always",
|
||||||
successUrl: window.location.origin,
|
successUrl: `${window.location.origin}${window.location.pathname}?checkout=success`,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(
|
setError(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user