track embedded markets separtely

This commit is contained in:
mantikoros 2022-09-06 22:43:28 -05:00
parent a9627bb2b6
commit 85be84071a
4 changed files with 24 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
function inIframe() {
export function inIframe() {
try {
return window.self !== window.top
} catch (e) {

View File

@ -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)
}, [])
}

View File

@ -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(

View File

@ -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'