Skip to content

Commit fa7c479

Browse files
committed
feat: mixpanel experimentation (wip)
1 parent acb94e9 commit fa7c479

File tree

10 files changed

+281
-30
lines changed

10 files changed

+281
-30
lines changed

web/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,23 @@
4848
"@parcel/watcher": "~2.2.0",
4949
"@types/amqplib": "^0.10.1",
5050
"@types/busboy": "^1.5.0",
51+
"@types/mixpanel-browser": "^2.47.3",
5152
"@types/react": "^18.2.14",
5253
"@types/react-dom": "^18.2.7",
5354
"@types/styled-components": "^5.1.26",
5455
"@typescript-eslint/eslint-plugin": "^5.58.0",
5556
"@typescript-eslint/parser": "^5.61.0",
5657
"@typescript-eslint/utils": "^5.58.0",
5758
"@wagmi/cli": "^1.3.0",
59+
"crypto-browserify": "^3.12.0",
5860
"eslint": "^8.38.0",
5961
"eslint-config-prettier": "^8.8.0",
6062
"eslint-import-resolver-parcel": "^1.10.6",
6163
"eslint-plugin-react": "^7.33.0",
6264
"eslint-plugin-react-hooks": "^4.6.0",
6365
"lru-cache": "^7.18.3",
6466
"parcel": "2.8.3",
67+
"string_decoder": "^1.3.0",
6568
"typescript": "^4.9.5"
6669
},
6770
"dependencies": {
@@ -81,6 +84,7 @@
8184
"ethers": "^5.7.2",
8285
"graphql": "^16.7.1",
8386
"graphql-request": "~6.1.0",
87+
"mixpanel-browser": "^2.47.0",
8488
"moment": "^2.29.4",
8589
"overlayscrollbars": "^2.3.0",
8690
"overlayscrollbars-react": "^0.5.2",

web/src/app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import Cases from "./pages/Cases";
1414
import Dashboard from "./pages/Dashboard";
1515
import Courts from "./pages/Courts";
1616
import DisputeTemplateView from "./pages/DisputeTemplateView";
17+
import mixpanel from "./utils/mixpanel";
1718

1819
const App: React.FC = () => {
20+
mixpanel.track("App");
1921
return (
2022
<StyledComponentsProvider>
2123
<QueryClientProvider>

web/src/components/CasesDisplay/index.tsx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styled from "styled-components";
33
import Search from "./Search";
44
import StatsAndFilters from "./StatsAndFilters";
55
import CasesGrid, { ICasesGrid } from "./CasesGrid";
6+
import useTracking from "../../hooks/useTracking";
67

78
const StyledHR = styled.hr`
89
margin-top: 24px;
@@ -22,26 +23,37 @@ const CasesDisplay: React.FC<ICasesDisplay> = ({
2223
casesPerPage,
2324
title = "Cases",
2425
className,
25-
}) => (
26-
<div {...{ className }}>
27-
<h1>{title}</h1>
28-
<Search />
29-
<StatsAndFilters />
30-
<StyledHR />
31-
{disputes.length > 0 ? (
32-
<CasesGrid
33-
{...{
34-
disputes,
35-
currentPage,
36-
setCurrentPage,
37-
numberDisputes,
38-
casesPerPage,
39-
}}
40-
/>
41-
) : (
42-
<h1>wow no cases</h1>
43-
)}
44-
</div>
45-
);
26+
}) => {
27+
useTracking("CasesDisplay", {
28+
disputes,
29+
currentPage,
30+
setCurrentPage,
31+
numberDisputes,
32+
casesPerPage,
33+
title,
34+
className,
35+
});
36+
return (
37+
<div {...{ className }}>
38+
<h1>{title}</h1>
39+
<Search />
40+
<StatsAndFilters />
41+
<StyledHR />
42+
{disputes.length > 0 ? (
43+
<CasesGrid
44+
{...{
45+
disputes,
46+
currentPage,
47+
setCurrentPage,
48+
numberDisputes,
49+
casesPerPage,
50+
}}
51+
/>
52+
) : (
53+
<h1>wow no cases</h1>
54+
)}
55+
</div>
56+
);
57+
};
4658

4759
export default CasesDisplay;

web/src/components/ConnectWallet/AccountDisplay.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { landscapeStyle } from "styles/landscapeStyle";
44
import { useAccount, useNetwork, useEnsAvatar, useEnsName } from "wagmi";
55
import Identicon from "react-identicons";
66
import { shortenAddress } from "utils/shortenAddress";
7+
import { useIdentify } from "../../hooks/useTracking";
78

89
const Container = styled.div`
910
display: flex;
@@ -119,6 +120,7 @@ export const AddressOrName: React.FC = () => {
119120
address,
120121
chainId: 1,
121122
});
123+
useIdentify(address);
122124
return <label>{data ?? (address && shortenAddress(address))}</label>;
123125
};
124126

web/src/components/ConnectWallet/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { useAccount, useNetwork, useSwitchNetwork } from "wagmi";
33
import { useWeb3Modal } from "@web3modal/react";
44
import { Button } from "@kleros/ui-components-library";
55
import { SUPPORTED_CHAINS, DEFAULT_CHAIN } from "consts/chains";
6+
import useTracking from "../../hooks/useTracking";
67
import AccountDisplay from "./AccountDisplay";
78

89
export const SwitchChainButton: React.FC = () => {
910
const { switchNetwork, isLoading } = useSwitchNetwork();
11+
useTracking("Switch Network");
1012
const handleSwitch = () => {
1113
if (!switchNetwork) {
1214
console.error("Cannot switch network. Please do it manually.");
@@ -36,6 +38,7 @@ const ConnectButton: React.FC = () => {
3638
const ConnectWallet: React.FC = () => {
3739
const { chain } = useNetwork();
3840
const { isConnected } = useAccount();
41+
useTracking("Connect Wallet", { chain });
3942
if (isConnected) {
4043
if (chain && chain.id !== DEFAULT_CHAIN) {
4144
return <SwitchChainButton />;

web/src/hooks/useTracking.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// useTracking.ts
2+
import { useEffect } from "react";
3+
import mixpanel from "../utils/mixpanel";
4+
import crypto from "crypto";
5+
6+
const useTracking = (eventName: string, props?: object) => {
7+
useEffect(() => {
8+
mixpanel.track(eventName, {
9+
pathname: window.location.pathname,
10+
...(props ?? {}),
11+
});
12+
}, [eventName, props]);
13+
};
14+
15+
export const useIdentify = (userId: string | undefined, props?: object) => {
16+
useEffect(() => {
17+
if (userId) {
18+
mixpanel.identify(crypto.createHash("sha256").update(userId).digest("hex"));
19+
}
20+
}, [userId, props]);
21+
};
22+
23+
export default useTracking;

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { uploadFormDataToIPFS } from "utils/uploadFormDataToIPFS";
88
import { useWalletClient, usePublicClient } from "wagmi";
99
import { EnsureChain } from "components/EnsureChain";
1010
import { prepareWriteDisputeKitClassic } from "hooks/contracts/generated";
11+
import mixpanel from "../../../../utils/mixpanel";
1112

1213
const StyledModal = styled(Modal)`
1314
position: absolute;
@@ -82,6 +83,11 @@ const SubmitEvidenceModal: React.FC<{
8283
});
8384
await wrapWithToast(async () => await walletClient.writeContract(request), publicClient).then(
8485
() => {
86+
mixpanel.track("submitEvidence", {
87+
pathname: window.location.pathname,
88+
cid,
89+
evidenceGroup,
90+
});
8591
setMessage("");
8692
close();
8793
}

web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useCourtDetails } from "hooks/queries/useCourtDetails";
1616
import { wrapWithToast } from "utils/wrapWithToast";
1717
import { isUndefined } from "utils/index";
1818
import { EnsureChain } from "components/EnsureChain";
19+
import mixpanel from "../../../../utils/mixpanel";
1920

2021
export enum ActionType {
2122
allowance = "allowance",
@@ -87,6 +88,10 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
8788
wrapWithToast(async () => await increaseAllowance().then((response) => response.hash), publicClient).finally(
8889
() => {
8990
setIsSending(false);
91+
mixpanel.track("increaseAllowance", {
92+
pathname: window.location.pathname,
93+
amount: increaseAllowanceConfig.request.args[1].toString(),
94+
});
9095
}
9196
);
9297
}
@@ -104,6 +109,12 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
104109
.then(() => setIsPopupOpen(true))
105110
.finally(() => {
106111
setIsSending(false);
112+
mixpanel.track("setStake", {
113+
pathname: window.location.pathname,
114+
action: isStaking ? "stake" : "withdraw",
115+
courtId: id,
116+
stakeChange: (isStaking ? "" : "-") + parsedAmount.toString(),
117+
});
107118
});
108119
}
109120
};

web/src/utils/mixpanel.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import mixpanel from "mixpanel-browser";
2+
3+
mixpanel.init(process.env.REACT_APP_MIXPANEL_TOKEN!, {
4+
debug: true,
5+
track_pageview: true,
6+
persistence: "localStorage",
7+
});
8+
9+
export default mixpanel;

0 commit comments

Comments
 (0)