Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat(analytics): checkout cancelled

Marc Seitz71bfa5bf95c7
diff --git a/pages/api/teams/[teamId]/billing/upgrade.ts b/pages/api/teams/[teamId]/billing/upgrade.ts
index 03613c49..7c5f3a11 100644
--- a/pages/api/teams/[teamId]/billing/upgrade.ts
+++ b/pages/api/teams/[teamId]/billing/upgrade.ts
@@ -50,7 +50,7 @@ export default async function handle(
customer_update: { name: "auto" },
billing_address_collection: "required",
success_url: `${process.env.NEXTAUTH_URL}/settings/billing?success=true`,
- cancel_url: `${process.env.NEXTAUTH_URL}/settings/billing`,
+ cancel_url: `${process.env.NEXTAUTH_URL}/settings/billing?cancel=true`,
line_items: [{ price: priceId, quantity: 1 }],
automatic_tax: {
enabled: true,
@@ -68,7 +68,7 @@ export default async function handle(
customer_email: userEmail ?? undefined,
billing_address_collection: "required",
success_url: `${process.env.NEXTAUTH_URL}/settings/billing?success=true`,
- cancel_url: `${process.env.NEXTAUTH_URL}/settings/billing`,
+ cancel_url: `${process.env.NEXTAUTH_URL}/settings/billing?cancel=true`,
line_items: [{ price: priceId, quantity: 1 }],
automatic_tax: {
enabled: true,
diff --git a/pages/settings/billing.tsx b/pages/settings/billing.tsx
index d7aeced8..c9f8ef97 100644
--- a/pages/settings/billing.tsx
+++ b/pages/settings/billing.tsx
@@ -4,6 +4,7 @@ import Navbar from "@/components/settings/navbar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { useTeam } from "@/context/team-context";
+import { useAnalytics } from "@/lib/analytics";
import { useBilling } from "@/lib/swr/use-billing";
import { cn } from "@/lib/utils";
import Link from "next/link";
@@ -24,6 +25,7 @@ interface Tier {
export default function Billing() {
const router = useRouter();
+ const analytics = useAnalytics();
const { plan, startsAt, endsAt } = useBilling();
const [clicked, setClicked] = useState<boolean>(false);
@@ -32,15 +34,20 @@ export default function Billing() {
useEffect(() => {
if (router.query.success) {
toast.success("Upgrade success!");
- // setTimeout(() => {
- // mutate(`/api/projects/${slug}`);
- // // track upgrade to pro event
- // va.track("Upgraded Plan", {
- // plan: "pro",
- // });
- // }, 1000);
+ analytics.capture("User Upgraded", {
+ plan: plan,
+ teamId: teamInfo?.currentTeam?.id,
+ $set: { teamId: teamInfo?.currentTeam?.id, teamPlan: plan },
+ });
}
- }, [router.query.success]);
+
+ if (router.query.cancel) {
+ console.log("Stripe Checkout Cancelled");
+ analytics.capture("Stripe Checkout Cancelled", {
+ teamId: teamInfo?.currentTeam?.id,
+ });
+ }
+ }, [router.query]);
const tiers: Tier[] = [
{