Skip to content

Commit 870e1c9

Browse files
committed
[DO NOT MERGE] - posthog migration part 6
1 parent 8894eed commit 870e1c9

File tree

11 files changed

+704
-358
lines changed

11 files changed

+704
-358
lines changed

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

Lines changed: 541 additions & 85 deletions
Large diffs are not rendered by default.

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/claim-tokens/claim-tokens-ui.tsx

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"use client";
2-
import { reportAssetBuy } from "@/analytics/report";
2+
import {
3+
reportBuyAssetCoinAttempted,
4+
reportBuyAssetCoinFailed,
5+
reportBuyAssetCoinSuccessful,
6+
} from "@/analytics/report";
37
import { Spinner } from "@/components/ui/Spinner/Spinner";
48
import { Button } from "@/components/ui/button";
59
import { DecimalInput } from "@/components/ui/decimal-input";
@@ -84,40 +88,16 @@ export function TokenDropClaim(props: {
8488
}
8589
>(undefined);
8690

87-
function report(
88-
params:
89-
| {
90-
status: "attempted" | "successful";
91-
}
92-
| {
93-
status: "failed";
94-
errorMessage: string;
95-
},
96-
) {
97-
reportAssetBuy({
98-
chainId: props.contract.chain.id,
99-
assetType: "Coin",
100-
contractType: "DropERC20",
101-
...(params.status === "failed"
102-
? {
103-
status: "failed",
104-
error: params.errorMessage,
105-
}
106-
: {
107-
status: "attempted",
108-
}),
109-
});
110-
}
111-
11291
const approveAndClaim = useMutation({
11392
mutationFn: async () => {
11493
if (!account) {
11594
toast.error("Wallet is not connected");
11695
return;
11796
}
11897

119-
report({
120-
status: "attempted",
98+
reportBuyAssetCoinAttempted({
99+
chainId: props.contract.chain.id,
100+
contractType: "DropERC20",
121101
});
122102

123103
setStepsUI(undefined);
@@ -157,9 +137,10 @@ export function TokenDropClaim(props: {
157137

158138
const errorMessage = parseError(approveTxResult.error);
159139

160-
report({
161-
status: "failed",
162-
errorMessage,
140+
reportBuyAssetCoinFailed({
141+
chainId: props.contract.chain.id,
142+
contractType: "DropERC20",
143+
error: errorMessage,
163144
});
164145

165146
toast.error("Failed to approve spending", {
@@ -193,9 +174,10 @@ export function TokenDropClaim(props: {
193174
claim: "error",
194175
});
195176

196-
report({
197-
status: "failed",
198-
errorMessage,
177+
reportBuyAssetCoinFailed({
178+
chainId: props.contract.chain.id,
179+
contractType: "DropERC20",
180+
error: errorMessage,
199181
});
200182

201183
toast.error("Failed to buy tokens", {
@@ -204,8 +186,9 @@ export function TokenDropClaim(props: {
204186
return;
205187
}
206188

207-
report({
208-
status: "successful",
189+
reportBuyAssetCoinSuccessful({
190+
chainId: props.contract.chain.id,
191+
contractType: "DropERC20",
209192
});
210193

211194
setStepsUI({

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-edition-drop/buy-edition-drop.client.tsx

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"use client";
22

3-
import { reportAssetBuy } from "@/analytics/report";
3+
import {
4+
reportBuyAssetNftAttempted,
5+
reportBuyAssetNftFailed,
6+
reportBuyAssetNftSuccessful,
7+
} from "@/analytics/report";
48
import {
59
Form,
610
FormControl,
@@ -70,39 +74,15 @@ export function BuyEditionDrop(props: BuyEditionDropProps) {
7074
enabled: true,
7175
});
7276

73-
function report(
74-
params:
75-
| {
76-
status: "attempted" | "successful";
77-
}
78-
| {
79-
status: "failed";
80-
errorMessage: string;
81-
},
82-
) {
83-
reportAssetBuy({
84-
chainId: props.contract.chain.id,
85-
assetType: "NFT",
86-
contractType: "DropERC1155",
87-
...(params.status === "failed"
88-
? {
89-
status: "failed",
90-
error: params.errorMessage,
91-
}
92-
: {
93-
status: "attempted",
94-
}),
95-
});
96-
}
97-
9877
const handleSubmit = form.handleSubmit(async (data) => {
9978
try {
10079
if (!account) {
10180
return toast.error("No account detected");
10281
}
10382

104-
report({
105-
status: "attempted",
83+
reportBuyAssetNftAttempted({
84+
chainId: props.contract.chain.id,
85+
contractType: "DropERC1155",
10686
});
10787

10888
const transaction = claimTo({
@@ -139,9 +119,10 @@ export function BuyEditionDrop(props: BuyEditionDropProps) {
139119
} catch (err) {
140120
const errorMessage = parseError(err);
141121

142-
report({
143-
status: "failed",
144-
errorMessage,
122+
reportBuyAssetNftFailed({
123+
chainId: props.contract.chain.id,
124+
contractType: "DropERC1155",
125+
error: errorMessage,
145126
});
146127

147128
console.error(errorMessage);
@@ -165,8 +146,9 @@ export function BuyEditionDrop(props: BuyEditionDropProps) {
165146
try {
166147
await claimTxPromise;
167148

168-
report({
169-
status: "successful",
149+
reportBuyAssetNftSuccessful({
150+
chainId: props.contract.chain.id,
151+
contractType: "DropERC1155",
170152
});
171153

172154
props.onSuccess?.();
@@ -178,9 +160,10 @@ export function BuyEditionDrop(props: BuyEditionDropProps) {
178160
console.error(err);
179161
const errorMessage = parseError(err);
180162

181-
report({
182-
status: "failed",
183-
errorMessage,
163+
reportBuyAssetNftFailed({
164+
chainId: props.contract.chain.id,
165+
contractType: "DropERC1155",
166+
error: errorMessage,
184167
});
185168

186169
return;
@@ -193,9 +176,10 @@ export function BuyEditionDrop(props: BuyEditionDropProps) {
193176
description: errorMessage,
194177
});
195178

196-
report({
197-
status: "failed",
198-
errorMessage,
179+
reportBuyAssetNftFailed({
180+
chainId: props.contract.chain.id,
181+
contractType: "DropERC1155",
182+
error: errorMessage,
199183
});
200184
}
201185
});

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-nft-drop/buy-nft-drop.client.tsx

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"use client";
2-
import { reportAssetBuy } from "@/analytics/report";
2+
import {
3+
reportBuyAssetNftAttempted,
4+
reportBuyAssetNftFailed,
5+
reportBuyAssetNftSuccessful,
6+
} from "@/analytics/report";
37
import { toast } from "sonner";
48
import type { ThirdwebContract } from "thirdweb";
59
import type { NFT } from "thirdweb";
@@ -28,40 +32,16 @@ export function BuyNFTDrop(props: BuyNFTDropProps) {
2832
const sendAndConfirmTx = useSendAndConfirmTransaction();
2933
const account = useActiveAccount();
3034

31-
function report(
32-
params:
33-
| {
34-
status: "attempted" | "successful";
35-
}
36-
| {
37-
status: "failed";
38-
errorMessage: string;
39-
},
40-
) {
41-
reportAssetBuy({
42-
chainId: props.contract.chain.id,
43-
assetType: "NFT",
44-
contractType: "DropERC721",
45-
...(params.status === "failed"
46-
? {
47-
status: "failed",
48-
error: params.errorMessage,
49-
}
50-
: {
51-
status: "attempted",
52-
}),
53-
});
54-
}
55-
5635
const handleSubmit = async (form: BuyNFTDropForm) => {
5736
const nftAmountToClaim = form.getValues("amount");
5837
try {
5938
if (!account) {
6039
return toast.error("No account detected");
6140
}
6241

63-
report({
64-
status: "attempted",
42+
reportBuyAssetNftAttempted({
43+
chainId: props.contract.chain.id,
44+
contractType: "DropERC721",
6545
});
6646

6747
const transaction = claimTo({
@@ -98,9 +78,10 @@ export function BuyNFTDrop(props: BuyNFTDropProps) {
9878
console.error(err);
9979
const errorMessage = parseError(err);
10080

101-
report({
102-
status: "failed",
103-
errorMessage,
81+
reportBuyAssetNftFailed({
82+
chainId: props.contract.chain.id,
83+
contractType: "DropERC721",
84+
error: errorMessage,
10485
});
10586

10687
return;
@@ -123,18 +104,20 @@ export function BuyNFTDrop(props: BuyNFTDropProps) {
123104
try {
124105
await claimTxPromise;
125106

126-
report({
127-
status: "successful",
107+
reportBuyAssetNftSuccessful({
108+
chainId: props.contract.chain.id,
109+
contractType: "DropERC721",
128110
});
129111

130112
props.onSuccess?.();
131113
} catch (err) {
132114
console.error(err);
133115
const errorMessage = parseError(err);
134116

135-
report({
136-
status: "failed",
137-
errorMessage,
117+
reportBuyAssetNftFailed({
118+
chainId: props.contract.chain.id,
119+
contractType: "DropERC721",
120+
error: errorMessage,
138121
});
139122

140123
return;
@@ -146,9 +129,10 @@ export function BuyNFTDrop(props: BuyNFTDropProps) {
146129
toast.error("Failed to buy NFTs", {
147130
description: errorMessage,
148131
});
149-
report({
150-
status: "failed",
151-
errorMessage,
132+
reportBuyAssetNftFailed({
133+
chainId: props.contract.chain.id,
134+
contractType: "DropERC721",
135+
error: errorMessage,
152136
});
153137
}
154138
};

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/assets/cards.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"use client";
22

3-
import { reportAssetsPageCardClick } from "@/analytics/report";
3+
import {
4+
reportAssetsPageCardCreateCoinClicked,
5+
reportAssetsPageCardCreateNftCollectionClicked,
6+
reportAssetsPageCardImportAssetClicked,
7+
} from "@/analytics/report";
48
import { cn } from "@/lib/utils";
59
import { ImportModal } from "components/contract-components/import-contract/modal";
610
import { ArrowDownToLineIcon, CoinsIcon, ImagesIcon } from "lucide-react";
@@ -32,27 +36,31 @@ export function Cards(props: {
3236

3337
<CardLink
3438
title="Create Coin"
35-
trackingLabel="create-coin"
3639
description="Launch your own ERC-20 coin"
3740
href={`/team/${props.teamSlug}/${props.projectSlug}/assets/create/token`}
3841
icon={CoinsIcon}
42+
onClick={() => {
43+
reportAssetsPageCardCreateCoinClicked();
44+
}}
3945
/>
4046

4147
<CardLink
4248
title="Create NFT Collection"
43-
trackingLabel="create-nft-collection"
4449
description="Launch your own NFT collection"
4550
href={`/team/${props.teamSlug}/${props.projectSlug}/assets/create/nft`}
4651
icon={ImagesIcon}
52+
onClick={() => {
53+
reportAssetsPageCardCreateNftCollectionClicked();
54+
}}
4755
/>
4856

4957
<CardLink
5058
title="Import Existing Asset"
51-
trackingLabel="import-asset"
5259
description="Import tokens or NFTs you own to the project"
5360
href={undefined}
5461
icon={ArrowDownToLineIcon}
5562
onClick={() => {
63+
reportAssetsPageCardImportAssetClicked();
5664
setImportModalOpen(true);
5765
}}
5866
/>
@@ -66,31 +74,22 @@ function CardLink(props: {
6674
href: string | undefined;
6775
onClick?: () => void;
6876
icon: React.FC<{ className?: string }>;
69-
trackingLabel: "create-nft-collection" | "import-asset" | "create-coin";
7077
}) {
7178
const { onClick } = props;
7279
const isClickable = !!onClick || !!props.href;
7380

74-
function handleClick() {
75-
reportAssetsPageCardClick({
76-
label: props.trackingLabel,
77-
});
78-
79-
onClick?.();
80-
}
81-
8281
return (
8382
<div
8483
className={cn(
8584
"relative flex flex-col rounded-lg border bg-card p-4",
8685
isClickable && "cursor-pointer hover:border-active-border ",
8786
)}
88-
onClick={handleClick}
87+
onClick={onClick}
8988
role={onClick ? "button" : undefined}
9089
tabIndex={onClick ? 0 : undefined}
9190
onKeyDown={(e) => {
9291
if (e.key === "Enter" || e.key === " ") {
93-
handleClick();
92+
onClick?.();
9493
}
9594
}}
9695
>

0 commit comments

Comments
 (0)