Skip to content

Commit

Permalink
Add more tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPhamous committed Jan 9, 2025
1 parent bfb0f1d commit 720e3ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/lib/buy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,44 @@ function BuyOrder(props: BuyOrderProps) {
const [resultMessage, setResultMessage] = useState<string | null>(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);
setResultMessage("Order not placed, use 'y' to confirm");
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);
Expand All @@ -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();
},
Expand Down
4 changes: 3 additions & 1 deletion src/lib/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const trackEvent = ({
}
};

runner();
if (!IS_TRACKING_DISABLED) {
runner();
}
};

export const analytics = {
Expand Down

0 comments on commit 720e3ca

Please sign in to comment.