Skip to content

Commit 5c572aa

Browse files
jnsdlsMananTank
authored andcommitted
posthog migration: part 5
1 parent 09cc9b3 commit 5c572aa

File tree

114 files changed

+423
-2331
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

+423
-2331
lines changed

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

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ export function reportContractDeployFailed(properties: {
3939
posthog.capture("contract deploy failed", properties);
4040
}
4141

42+
/**
43+
* ### Why do we need to report this event?
44+
* - To track the number of contracts published
45+
* - To understand the type of contracts published
46+
* - To understand who publishes contracts
47+
*
48+
* ### Who is responsible for this event?
49+
* @jnsdls
50+
*
51+
*/
52+
export function reportContractPublished(properties: {
53+
publisher: string;
54+
contractName: string;
55+
version: string;
56+
deployType: string | undefined;
57+
}) {
58+
posthog.capture("contract published", properties);
59+
}
60+
4261
// ----------------------------
4362
// ONBOARDING (TEAM)
4463
// ----------------------------
@@ -148,3 +167,130 @@ export function reportOnboardingMembersUpsellPlanSelected(properties: {
148167
export function reportOnboardingCompleted() {
149168
posthog.capture("onboarding completed");
150169
}
170+
171+
// ----------------------------
172+
// FAUCET
173+
// ----------------------------
174+
/**
175+
* ### Why do we need to report this event?
176+
* - To track which chain the faucet was used on
177+
* - To track how popular specific faucets are
178+
*
179+
* ### Who is responsible for this event?
180+
* @jnsdls
181+
*
182+
*/
183+
export function reportFaucetUsed(properties: {
184+
chainId: number;
185+
}) {
186+
posthog.capture("faucet used", {
187+
chainId: properties.chainId,
188+
});
189+
}
190+
// ----------------------------
191+
// CHAIN CONFIGURATION
192+
// ----------------------------
193+
/**
194+
* ### Why do we need to report this event?
195+
* - To track which custom chains customers are adding that we may want to add to the app
196+
*
197+
* ### Who is responsible for this event?
198+
* @jnsdls
199+
*
200+
*/
201+
export function reportChainConfigurationAdded(properties: {
202+
chainId: number;
203+
chainName: string;
204+
rpcURLs: readonly string[];
205+
nativeCurrency: {
206+
name: string;
207+
symbol: string;
208+
decimals: number;
209+
};
210+
}) {
211+
posthog.capture("chain configuration added", {
212+
chainId: properties.chainId,
213+
chainName: properties.chainName,
214+
rpcURLs: properties.rpcURLs,
215+
nativeCurrency: properties.nativeCurrency,
216+
});
217+
}
218+
219+
// ----------------------------
220+
// ASSETS
221+
// ----------------------------
222+
223+
/**
224+
* ### Why do we need to report this event?
225+
* - To track asset buy statuses (successful, failed, attempted) in the new asset pages
226+
*
227+
* ### Who is responsible for this event?
228+
* @MananTank
229+
*
230+
*/
231+
export function reportAssetBuy(
232+
properties: {
233+
chainId: number;
234+
assetType: "NFT" | "Coin";
235+
contractType: "DropERC20" | "DropERC1155" | "DropERC721";
236+
} & (
237+
| {
238+
status: "successful" | "attempted";
239+
}
240+
| {
241+
status: "failed";
242+
error: string;
243+
}
244+
),
245+
) {
246+
posthog.capture(`asset buy ${properties.status}`, {
247+
chainId: properties.chainId,
248+
assetType: properties.assetType,
249+
contractType: properties.contractType,
250+
status: properties.status,
251+
...(properties.status === "failed" && {
252+
error: properties.error,
253+
}),
254+
});
255+
}
256+
257+
/**
258+
* ### Why do we need to report this event?
259+
* - To track asset buy statuses (successful, failed, attempted) in the new asset pages
260+
*
261+
* ### Who is responsible for this event?
262+
* @MananTank
263+
*
264+
*/
265+
export function reportAssetsPageCardClick(properties: {
266+
label: "create-nft-collection" | "import-asset" | "create-coin";
267+
}) {
268+
posthog.capture("assets page card clicked", {
269+
label: properties.label,
270+
});
271+
}
272+
273+
/**
274+
* ### Why do we need to report this event?
275+
* - To track the steps that users are going through when creating an asset
276+
*
277+
* ### Who is responsible for this event?
278+
* @MananTank
279+
*
280+
*/
281+
export function reportCreateAssetNextStepClicked(
282+
properties:
283+
| {
284+
assetType: "NFT";
285+
page: "collection-info" | "upload-assets" | "sales-settings";
286+
}
287+
| {
288+
assetType: "Coin";
289+
page: "coin-info" | "token-distribution" | "launch-coin";
290+
},
291+
) {
292+
posthog.capture("create asset next clicked", {
293+
page: properties.page,
294+
assetType: properties.assetType,
295+
});
296+
}

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
}

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

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22
import { Button } from "@/components/ui/button";
33
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
4-
import { useTrack } from "hooks/analytics/useTrack";
54
import { defineDashboardChain } from "lib/defineDashboardChain";
65
import { useTheme } from "next-themes";
76
import type { ThirdwebClient } from "thirdweb";
@@ -14,21 +13,11 @@ export function PayModalButton(props: {
1413
client: ThirdwebClient;
1514
}) {
1615
const { theme } = useTheme();
17-
const trackEvent = useTrack();
16+
1817
return (
1918
<Dialog>
2019
<DialogTrigger asChild>
21-
<Button
22-
variant="primary"
23-
className="w-full"
24-
onClick={() => {
25-
trackEvent({
26-
category: "pay",
27-
action: "buy",
28-
label: "attempt",
29-
});
30-
}}
31-
>
20+
<Button variant="primary" className="w-full">
3221
{props.label}
3322
</Button>
3423
</DialogTrigger>
@@ -42,35 +31,6 @@ export function PayModalButton(props: {
4231
theme={getSDKTheme(theme === "dark" ? "dark" : "light")}
4332
className="!w-auto"
4433
payOptions={{
45-
// biome-ignore lint/suspicious/noExplicitAny: false positive
46-
onPurchaseSuccess(info: any) {
47-
if (
48-
info.type === "crypto" &&
49-
info.status.status !== "NOT_FOUND"
50-
) {
51-
trackEvent({
52-
category: "pay",
53-
action: "buy",
54-
label: "success",
55-
type: info.type,
56-
chainId: info.status.quote.toToken.chainId,
57-
tokenAddress: info.status.quote.toToken.tokenAddress,
58-
amount: info.status.quote.toAmount,
59-
});
60-
}
61-
62-
if (info.type === "fiat" && info.status.status !== "NOT_FOUND") {
63-
trackEvent({
64-
category: "pay",
65-
action: "buy",
66-
label: "success",
67-
type: info.type,
68-
chainId: info.status.quote.toToken.chainId,
69-
tokenAddress: info.status.quote.toToken.tokenAddress,
70-
amount: info.status.quote.estimatedToTokenAmount,
71-
});
72-
}
73-
},
7434
prefillBuy: {
7535
// Do not include local chain overrides for chain pages
7636
// eslint-disable-next-line no-restricted-syntax

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/cancel-tab.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"use client";
22
import { TransactionButton } from "components/buttons/TransactionButton";
3-
import { useTrack } from "hooks/analytics/useTrack";
4-
import { useAllChainsData } from "hooks/chains/allChains";
53
import { toast } from "sonner";
64
import type { ThirdwebContract } from "thirdweb";
75
import { cancelAuction, cancelListing } from "thirdweb/extensions/marketplace";
@@ -20,9 +18,6 @@ export const CancelTab: React.FC<CancelTabProps> = ({
2018
isAuction,
2119
isLoggedIn,
2220
}) => {
23-
const trackEvent = useTrack();
24-
const { idToChain } = useAllChainsData();
25-
const network = idToChain.get(contract.chain.id);
2621
const transaction = isAuction
2722
? cancelAuction({ contract, auctionId: BigInt(id) })
2823
: cancelListing({ contract, listingId: BigInt(id) });
@@ -36,28 +31,8 @@ export const CancelTab: React.FC<CancelTabProps> = ({
3631
transactionCount={1}
3732
isPending={cancelQuery.isPending}
3833
onClick={() => {
39-
trackEvent({
40-
category: "marketplace",
41-
action: "cancel-listing",
42-
label: "attempt",
43-
});
4434
const promise = cancelQuery.mutateAsync(transaction, {
45-
onSuccess: () => {
46-
trackEvent({
47-
category: "marketplace",
48-
action: "cancel-listing",
49-
label: "success",
50-
network,
51-
});
52-
},
5335
onError: (error) => {
54-
trackEvent({
55-
category: "marketplace",
56-
action: "cancel-listing",
57-
label: "error",
58-
network,
59-
error,
60-
});
6136
console.error(error);
6237
},
6338
});

0 commit comments

Comments
 (0)