Skip to content

Commit 03132a7

Browse files
jnsdlsMananTank
authored andcommitted
posthog migration: part 5
1 parent f005dd2 commit 03132a7

File tree

114 files changed

+735
-2337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+735
-2337
lines changed

apps/dashboard/src/@/analytics/report.ts

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { Team } from "../api/team";
1010
* ### Why do we need to report this event?
1111
* - To track the number of contracts deployed
1212
* - To track the number of contracts deployed on each chain
13+
* - To track if the contract was deployed on the asset page vs on the deploy page
1314
*
1415
* ### Who is responsible for this event?
1516
* @jnsdls
@@ -20,6 +21,7 @@ export function reportContractDeployed(properties: {
2021
chainId: number;
2122
publisher: string | undefined;
2223
contractName: string | undefined;
24+
deploymentType?: "asset";
2325
}) {
2426
posthog.capture("contract deployed", properties);
2527
}
@@ -39,6 +41,25 @@ export function reportContractDeployFailed(properties: {
3941
posthog.capture("contract deploy failed", properties);
4042
}
4143

44+
/**
45+
* ### Why do we need to report this event?
46+
* - To track the number of contracts published
47+
* - To understand the type of contracts published
48+
* - To understand who publishes contracts
49+
*
50+
* ### Who is responsible for this event?
51+
* @jnsdls
52+
*
53+
*/
54+
export function reportContractPublished(properties: {
55+
publisher: string;
56+
contractName: string;
57+
version: string;
58+
deployType: string | undefined;
59+
}) {
60+
posthog.capture("contract published", properties);
61+
}
62+
4263
// ----------------------------
4364
// ONBOARDING (TEAM)
4465
// ----------------------------
@@ -148,3 +169,193 @@ export function reportOnboardingMembersUpsellPlanSelected(properties: {
148169
export function reportOnboardingCompleted() {
149170
posthog.capture("onboarding completed");
150171
}
172+
173+
// ----------------------------
174+
// FAUCET
175+
// ----------------------------
176+
/**
177+
* ### Why do we need to report this event?
178+
* - To track which chain the faucet was used on
179+
* - To track how popular specific faucets are
180+
*
181+
* ### Who is responsible for this event?
182+
* @jnsdls
183+
*
184+
*/
185+
export function reportFaucetUsed(properties: {
186+
chainId: number;
187+
}) {
188+
posthog.capture("faucet used", {
189+
chainId: properties.chainId,
190+
});
191+
}
192+
// ----------------------------
193+
// CHAIN CONFIGURATION
194+
// ----------------------------
195+
/**
196+
* ### Why do we need to report this event?
197+
* - To track which custom chains customers are adding that we may want to add to the app
198+
*
199+
* ### Who is responsible for this event?
200+
* @jnsdls
201+
*
202+
*/
203+
export function reportChainConfigurationAdded(properties: {
204+
chainId: number;
205+
chainName: string;
206+
rpcURLs: readonly string[];
207+
nativeCurrency: {
208+
name: string;
209+
symbol: string;
210+
decimals: number;
211+
};
212+
}) {
213+
posthog.capture("chain configuration added", {
214+
chainId: properties.chainId,
215+
chainName: properties.chainName,
216+
rpcURLs: properties.rpcURLs,
217+
nativeCurrency: properties.nativeCurrency,
218+
});
219+
}
220+
221+
// ----------------------------
222+
// ASSETS
223+
// ----------------------------
224+
225+
type StatusWithError =
226+
| {
227+
status: "successful" | "attempted";
228+
}
229+
| {
230+
status: "failed";
231+
error: string;
232+
};
233+
234+
type AssetContractType = "DropERC20" | "DropERC1155" | "DropERC721";
235+
236+
/**
237+
* ### Why do we need to report this event?
238+
* - To track asset buy statuses (successful, failed, attempted) in the new asset pages
239+
*
240+
* ### Who is responsible for this event?
241+
* @MananTank
242+
*
243+
*/
244+
export function reportAssetBuy(
245+
properties: {
246+
chainId: number;
247+
assetType: "NFT" | "Coin";
248+
contractType: AssetContractType;
249+
} & StatusWithError,
250+
) {
251+
// Example: asset buy NFT successful
252+
posthog.capture(`asset buy ${properties.assetType} ${properties.status}`, {
253+
chainId: properties.chainId,
254+
contractType: properties.contractType,
255+
...(properties.status === "failed" && {
256+
error: properties.error,
257+
}),
258+
});
259+
}
260+
261+
/**
262+
* ### Why do we need to report this event?
263+
* - To track the CTA card clicks on the assets page
264+
*
265+
* ### Who is responsible for this event?
266+
* @MananTank
267+
*
268+
*/
269+
export function reportAssetsPageCardClick(properties: {
270+
label: "create-nft-collection" | "import-asset" | "create-coin";
271+
}) {
272+
// Example: asset page card create-nft-collection clicked
273+
posthog.capture(`assets page card ${properties.label} clicked`);
274+
}
275+
276+
/**
277+
* ### Why do we need to report this event?
278+
* - To track the steps that users are going through in asset creation flow
279+
*
280+
* ### Who is responsible for this event?
281+
* @MananTank
282+
*
283+
*/
284+
export function reportCreateAssetStepNextClicked(
285+
properties:
286+
| {
287+
assetType: "NFT";
288+
page: "collection-info" | "upload-assets" | "sales-settings";
289+
}
290+
| {
291+
assetType: "Coin";
292+
page: "coin-info" | "token-distribution" | "launch-coin";
293+
},
294+
) {
295+
// Example: create asset NFT collection-info next clicked
296+
posthog.capture(
297+
`create asset ${properties.assetType} ${properties.page} next clicked`,
298+
);
299+
}
300+
301+
/**
302+
* ### Why do we need to report this event?
303+
* - To track the status of each step of the create asset flow
304+
*
305+
* ### Who is responsible for this event?
306+
* @MananTank
307+
*
308+
*/
309+
export function reportCreateAssetStepStatus(
310+
properties: (
311+
| {
312+
assetType: "NFT";
313+
step: "deploy-contract" | "lazy-mint-nfts" | "set-claim-conditions";
314+
}
315+
| {
316+
assetType: "Coin";
317+
step:
318+
| "deploy-contract"
319+
| "set-claim-conditions"
320+
| "mint-tokens"
321+
| "airdrop-tokens";
322+
}
323+
) &
324+
StatusWithError & {
325+
contractType: AssetContractType;
326+
},
327+
) {
328+
// Example: create asset NFT deploy-contract successful
329+
posthog.capture(
330+
`create asset ${properties.assetType} ${properties.step} ${properties.status}`,
331+
{
332+
...(properties.status === "failed" && {
333+
error: properties.error,
334+
}),
335+
contractType: properties.contractType,
336+
},
337+
);
338+
}
339+
340+
/**
341+
* ### Why do we need to report this event?
342+
* - To track the status of create asset as a whole (successful, failed, attempted)
343+
*
344+
* ### Who is responsible for this event?
345+
* @MananTank
346+
*
347+
*/
348+
export function reportCreateAssetStatus(
349+
properties: {
350+
assetType: "NFT" | "Coin";
351+
contractType: AssetContractType;
352+
} & StatusWithError,
353+
) {
354+
// Example: create asset NFT successful
355+
posthog.capture(`create asset ${properties.assetType} ${properties.status}`, {
356+
...(properties.status === "failed" && {
357+
error: properties.error,
358+
}),
359+
contractType: properties.contractType,
360+
});
361+
}

apps/dashboard/src/@/components/blocks/pricing-card.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Button } from "@/components/ui/button";
55
import { ToolTipLabel } from "@/components/ui/tooltip";
66
import { cn } from "@/lib/utils";
77
import { RenewSubscriptionButton } from "components/settings/Account/Billing/renew-subscription/renew-subscription-button";
8-
import { useTrack } from "hooks/analytics/useTrack";
98
import { CheckIcon, DollarSignIcon } from "lucide-react";
109
import Link from "next/link";
1110
import type React from "react";
@@ -58,7 +57,6 @@ export const PricingCard: React.FC<PricingCardProps> = ({
5857
}) => {
5958
const plan = TEAM_PLANS[billingPlan];
6059

61-
const trackEvent = useTrack();
6260
const remainingTrialDays =
6361
(activeTrialEndsAt ? remainingDays(activeTrialEndsAt) : 0) || 0;
6462

@@ -68,15 +66,6 @@ export const PricingCard: React.FC<PricingCardProps> = ({
6866
billingStatus === "noPayment" &&
6967
billingPlan === "growth";
7068

71-
const handleCTAClick = () => {
72-
cta?.onClick?.();
73-
trackEvent({
74-
category: "account",
75-
label: `${billingPlan}Plan`,
76-
action: "click",
77-
});
78-
};
79-
8069
return (
8170
<div
8271
className={cn(
@@ -163,7 +152,7 @@ export const PricingCard: React.FC<PricingCardProps> = ({
163152
buttonProps={{
164153
variant: highlighted ? "default" : "outline",
165154
className: highlighted ? undefined : "bg-background",
166-
onClick: handleCTAClick,
155+
onClick: cta.onClick,
167156
}}
168157
teamSlug={teamSlug}
169158
sku={billingPlanToSkuMap[billingPlan]}
@@ -181,7 +170,7 @@ export const PricingCard: React.FC<PricingCardProps> = ({
181170
<Link
182171
href={cta.href}
183172
target="_blank"
184-
onClick={handleCTAClick}
173+
onClick={cta.onClick}
185174
rel="noopener noreferrer"
186175
>
187176
{has7DayTrial ? "Start 7 Day Free Trial" : cta.label}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/FaucetButton.tsx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use client";
2+
import { reportFaucetUsed } from "@/analytics/report";
23
import { CopyTextButton } from "@/components/ui/CopyTextButton";
34
import { Spinner } from "@/components/ui/Spinner/Spinner";
45
import { Button } from "@/components/ui/button";
@@ -29,7 +30,6 @@ import { Turnstile } from "@marsidev/react-turnstile";
2930
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3031
import type { CanClaimResponseType } from "app/(app)/api/testnet-faucet/can-claim/CanClaimResponseType";
3132
import { mapV4ChainToV5Chain } from "contexts/map-chains";
32-
import { useTrack } from "hooks/analytics/useTrack";
3333
import Link from "next/link";
3434
import { usePathname } from "next/navigation";
3535
import { useForm } from "react-hook-form";
@@ -95,17 +95,11 @@ export function FaucetButton({
9595
chain: definedChain,
9696
client,
9797
});
98-
const trackEvent = useTrack();
98+
9999
const queryClient = useQueryClient();
100100

101101
const claimMutation = useMutation({
102102
mutationFn: async (turnstileToken: string) => {
103-
trackEvent({
104-
category: "faucet",
105-
action: "claim",
106-
label: "attempt",
107-
chain_id: chainId,
108-
});
109103
const response = await fetch("/api/testnet-faucet/claim", {
110104
method: "POST",
111105
headers: {
@@ -124,20 +118,8 @@ export function FaucetButton({
124118
}
125119
},
126120
onSuccess: () => {
127-
trackEvent({
128-
category: "faucet",
129-
action: "claim",
130-
label: "success",
131-
chain_id: chainId,
132-
});
133-
},
134-
onError: (error) => {
135-
trackEvent({
136-
category: "faucet",
137-
action: "claim",
138-
label: "error",
139-
chain_id: chainId,
140-
errorMsg: error instanceof Error ? error.message : "Unknown error",
121+
reportFaucetUsed({
122+
chainId,
141123
});
142124
},
143125
onSettled: () => {
@@ -223,8 +205,9 @@ export function FaucetButton({
223205
{canClaimFaucetQuery.data.type === "unsupported-chain" &&
224206
"Faucet is empty right now"}
225207

208+
{/* TODO: add an upsell path here to subscribe to one of these plans */}
226209
{canClaimFaucetQuery.data.type === "paid-plan-required" &&
227-
"Faucet is only available on Starter, Growth and Pro plans."}
210+
"Faucet is only available on Starter, Growth, Scale and Pro plans."}
228211
</Button>
229212
);
230213
}

0 commit comments

Comments
 (0)