diff --git a/web/hooks/use-is-iframe.ts b/web/hooks/use-is-iframe.ts index 2ce7eda3..3085fa42 100644 --- a/web/hooks/use-is-iframe.ts +++ b/web/hooks/use-is-iframe.ts @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react' -function inIframe() { +export function inIframe() { try { return window.self !== window.top } catch (e) { diff --git a/web/hooks/use-tracking.ts b/web/hooks/use-tracking.ts index 018e82a0..e62209c0 100644 --- a/web/hooks/use-tracking.ts +++ b/web/hooks/use-tracking.ts @@ -1,8 +1,14 @@ import { track } from '@amplitude/analytics-browser' import { useEffect } from 'react' +import { inIframe } from './use-is-iframe' -export const useTracking = (eventName: string, eventProperties?: any) => { +export const useTracking = ( + eventName: string, + eventProperties?: any, + excludeIframe?: boolean +) => { useEffect(() => { + if (excludeIframe && inIframe()) return track(eventName, eventProperties) }, []) } diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index efc24fa2..de0c7807 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -158,11 +158,15 @@ export function ContractPageContent( const contract = useContractWithPreload(props.contract) ?? props.contract usePrefetch(user?.id) - useTracking('view market', { - slug: contract.slug, - contractId: contract.id, - creatorId: contract.creatorId, - }) + useTracking( + 'view market', + { + slug: contract.slug, + contractId: contract.id, + creatorId: contract.creatorId, + }, + true + ) const bets = useBets(contract.id) ?? props.bets const nonChallengeBets = useMemo( diff --git a/web/pages/embed/[username]/[contractSlug].tsx b/web/pages/embed/[username]/[contractSlug].tsx index 4a94b1db..c5fba0c8 100644 --- a/web/pages/embed/[username]/[contractSlug].tsx +++ b/web/pages/embed/[username]/[contractSlug].tsx @@ -21,6 +21,7 @@ import { SiteLink } from 'web/components/site-link' import { useContractWithPreload } from 'web/hooks/use-contract' import { useMeasureSize } from 'web/hooks/use-measure-size' import { fromPropz, usePropz } from 'web/hooks/use-propz' +import { useTracking } from 'web/hooks/use-tracking' import { listAllBets } from 'web/lib/firebase/bets' import { contractPath, @@ -82,6 +83,12 @@ export function ContractEmbed(props: { contract: Contract; bets: Bet[] }) { const { contract, bets } = props const { question, outcomeType } = contract + useTracking('view market embed', { + slug: contract.slug, + contractId: contract.id, + creatorId: contract.creatorId, + }) + const isBinary = outcomeType === 'BINARY' const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC'