From 0b63311b65d90bf49a97c7f03a47bd08e50dc621 Mon Sep 17 00:00:00 2001 From: BrickheadJohnny Date: Wed, 5 Mar 2025 20:05:07 +0100 Subject: [PATCH] cleanup: remove unused posthog events --- .../JoinModal/hooks/useMembershipUpdate.tsx | 32 ----------------- .../utils/getGuildPlatformsOfRoles.ts | 26 -------------- src/components/[guild]/forms/FillForm.tsx | 5 --- src/hooks/useCustomPosthogEvents.ts | 36 ++++++++----------- src/hooks/useSetKeyPair.ts | 8 ----- src/rewards/Gather/hooks/useClaimGather.tsx | 4 --- src/rewards/SecretText/hooks/useClaimText.tsx | 13 +------ src/rewards/Token/hooks/useCollectToken.tsx | 6 ---- .../components/FarcasterProfile.tsx | 24 +++---------- 9 files changed, 20 insertions(+), 134 deletions(-) delete mode 100644 src/components/[guild]/JoinModal/utils/getGuildPlatformsOfRoles.ts diff --git a/src/components/[guild]/JoinModal/hooks/useMembershipUpdate.tsx b/src/components/[guild]/JoinModal/hooks/useMembershipUpdate.tsx index eed3e55bbd..62d617bed5 100644 --- a/src/components/[guild]/JoinModal/hooks/useMembershipUpdate.tsx +++ b/src/components/[guild]/JoinModal/hooks/useMembershipUpdate.tsx @@ -1,16 +1,12 @@ -import { usePostHogContext } from "@/components/Providers/PostHogProvider" import type { JoinJob } from "@guildxyz/types" import useGuild from "components/[guild]/hooks/useGuild" import useGuildPermission from "components/[guild]/hooks/useGuildPermission" -import useMembership from "components/explorer/hooks/useMembership" -import useCustomPosthogEvents from "hooks/useCustomPosthogEvents" import { useFetcherWithSign } from "hooks/useFetcherWithSign" import { useGetKeyForSWRWithOptionalAuth } from "hooks/useGetKeyForSWRWithOptionalAuth" import useSubmit from "hooks/useSubmit" import { UseSubmitOptions } from "hooks/useSubmit/types" import { atom, useAtom } from "jotai" import useUsersPoints from "rewards/Points/useUsersPoints" -import { getGuildPlatformsOfRoles } from "../utils/getGuildPlatformsOfRoles" import { mapAccessJobState } from "../utils/mapAccessJobState" import { useActiveMembershipUpdate } from "./useActiveMembershipUpdate" @@ -50,16 +46,6 @@ const useMembershipUpdate = ({ const [currentlyCheckedRoleIds, setCurrentlyCheckedRoleIds] = useAtom( currentlyCheckedRoleIdsAtom ) - const { captureEvent } = usePostHogContext() - const { rewardGranted } = useCustomPosthogEvents() - const posthogOptions = { - guild: guild.urlName, - } - - const { roleIds: accessedRoleIds } = useMembership() - const accessedGuildPlatformIds = new Set( - getGuildPlatformsOfRoles(accessedRoleIds, guild).map(({ id }) => id) - ) const getKeyForSWRWithOptionalAuth = useGetKeyForSWRWithOptionalAuth() @@ -95,23 +81,6 @@ const useMembershipUpdate = ({ correlationId: res.correlationId, }) - if (res?.updateMembershipResult?.newMembershipRoleIds?.length > 0) { - const grantedGuildPlatforms = getGuildPlatformsOfRoles( - res.updateMembershipResult.newMembershipRoleIds, - guild - ) - - const newGuildPlatforms = grantedGuildPlatforms.filter( - ({ id }) => !accessedGuildPlatformIds.has(id) - ) - - if (newGuildPlatforms.length > 0) { - newGuildPlatforms.forEach((newGuildPlatform) => { - rewardGranted(newGuildPlatform.platformId) - }) - } - } - if (res?.roleAccesses?.some((role) => !!role.access)) { // mutate guild in case the user sees more entities due to visibilities if (!isAdmin) guild.mutateGuild() @@ -136,7 +105,6 @@ const useMembershipUpdate = ({ }, onError: (error) => { setIsGettingJob(false) - captureEvent(`Guild join error`, { ...posthogOptions, error }) onError?.(error) }, }) diff --git a/src/components/[guild]/JoinModal/utils/getGuildPlatformsOfRoles.ts b/src/components/[guild]/JoinModal/utils/getGuildPlatformsOfRoles.ts deleted file mode 100644 index 20748e4b2b..0000000000 --- a/src/components/[guild]/JoinModal/utils/getGuildPlatformsOfRoles.ts +++ /dev/null @@ -1,26 +0,0 @@ -import useGuild from "components/[guild]/hooks/useGuild" - -export function getGuildPlatformsOfRoles( - roleIds: number[], - guild: ReturnType -) { - try { - const roleIdsSet = new Set(roleIds) - - const rolePlatforms = guild.roles - .filter((role) => roleIdsSet.has(role.id)) - .flatMap((role) => role.rolePlatforms) - - const guildPlatformIds = new Set( - rolePlatforms.map(({ guildPlatformId }) => guildPlatformId) - ) - - const guildPlatforms = guild.guildPlatforms.filter((guildPlatform) => - guildPlatformIds.has(guildPlatform.id) - ) - - return guildPlatforms - } catch { - return [] - } -} diff --git a/src/components/[guild]/forms/FillForm.tsx b/src/components/[guild]/forms/FillForm.tsx index 5fa8cdba9b..fc5a3af65e 100644 --- a/src/components/[guild]/forms/FillForm.tsx +++ b/src/components/[guild]/forms/FillForm.tsx @@ -6,14 +6,12 @@ import Button from "components/common/Button" import Card from "components/common/Card" import FormErrorMessage from "components/common/FormErrorMessage" import DynamicDevTool from "components/create-guild/DynamicDevTool" -import useCustomPosthogEvents from "hooks/useCustomPosthogEvents" import useShowErrorToast from "hooks/useShowErrorToast" import { useSubmitWithSign } from "hooks/useSubmit" import useToast from "hooks/useToast" import { useState } from "react" import { Controller, FormProvider, UseFormProps, useForm } from "react-hook-form" import { useUserFormSubmission } from "rewards/Forms/hooks/useFormSubmissions" -import { PlatformType } from "types" import fetcher from "utils/fetcher" import { useMembershipUpdate } from "../JoinModal/hooks/useMembershipUpdate" import useGuild from "../hooks/useGuild" @@ -49,8 +47,6 @@ const FillForm = ({ form, method = "POST", ...config }: Props) => { const { mutate: mutateSubmission } = useUserFormSubmission(form) const { triggerMembershipUpdate } = useMembershipUpdate() - const { rewardClaimed } = useCustomPosthogEvents() - const toast = useToast() const showErrorToast = useShowErrorToast() const { onSubmit, isLoading } = useSubmitWithSign( @@ -64,7 +60,6 @@ const FillForm = ({ form, method = "POST", ...config }: Props) => { ), { onSuccess: (res) => { - rewardClaimed(PlatformType.FORM) toast({ status: "success", title: "Successfully submitted form", diff --git a/src/hooks/useCustomPosthogEvents.ts b/src/hooks/useCustomPosthogEvents.ts index 4888091bb0..87e9fb5856 100644 --- a/src/hooks/useCustomPosthogEvents.ts +++ b/src/hooks/useCustomPosthogEvents.ts @@ -24,28 +24,22 @@ export default function useCustomPosthogEvents() { }) }, - rewardGranted(platformId: number) { - captureEvent("reward granted", { - platformName: PlatformType[platformId], - guild: urlName, - userId: id, - }) - }, - rewardClaimed(platformId: number) { - captureEvent("reward claimed", { - platformName: PlatformType[platformId], - guild: urlName, - userId: id, - ...(platformId === PlatformType.CONTRACT_CALL - ? { - $set: { - mintedReward: true, - mintedNFT: true, - }, - } - : {}), - }) + if (platformId === PlatformType.CONTRACT_CALL) { + captureEvent("reward claimed", { + platformName: PlatformType[platformId], + guild: urlName, + userId: id, + ...(platformId === PlatformType.CONTRACT_CALL + ? { + $set: { + mintedReward: true, + mintedNFT: true, + }, + } + : {}), + }) + } }, } as const } diff --git a/src/hooks/useSetKeyPair.ts b/src/hooks/useSetKeyPair.ts index bc8664050c..2ebaf4287c 100644 --- a/src/hooks/useSetKeyPair.ts +++ b/src/hooks/useSetKeyPair.ts @@ -180,14 +180,6 @@ const useSetKeyPair = (submitOptions?: UseSubmitOptions) => { ...submitOptions, onError: (error) => { console.error("setKeyPair error", error) - if ( - error?.code !== RPC_INTERNAL_ERROR_CODE && - error?.code !== "ACTION_REJECTED" - ) { - const trace = error?.stack || new Error().stack - captureEvent(`Failed to set keypair`, { error, trace }) - } - submitOptions?.onError?.(error) }, onSuccess: () => { diff --git a/src/rewards/Gather/hooks/useClaimGather.tsx b/src/rewards/Gather/hooks/useClaimGather.tsx index 4d180b5f6c..ced7488de0 100644 --- a/src/rewards/Gather/hooks/useClaimGather.tsx +++ b/src/rewards/Gather/hooks/useClaimGather.tsx @@ -2,12 +2,10 @@ import { useDisclosure } from "@chakra-ui/react" import useGuild from "components/[guild]/hooks/useGuild" import useJsConfetti from "components/create-guild/hooks/useJsConfetti" import { useClaimedReward } from "hooks/useClaimedReward" -import useCustomPosthogEvents from "hooks/useCustomPosthogEvents" import useShowErrorToast from "hooks/useShowErrorToast" import { SignedValidation, useSubmitWithSign } from "hooks/useSubmit" import { useSWRConfig } from "swr" import useSWRImmutable from "swr/immutable" -import { PlatformType } from "types" import fetcher from "utils/fetcher" type ClaimResponse = { @@ -26,7 +24,6 @@ const useClaimGather = (rolePlatformId: number) => { const triggerConfetti = useJsConfetti() const showErrorToast = useShowErrorToast() - const { rewardClaimed } = useCustomPosthogEvents() const endpoint = `/v2/guilds/${guildId}/roles/${roleId}/role-platforms/${rolePlatformId}/claim` const { data: responseFromCache, mutate: mutateCachedResponse } = useSWRImmutable( @@ -43,7 +40,6 @@ const useClaimGather = (rolePlatformId: number) => { const { onSubmit: onClaimGatherSubmit, ...claim } = useSubmitWithSign(claimFetcher, { onSuccess: (response) => { - rewardClaimed(PlatformType.GATHER_TOWN) triggerConfetti() /** * Saving in SWR cache so we don't need to re-claim the reward if the user diff --git a/src/rewards/SecretText/hooks/useClaimText.tsx b/src/rewards/SecretText/hooks/useClaimText.tsx index e7d7888058..2ec519a355 100644 --- a/src/rewards/SecretText/hooks/useClaimText.tsx +++ b/src/rewards/SecretText/hooks/useClaimText.tsx @@ -15,7 +15,6 @@ import useGuild from "components/[guild]/hooks/useGuild" import ErrorAlert from "components/common/ErrorAlert" import { Modal } from "components/common/Modal" import useJsConfetti from "components/create-guild/hooks/useJsConfetti" -import useCustomPosthogEvents from "hooks/useCustomPosthogEvents" import useShowErrorToast from "hooks/useShowErrorToast" import { SignedValidation, useSubmitWithSign } from "hooks/useSubmit" import { PropsWithChildren } from "react" @@ -33,21 +32,14 @@ type ClaimResponse = { const useClaimText = (rolePlatformId: number) => { const { cache } = useSWRConfig() const { uniqueValue } = useClaimedReward(rolePlatformId) - const { rewardClaimed } = useCustomPosthogEvents() const { isOpen, onOpen, onClose } = useDisclosure() - const { id: guildId, roles, mutateGuild, guildPlatforms } = useGuild() + const { id: guildId, roles, mutateGuild } = useGuild() const roleId = roles.find((role) => role.rolePlatforms.some((rp) => rp.id === rolePlatformId) )?.id - const guildPlatformId = roles - .find((role) => role.id === roleId) - ?.rolePlatforms?.find(({ id }) => id === rolePlatformId)?.guildPlatformId - - const guildPlatform = guildPlatforms.find(({ id }) => id === guildPlatformId) - const triggerConfetti = useJsConfetti() const showErrorToast = useShowErrorToast() @@ -67,9 +59,6 @@ const useClaimText = (rolePlatformId: number) => { claimFetcher, { onSuccess: (response) => { - if (guildPlatform) { - rewardClaimed(guildPlatform.platformId) - } triggerConfetti() /** * Saving in SWR cache so we don't need to re-claim the reward if the user diff --git a/src/rewards/Token/hooks/useCollectToken.tsx b/src/rewards/Token/hooks/useCollectToken.tsx index 2d8555bc18..09f560c051 100644 --- a/src/rewards/Token/hooks/useCollectToken.tsx +++ b/src/rewards/Token/hooks/useCollectToken.tsx @@ -1,13 +1,11 @@ import { usePostHogContext } from "@/components/Providers/PostHogProvider" import useGuild from "components/[guild]/hooks/useGuild" -import useCustomPosthogEvents from "hooks/useCustomPosthogEvents" import { useFetcherWithSign } from "hooks/useFetcherWithSign" import useShowErrorToast from "hooks/useShowErrorToast" import useSubmit from "hooks/useSubmit" import { useToastWithShareButtons } from "hooks/useToastWithShareButtons" import { useState } from "react" import tokenRewardPoolAbi from "static/abis/tokenRewardPool" -import { PlatformType } from "types" import { ERC20_CONTRACTS } from "utils/guildCheckout/constants" import processViemContractError from "utils/processViemContractError" import { TransactionReceipt, WriteContractParameters } from "viem" @@ -41,7 +39,6 @@ const useCollectToken = ( const fetcherWithSign = useFetcherWithSign() const publicClient = usePublicClient() const { data: walletClient } = useWalletClient() - const { rewardClaimed } = useCustomPosthogEvents() const collect = async () => { setLoadingText("Getting signature...") @@ -67,9 +64,6 @@ const useCollectToken = ( return }) .then((res) => { - if (res) { - rewardClaimed(PlatformType.ERC20) - } const data: ClaimResponse = res.data // eslint-disable-next-line @typescript-eslint/naming-convention const [_poolId, _rolePlatformId, _amount, _signedAt, _userId, _signature] = diff --git a/src/v2/components/Account/components/AccountModal/components/FarcasterProfile.tsx b/src/v2/components/Account/components/AccountModal/components/FarcasterProfile.tsx index 49d9cd6a6d..b557777a52 100644 --- a/src/v2/components/Account/components/AccountModal/components/FarcasterProfile.tsx +++ b/src/v2/components/Account/components/AccountModal/components/FarcasterProfile.tsx @@ -1,4 +1,3 @@ -import { usePostHogContext } from "@/components/Providers/PostHogProvider" import { Accordion, AccordionContent, @@ -70,7 +69,6 @@ const ConnectFarcasterButton = ({ children, ...props }: ButtonProps & { onSuccess?: () => void; isReconnection?: boolean }) => { - const { captureEvent } = usePostHogContext() const { farcasterProfiles, id: userId, mutate } = useUser() const { isOpen, onOpen, onClose } = useDisclosure() const { toast } = useToast() @@ -80,7 +78,6 @@ const ConnectFarcasterButton = ({ const getKeyForSWRWithOptionalAuth = useGetKeyForSWRWithOptionalAuth() const onApprove = () => { - captureEvent("[farcaster] request approved") onClose() toast({ variant: "success", @@ -163,13 +160,10 @@ const ConnectFarcasterButton = ({ useEffect(() => { if (seconds > 0) return - - captureEvent("[farcaster] deadline hit") onRegenerate() - }, [seconds, resetCountdown, captureEvent, onRegenerate]) + }, [seconds, resetCountdown, onRegenerate]) const handleOnClose = () => { - captureEvent("[farcaster] connect modal closed") stop() signedKeyRequest.reset() if (pollInterval) { @@ -186,10 +180,7 @@ const ConnectFarcasterButton = ({ return ( <>