The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix success_url
Steven Tey44c0dcc022ca
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.tsindex efe3894219..6cb46b8777 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts@@ -57,7 +57,7 @@ export const POST = withWorkspace(async ({ req, workspace, session }) => {const stripeSession = await stripe.checkout.sessions.create({customer_email: session.user.email,billing_address_collection: "required",- success_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing?success=true`,+ success_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing?success=true&plan=${plan}&period=${period}`,cancel_url: `${baseUrl}?upgrade=${plan}`,line_items: [{ price: prices.data[0].id, quantity: 1 }],automatic_tax: {diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsxindex 66b66d3d4a..d5bead1ce5 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx@@ -20,7 +20,6 @@ import posthog from "posthog-js";import { useEffect, useMemo, useState } from "react";import Confetti from "react-dom-confetti";import { toast } from "sonner";-import { mutate } from "swr";export default function WorkspaceBillingClient() {const router = useRouter();@@ -70,29 +69,38 @@ export default function WorkspaceBillingClient() {useEffect(() => {if (searchParams?.get("success")) {- toast.success("Upgrade success!");setConfetti(true);- setTimeout(async () => {- await mutate(`/api/workspaces/${id}`);- const currentPlan = plan ? getPlanDetails(plan) : undefined;- if (currentPlan && currentPlan.price.monthly) {- // track upgrade event- trackEvent(`Upgraded to ${currentPlan.name}`, {- _value: currentPlan.price.monthly * 100, // in cents- });- plausible("Upgraded Plan", {- props: {},- revenue: {- currency: "USD",- amount: currentPlan.price.monthly,- },- });- posthog.capture("plan_upgraded", {+ const plan = searchParams.get("plan");+ const period = searchParams.get("period");+ const currentPlan = plan ? getPlanDetails(plan) : undefined;+ toast.success(`Successfully upgraded to ${currentPlan?.name || plan}!`);+ if (currentPlan && period) {+ // track upgrade event+ trackEvent(`Upgraded to ${currentPlan.name}`, {+ _value: currentPlan.price[period] * 100, // in cents+ });+ plausible("Upgraded Plan", {+ props: {plan: currentPlan.name,- revenue: currentPlan.price.monthly,- });- }- }, 1000);+ period,+ },+ revenue: {+ currency: "USD",+ amount: currentPlan.price[period],+ },+ });+ plausible(`Upgraded to ${currentPlan.name}`, {+ revenue: {+ currency: "USD",+ amount: currentPlan.price[period],+ },+ });+ posthog.capture("plan_upgraded", {+ plan: currentPlan.name,+ period,+ revenue: currentPlan.price[period],+ });+ }}}, [searchParams, plan]);