Skip to content

Commit ac429f1

Browse files
committed
[DO NOT MERGE] - posthog migration part 6
1 parent 03132a7 commit ac429f1

File tree

12 files changed

+258
-416
lines changed

12 files changed

+258
-416
lines changed

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

Lines changed: 101 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export function reportFaucetUsed(properties: {
189189
chainId: properties.chainId,
190190
});
191191
}
192+
192193
// ----------------------------
193194
// CHAIN CONFIGURATION
194195
// ----------------------------
@@ -222,140 +223,161 @@ export function reportChainConfigurationAdded(properties: {
222223
// ASSETS
223224
// ----------------------------
224225

225-
type StatusWithError =
226-
| {
227-
status: "successful" | "attempted";
228-
}
229-
| {
230-
status: "failed";
231-
error: string;
232-
};
233-
234226
type AssetContractType = "DropERC20" | "DropERC1155" | "DropERC721";
235227

236228
/**
237229
* ### Why do we need to report this event?
238-
* - To track asset buy statuses (successful, failed, attempted) in the new asset pages
230+
* - To track number of successful asset purchases from the asset page
231+
* - To track which asset and contract types are being purchased the most
239232
*
240233
* ### Who is responsible for this event?
241234
* @MananTank
242-
*
243235
*/
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}`, {
236+
export function reportAssetBuySuccessful(properties: {
237+
chainId: number;
238+
contractType: AssetContractType;
239+
assetType: "nft" | "coin";
240+
}) {
241+
posthog.capture("asset buy successful", {
253242
chainId: properties.chainId,
254243
contractType: properties.contractType,
255-
...(properties.status === "failed" && {
256-
error: properties.error,
257-
}),
244+
assetType: properties.assetType,
258245
});
259246
}
260247

261248
/**
262249
* ### Why do we need to report this event?
263-
* - To track the CTA card clicks on the assets page
250+
* - To track number of failed asset purchases from the asset page
251+
* - To track the errors that users encounter when trying to purchase an asset
264252
*
265253
* ### Who is responsible for this event?
266254
* @MananTank
255+
*/
256+
export function reportAssetBuyFailed(properties: {
257+
chainId: number;
258+
contractType: AssetContractType;
259+
assetType: "nft" | "coin";
260+
error: string;
261+
}) {
262+
posthog.capture("asset buy failed", {
263+
chainId: properties.chainId,
264+
contractType: properties.contractType,
265+
assetType: properties.assetType,
266+
error: properties.error,
267+
});
268+
}
269+
270+
// Assets Landing Page ----------------------------
271+
272+
/**
273+
* ### Why do we need to report this event?
274+
* - To track number of asset creation started from the assets page
275+
* - To track which asset types are being created the most
267276
*
277+
* ### Who is responsible for this event?
278+
* @MananTank
268279
*/
269-
export function reportAssetsPageCardClick(properties: {
270-
label: "create-nft-collection" | "import-asset" | "create-coin";
280+
export function reportAssetCreationStarted(properties: {
281+
assetType: "nft" | "coin";
271282
}) {
272-
// Example: asset page card create-nft-collection clicked
273-
posthog.capture(`assets page card ${properties.label} clicked`);
283+
posthog.capture("asset creation started", {
284+
assetType: properties.assetType,
285+
});
286+
}
287+
288+
/**
289+
* ### Why do we need to report this event?
290+
* - To track number of assets imported successfully from the assets page
291+
*
292+
* ### Who is responsible for this event?
293+
* @MananTank
294+
*/
295+
export function reportAssetImportSuccessful() {
296+
posthog.capture("asset import successful");
274297
}
275298

276299
/**
277300
* ### Why do we need to report this event?
278-
* - To track the steps that users are going through in asset creation flow
301+
* - To track number of asset import started in the assets page
279302
*
280303
* ### Who is responsible for this event?
281304
* @MananTank
305+
*/
306+
export function reportAssetImportStarted() {
307+
posthog.capture("asset import started");
308+
}
309+
310+
/**
311+
* ### Why do we need to report this event?
312+
* - To track the steps users are configuring in the asset creation to understand if there are any drop-offs
282313
*
314+
* ### Who is responsible for this event?
315+
* @MananTank
283316
*/
284-
export function reportCreateAssetStepNextClicked(
317+
export function reportAssetCreationStepConfigured(
285318
properties:
286319
| {
287-
assetType: "NFT";
288-
page: "collection-info" | "upload-assets" | "sales-settings";
320+
assetType: "nft";
321+
step: "collection-info" | "upload-assets" | "sales-settings";
289322
}
290323
| {
291-
assetType: "Coin";
292-
page: "coin-info" | "token-distribution" | "launch-coin";
324+
assetType: "coin";
325+
step: "coin-info" | "token-distribution" | "launch-coin";
293326
},
294327
) {
295-
// Example: create asset NFT collection-info next clicked
296-
posthog.capture(
297-
`create asset ${properties.assetType} ${properties.page} next clicked`,
298-
);
328+
posthog.capture("asset creation step configured", {
329+
assetType: properties.assetType,
330+
step: properties.step,
331+
});
299332
}
300333

301334
/**
302335
* ### Why do we need to report this event?
303-
* - To track the status of each step of the create asset flow
336+
* - To track number of successful asset creations
337+
* - To track which asset types are being created the most
304338
*
305339
* ### Who is responsible for this event?
306340
* @MananTank
341+
*/
342+
export function reportAssetCreationSuccessful(properties: {
343+
assetType: "nft" | "coin";
344+
contractType: AssetContractType;
345+
}) {
346+
posthog.capture("asset creation successful", {
347+
assetType: properties.assetType,
348+
contractType: properties.contractType,
349+
});
350+
}
351+
352+
/**
353+
* ### Why do we need to report this event?
354+
* - To track number of failed asset creations
355+
* - To track the errors that users encounter when trying to create an asset
356+
* - To track the step that is failing in the asset creation
307357
*
358+
* ### Who is responsible for this event?
359+
* @MananTank
308360
*/
309-
export function reportCreateAssetStepStatus(
310-
properties: (
361+
export function reportAssetCreationFailed(
362+
properties: { contractType: AssetContractType; error: string } & (
311363
| {
312-
assetType: "NFT";
313-
step: "deploy-contract" | "lazy-mint-nfts" | "set-claim-conditions";
364+
assetType: "nft";
365+
step: "deploy-contract" | "mint-nfts" | "set-claim-conditions";
314366
}
315367
| {
316-
assetType: "Coin";
368+
assetType: "coin";
317369
step:
318370
| "deploy-contract"
319371
| "set-claim-conditions"
320372
| "mint-tokens"
321373
| "airdrop-tokens";
322374
}
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,
375+
),
353376
) {
354-
// Example: create asset NFT successful
355-
posthog.capture(`create asset ${properties.assetType} ${properties.status}`, {
356-
...(properties.status === "failed" && {
357-
error: properties.error,
358-
}),
377+
posthog.capture("asset creation failed", {
378+
assetType: properties.assetType,
359379
contractType: properties.contractType,
380+
error: properties.error,
381+
step: properties.step,
360382
});
361383
}

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

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"use client";
2-
import { reportAssetBuy } from "@/analytics/report";
2+
3+
import {
4+
reportAssetBuyFailed,
5+
reportAssetBuySuccessful,
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,42 +88,13 @@ 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",
121-
});
122-
12398
setStepsUI(undefined);
12499

125100
const transaction = claimTo({
@@ -157,9 +132,11 @@ export function TokenDropClaim(props: {
157132

158133
const errorMessage = parseError(approveTxResult.error);
159134

160-
report({
161-
status: "failed",
162-
errorMessage,
135+
reportAssetBuyFailed({
136+
chainId: props.contract.chain.id,
137+
contractType: "DropERC20",
138+
assetType: "coin",
139+
error: errorMessage,
163140
});
164141

165142
toast.error("Failed to approve spending", {
@@ -193,9 +170,11 @@ export function TokenDropClaim(props: {
193170
claim: "error",
194171
});
195172

196-
report({
197-
status: "failed",
198-
errorMessage,
173+
reportAssetBuyFailed({
174+
chainId: props.contract.chain.id,
175+
contractType: "DropERC20",
176+
assetType: "coin",
177+
error: errorMessage,
199178
});
200179

201180
toast.error("Failed to buy tokens", {
@@ -204,8 +183,10 @@ export function TokenDropClaim(props: {
204183
return;
205184
}
206185

207-
report({
208-
status: "successful",
186+
reportAssetBuySuccessful({
187+
chainId: props.contract.chain.id,
188+
contractType: "DropERC20",
189+
assetType: "coin",
209190
});
210191

211192
setStepsUI({

0 commit comments

Comments
 (0)