Skip to content

Commit 3d36985

Browse files
NicolappsConvex, Inc.
authored and
Convex, Inc.
committed
Add product event logs for referrals (#35933)
GitOrigin-RevId: 94f242153671a4a8cd3f09a1ef1ccb1d7efeff14
1 parent f97287b commit 3d36985

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

npm-packages/dashboard/src/components/referral/RedeemReferralLanding.test.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { act, render, screen } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
33
import { RedeemReferralLanding } from "./RedeemReferralLanding";
44

5+
jest.mock("convex-analytics", () => ({
6+
logEvent: jest.fn(),
7+
}));
8+
59
describe("RedeemReferralLanding", () => {
610
// We’re applying a onClick event to the link. This test verifies it is still a <a> and not a
711
// button to ensure there is no regression on the click behavior.
@@ -20,6 +24,9 @@ describe("RedeemReferralLanding", () => {
2024
await userEvent.click(link);
2125
});
2226

27+
expect(jest.requireMock("convex-analytics").logEvent).toHaveBeenCalledWith(
28+
"clicked “Sign up with GitHub” through referral landing",
29+
);
2330
expect(link).toHaveAttribute("aria-disabled", "true");
2431
});
2532
});

npm-packages/dashboard/src/components/referral/RedeemReferralLanding.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GitHubLogoIcon } from "@radix-ui/react-icons";
2+
import { logEvent } from "convex-analytics";
23
import { Sheet } from "dashboard-common/elements/Sheet";
34
import { Spinner } from "dashboard-common/elements/Spinner";
45
import { cn } from "dashboard-common/lib/cn";
@@ -65,7 +66,10 @@ function LogInButton({ code }: { code: string }) {
6566
clicked && "opacity-80 cursor-progress",
6667
)}
6768
href={`/api/auth/login?returnTo=${encodeURIComponent(`/referral/${code}/apply`)}`}
68-
onClick={() => setClicked(true)}
69+
onClick={() => {
70+
logEvent("clicked “Sign up with GitHub” through referral landing");
71+
setClicked(true);
72+
}}
6973
aria-disabled={clicked}
7074
>
7175
<span

npm-packages/dashboard/src/components/referral/Referrals.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Callout } from "dashboard-common/elements/Callout";
99
import { useReferralState } from "api/referrals";
1010
import { Loading } from "dashboard-common/elements/Loading";
1111
import { useCopy } from "dashboard-common/lib/useCopy";
12+
import { logEvent } from "convex-analytics";
1213
import { ReferralsBenefits } from "./ReferralsBenefits";
1314

1415
// Keep in sync with MAX_REFERRALS_BONUS in big_brain_lib/src/model/referrals.rs
@@ -155,6 +156,7 @@ function ReferralLink({ referralCode }: { referralCode: string }) {
155156
iconTooltip={copied ? "Copied" : "Copy to clipboard"}
156157
action={async () => {
157158
copy(`https://www.convex.dev/referral/${referralCode}`);
159+
logEvent("copied referral link");
158160

159161
setCopied(true);
160162
setTimeout(() => {

npm-packages/dashboard/src/pages/referral/[code]/apply.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useState } from "react";
1010
import { Team } from "generatedApi";
1111
import { useApplyReferralCode, useReferralCode } from "api/referrals";
1212
import { useProfile } from "api/profile";
13+
import { logEvent } from "convex-analytics";
1314

1415
export { getServerSideProps } from "lib/ssr";
1516

@@ -49,6 +50,8 @@ function RedeemReferralCodePage() {
4950
referralCode: code,
5051
});
5152

53+
logEvent("redeemed referral code");
54+
5255
void router.push(`/t/${selectedTeam.slug}`);
5356
}}
5457
teamEligibility={teamEligibility}

0 commit comments

Comments
 (0)