From 720e3cab5d9e10f72de6478bc9e9202b79721e20 Mon Sep 17 00:00:00 2001 From: John Pham Date: Thu, 9 Jan 2025 14:02:40 -0800 Subject: [PATCH] Add more tracking --- src/lib/buy/index.tsx | 37 +++++++++++++++++++++++++++++++++++++ src/lib/posthog.ts | 4 +++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/lib/buy/index.tsx b/src/lib/buy/index.tsx index 6d8fdeb..7e7c7e6 100644 --- a/src/lib/buy/index.tsx +++ b/src/lib/buy/index.tsx @@ -351,8 +351,29 @@ function BuyOrder(props: BuyOrderProps) { const [resultMessage, setResultMessage] = useState(null); const handleSubmit = useCallback( (submitValue: boolean) => { + const endsAt = roundEndDate(props.endsAt); + const startAt = + props.startAt === "NOW" + ? parseStartAsDate(props.startAt) + : props.startAt; + const realDurationInHours = + dayjs(endsAt).diff(dayjs(startAt)) / 1000 / 3600; + const totalPriceInCents = getTotalPrice( + props.price, + props.size, + realDurationInHours + ); + analytics.track({ event: "buy_order_quoted", + properties: { + price: totalPriceInCents, + startsAt: startAt, + endsAt: endsAt.toDate(), + numberNodes: props.size, + instanceType: props.type, + duration: realDurationInHours, + }, }); if (submitValue === false) { setIsLoading(false); @@ -360,6 +381,14 @@ function BuyOrder(props: BuyOrderProps) { setTimeout(() => { analytics.track({ event: "buy_order_quoted_rejected", + properties: { + price: totalPriceInCents, + startsAt: startAt, + endsAt: endsAt.toDate(), + numberNodes: props.size, + instanceType: props.type, + duration: realDurationInHours, + }, }); exit(); }, 0); @@ -368,6 +397,14 @@ function BuyOrder(props: BuyOrderProps) { analytics.track({ event: "buy_order_quoted_accepted", + properties: { + price: totalPriceInCents, + startsAt: startAt, + endsAt: endsAt.toDate(), + numberNodes: props.size, + instanceType: props.type, + duration: realDurationInHours, + }, }); submitOrder(); }, diff --git a/src/lib/posthog.ts b/src/lib/posthog.ts index 05a1bdd..69a296b 100644 --- a/src/lib/posthog.ts +++ b/src/lib/posthog.ts @@ -76,7 +76,9 @@ const trackEvent = ({ } }; - runner(); + if (!IS_TRACKING_DISABLED) { + runner(); + } }; export const analytics = {