Skip to content

Commit

Permalink
removes google analytics, adds posthog.capture
Browse files Browse the repository at this point in the history
  • Loading branch information
Adebesin-Cell committed Jun 24, 2024
1 parent 112b4b7 commit 0bd3eba
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 143 deletions.
30 changes: 0 additions & 30 deletions src/components/SEO/GoogleAnalyticsScripts.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/client/AppProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { connectors, publicClient, webSocketPublicClient } from '@/config/wagmi'
import { store } from '@/store/store'
import { UALProviderSwitch, WalletProvider } from '@/context/eosWalletContext'
import { DashboardLayout } from '@/components/dashboard/layout'
import GoogleAnalyticsScripts from '@/components/SEO/GoogleAnalyticsScripts'
import chakraTheme from '@/theme'
import { CSPostHogProvider } from './PosthogProvider'

Expand All @@ -32,7 +31,6 @@ const AppProviders = ({ children }: { children: React.ReactNode }) => {
<Fonts />
<WagmiConfig config={client}>
<CSPostHogProvider>
<GoogleAnalyticsScripts />
<UALProviderSwitch>
<WalletProvider>
<DashboardLayout>{children}</DashboardLayout>
Expand Down
24 changes: 8 additions & 16 deletions src/components/client/BridgePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import { IQEosLogo } from '@/components/iq-eos-logo'
import { IQEthLogo } from '@/components/iq-eth-logo'
import { Swap } from '@/components/icons/swap'
import { logEvent } from '@/utils/googleAnalytics'
import { useGetIqPriceQuery } from '@/services/iqPrice'
import { getError } from '@/utils/getError'
import NetworkErrorNotification from '@/components/lock/NetworkErrorNotification'
Expand Down Expand Up @@ -112,7 +111,7 @@ const BridgePage = () => {
const { error } = await bridgeFromPTokenToEth(tokenInputAmount)
if (error) isError = true
showToast(
error || 'Ptokens bridged successfully',
error ?? 'Ptokens bridged successfully',
error ? 'error' : 'success',
)
}
Expand All @@ -126,18 +125,11 @@ const BridgePage = () => {

if (error) isError = true
showToast(
error || 'IQ bridged successfully to EOS',
error ?? 'IQ bridged successfully to EOS',
error ? 'error' : 'success',
)
}

logEvent({
action: isError ? 'TOKEN_BRIDGE_ERROR' : 'TOKEN_BRIDGE_SUCCESS',
label: JSON.stringify(inputAddress),
value: 1,
category: isError ? 'token_bridge_error' : 'token_bridge_success',
})

posthog.capture('bridge_transaction', {
action: isError ? 'TOKEN_BRIDGE_ERROR' : 'TOKEN_BRIDGE_SUCCESS',
label: JSON.stringify(inputAddress),
Expand All @@ -149,7 +141,7 @@ const BridgePage = () => {
}

const getSpecificBalance = (id: TokenId) => {
if (id) return parseInt(balances.find((b) => b.id === id)?.balance || '')
if (id) return parseInt(balances.find(b => b.id === id)?.balance || '')

return 0
}
Expand Down Expand Up @@ -268,8 +260,8 @@ const BridgePage = () => {

useEffect(() => {
if (pIQBalance)
setBalances((currentBalances) =>
currentBalances.map((b) => {
setBalances(currentBalances =>
currentBalances.map(b => {
if (b.id === TokenId.PIQ) b.balance = pIQBalance

return b
Expand All @@ -279,8 +271,8 @@ const BridgePage = () => {

useEffect(() => {
if (iqBalanceOnEth)
setBalances((currentBalances) =>
currentBalances.map((b) => {
setBalances(currentBalances =>
currentBalances.map(b => {
if (b.id === TokenId.IQ) b.balance = iqBalanceOnEth

return b
Expand All @@ -293,7 +285,7 @@ const BridgePage = () => {
const balance = await getUserTokenBalance(authContext)
if (balance)
setBalances(
balances.map((b) => {
balances.map(b => {
if (b.id === TokenId.EOS)
b.balance = balance.toString().replace(' IQ', '')
return b
Expand Down
4 changes: 3 additions & 1 deletion src/components/client/PosthogProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const CSPostHogProvider = ({
)
}

function PosthogAuthWrapper({ children }: React.PropsWithChildren<{}>) {
function PosthogAuthWrapper({
children,
}: Readonly<React.PropsWithChildren<{}>>) {
const { address, connector } = useAccount()

useEffect(() => {
Expand Down
7 changes: 0 additions & 7 deletions src/components/dashboard/Exchanges.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { logEvent } from '@/utils/googleAnalytics'
import { Divider, Flex, Link as ChakraLink, Text } from '@chakra-ui/layout'
import { IconButton } from '@chakra-ui/react'
import Link from 'next/link'
Expand Down Expand Up @@ -30,12 +29,6 @@ const ExchangeLink: React.FC<IconButtonProps> = ({
href={href}
target="_blank"
onClick={() => {
logEvent({
category: 'Dashboard',
action: 'Click',
label: `${logEventLabel}`,
value: 1,
})
posthog.capture('exchange_link_click', {
category: 'Dashboard',
target: logEventLabel,
Expand Down
17 changes: 6 additions & 11 deletions src/components/lock/IncreaseLockTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { useReward } from '@/hooks/useReward'
import { useAccount, useWaitForTransaction } from 'wagmi'
import { calculateReturn } from '@/utils/LockOverviewUtils'
import { Dict } from '@chakra-ui/utils'
import { logEvent } from '@/utils/googleAnalytics'
import { useReusableToast } from '@/hooks/useToast'
import { useLockEnd } from '@/hooks/useLockEnd'
import LockFormCommon from './LockFormCommon'
import LockSlider from '../elements/Slider/LockSlider'
import { usePostHog } from 'posthog-js/react'

const IncreaseLockTime = () => {
const { increaseLockPeriod } = useLock()
Expand All @@ -26,6 +26,7 @@ const IncreaseLockTime = () => {
const { checkPoint } = useReward()
const { data } = useWaitForTransaction({ hash: trxHash })
const { address } = useAccount()
const posthog = usePostHog()

const resetValues = () => {
setLoading(false)
Expand Down Expand Up @@ -89,20 +90,14 @@ const IncreaseLockTime = () => {
const result = await increaseLockPeriod(lockend.getTime())
if (!result) {
showToast('Transaction failed', 'error')
logEvent({
action: 'INCREASE_STAKE_PERIOD_FAILURE',
label: JSON.stringify(address),
value: 0,
category: 'increase_stake_period_failure',
posthog.capture('increase_stake_period_failure', {
userAddress: address,
})
setLoading(false)
return
}
logEvent({
action: 'INCREASE_STAKE_PERIOD_SUCCESS',
label: JSON.stringify(address),
value: 1,
category: 'increase_stake_period_success',
posthog.capture('increase_stake_period_success', {
userAddress: address,
})
setTrxHash(result.hash)
} catch (err) {
Expand Down
11 changes: 5 additions & 6 deletions src/components/lock/LockedDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import * as Humanize from 'humanize-plus'
import { useReward } from '@/hooks/useReward'
import { useAccount, useWaitForTransaction } from 'wagmi'
import { Dict } from '@chakra-ui/utils'
import { logEvent } from '@/utils/googleAnalytics'
import { useGetIqPriceQuery } from '@/services/iqPrice'
import { useReusableToast } from '@/hooks/useToast'
import { useLockEnd } from '@/hooks/useLockEnd'
Expand All @@ -23,6 +22,7 @@ import StakeHeader from '../elements/stakeCommon/StakeHeader'
import TooltipElement from '../elements/Tooltip/TooltipElement'
import ClaimModal from './ClaimWarningModal'
import { CLAIM_WARNING_THRESHOLD } from '@/data/LockConstants'
import { usePostHog } from 'posthog-js/react'

const LockedDetails = ({
setOpenUnlockNotification,
Expand Down Expand Up @@ -59,6 +59,7 @@ const LockedDetails = ({
const { showToast } = useReusableToast()
const [isModalOpen, setIsModalOpen] = useState(false)
const closeModal = () => setIsModalOpen(false)
const posthog = usePostHog()

useEffect(() => {
const resolveReward = async () => {
Expand Down Expand Up @@ -116,11 +117,9 @@ const LockedDetails = ({
try {
const result = await resultAction()
setTrxHash(result.hash)
logEvent({
action: logAction,
label: JSON.stringify(address),
value: 1,
category: logAction.toLocaleLowerCase(),
posthog.capture(logAction.toLocaleLowerCase(), {
category: 'lock',
userAddress: address,
})
if (logAction === 'CLAIM_REWARD' && result) {
setHasClaimed(true)
Expand Down
30 changes: 3 additions & 27 deletions src/components/lock/StakeIQ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useAccount, useWaitForTransaction } from 'wagmi'
import { useLockOverview } from '@/hooks/useLockOverview'
import { useReward } from '@/hooks/useReward'
import { Dict } from '@chakra-ui/utils'
import { logEvent } from '@/utils/googleAnalytics'
import { useReusableToast } from '@/hooks/useToast'
import { useLockEnd } from '@/hooks/useLockEnd'
import LockFormCommon from './LockFormCommon'
Expand Down Expand Up @@ -138,12 +137,7 @@ const StakeIQ = ({ exchangeRate }: { exchangeRate: number }) => {
const result = await increaseLockAmount(iqToBeLocked)
if (!result) {
showToast('Transaction failed', 'error')
logEvent({
action: 'INCREASE_STAKE_FAILURE',
label: JSON.stringify(address),
value: 0,
category: 'increase_stake_failure',
})

posthog.capture('INCREASE_STAKE_FAILURE', {
action: 'INCREASE_STAKE_FAILURE',
userId: address,
Expand All @@ -160,12 +154,6 @@ const StakeIQ = ({ exchangeRate }: { exchangeRate: number }) => {
setLoading(false)
return
}
logEvent({
action: 'INCREASE_STAKE_SUCCESS',
label: JSON.stringify(address),
value: 1,
category: 'increase_stake_success',
})
posthog.capture('INCREASE_STAKE_SUCCESS', {
action: 'INCREASE_STAKE_SUCCESS',
userId: address,
Expand All @@ -186,12 +174,6 @@ const StakeIQ = ({ exchangeRate }: { exchangeRate: number }) => {
const result = await lockIQ(iqToBeLocked, lockValue)
if (!result) {
showToast('Transaction failed', 'error')
logEvent({
action: 'STAKE_FAILURE',
label: JSON.stringify(address),
value: 0,
category: 'stake_failure',
})
posthog.capture('STAKE_FAILURE', {
action: 'STAKE_FAILURE',
userId: address,
Expand All @@ -208,12 +190,6 @@ const StakeIQ = ({ exchangeRate }: { exchangeRate: number }) => {
setLoading(false)
return
}
logEvent({
action: 'STAKE_SUCCESS',
label: JSON.stringify(address),
value: 1,
category: 'stake_success',
})
posthog.capture('STAKE_SUCCESS', {
action: 'STAKE_SUCCESS',
userId: address,
Expand Down Expand Up @@ -280,7 +256,7 @@ const StakeIQ = ({ exchangeRate }: { exchangeRate: number }) => {
<Flex align="center" gap="2.5" w="full">
<Input
variant="unstyled"
onChange={(e) => updateIqToBeLocked(e.target.value)}
onChange={e => updateIqToBeLocked(e.target.value)}
placeholder="23.00"
value={userInput}
color="fadedText4"
Expand All @@ -306,7 +282,7 @@ const StakeIQ = ({ exchangeRate }: { exchangeRate: number }) => {
</Flex>
</VStack>
{userTotalIQLocked < 1 && (
<LockSlider updateLockend={(newDate) => updateLockend(newDate)} />
<LockSlider updateLockend={newDate => updateLockend(newDate)} />
)}
<IconButton
icon={<RiArrowDownLine />}
Expand Down
21 changes: 6 additions & 15 deletions src/components/wallet/WalletConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { FocusableElement } from '@chakra-ui/utils'
import { RiCloseLine } from 'react-icons/ri'
import { useConnect, Connector } from 'wagmi'
import { WALLET_LOGOS } from '@/data/WalletData'
import { logEvent } from '@/utils/googleAnalytics'
import { usePostHog } from 'posthog-js/react'

const WalletConnect = ({
Expand All @@ -26,19 +25,17 @@ const WalletConnect = ({
const posthog = usePostHog()
const { connectors, connect } = useConnect({
onError(error) {
logEvent({
posthog.capture('LOGIN_ERROR', {
action: 'LOGIN_ERROR',
label: error.message,
value: 0,
category: 'login_status',
errorReason: error.message,
category: 'connectors',
})
},
onSuccess(data) {
logEvent({
posthog.capture('LOGIN_SUCCESS', {
action: 'LOGIN_SUCCESS',
label: JSON.stringify(data.account),
value: 1,
category: 'login_status',
userAddress: data.account,
category: 'connectors',
})
const w = window as any
w.gtag('config', process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS, {
Expand All @@ -49,12 +46,6 @@ const WalletConnect = ({
})

const handleConnect = (selectedConnector: Connector) => {
logEvent({
action: 'LOGIN_ATTEMPT',
label: selectedConnector.name,
value: 1,
category: 'connectors',
})
posthog.capture('LOGIN_ATTEMPT', {
action: 'LOGIN_ATTEMPT',
label: selectedConnector.name,
Expand Down
28 changes: 0 additions & 28 deletions src/utils/googleAnalytics.ts

This file was deleted.

0 comments on commit 0bd3eba

Please sign in to comment.