Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(web): slim PurchaseTracker to checkout URL cleanup

Richie McIlroye8be351d0dd7
diff --git a/apps/web/app/Layout/PurchaseTracker.tsx b/apps/web/app/Layout/PurchaseTracker.tsx
index d15e3ed73..3a142fba4 100644
--- a/apps/web/app/Layout/PurchaseTracker.tsx
+++ b/apps/web/app/Layout/PurchaseTracker.tsx
@@ -1,50 +1,25 @@
"use client";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
-import { useCallback, useEffect } from "react";
-import { getPurchaseForMeta } from "@/actions/billing/track-meta-purchase";
-import { trackMetaEvent } from "./MetaPixel";
+import { useEffect } from "react";
export function PurchaseTracker() {
const params = useSearchParams();
const router = useRouter();
const pathname = usePathname();
- const shouldCheck = params.get("upgrade") === "true";
- const sessionId = params.get("session_id");
+ const shouldClean = params.get("upgrade") === "true";
+
+ useEffect(() => {
+ if (!shouldClean) return;
- const cleanUrl = useCallback(() => {
const next = new URLSearchParams(params.toString());
next.delete("upgrade");
next.delete("guest");
next.delete("session_id");
const query = next.toString();
router.replace(query ? `${pathname}?${query}` : pathname);
- }, [params, pathname, router]);
-
- useEffect(() => {
- if (!shouldCheck) return;
- let cancelled = false;
- (async () => {
- const result = await getPurchaseForMeta({ sessionId });
- if (cancelled) return;
- if (
- result.shouldTrack &&
- typeof result.value === "number" &&
- result.currency
- ) {
- trackMetaEvent(
- "Purchase",
- { value: result.value, currency: result.currency },
- { eventId: result.eventId },
- );
- }
- cleanUrl();
- })();
- return () => {
- cancelled = true;
- };
- }, [shouldCheck, sessionId, cleanUrl]);
+ }, [shouldClean, params, pathname, router]);
return null;
}