({
postId,
source: postSource,
isCompact = false,
}: AdAsCommentProps)
| 36 | isCompact?: boolean; |
| 37 | } |
| 38 | export const AdAsComment = ({ |
| 39 | postId, |
| 40 | source: postSource, |
| 41 | isCompact = false, |
| 42 | }: AdAsCommentProps): ReactElement => { |
| 43 | const { logEvent } = useLogContext(); |
| 44 | const { user } = useAuthContext(); |
| 45 | const { isPlus } = usePlusSubscription(); |
| 46 | const isAdFree = shouldSkipSourceAds(postSource); |
| 47 | |
| 48 | const { |
| 49 | data: ad, |
| 50 | isFetching, |
| 51 | isRefetching, |
| 52 | } = useAdQuery({ |
| 53 | placement: AdPlacement.PostComment, |
| 54 | queryKey: generateQueryKey(RequestKey.Ads, user, postId), |
| 55 | enabled: !isAdFree, |
| 56 | staleTime: StaleTime.OneHour, |
| 57 | refreshOnPageView: true, |
| 58 | }); |
| 59 | |
| 60 | const onAdAction = useCallback( |
| 61 | (action: AdActions, extra?: Record<string, unknown>) => { |
| 62 | if (!ad) { |
| 63 | return; |
| 64 | } |
| 65 | logEvent( |
| 66 | adLogEvent(action, ad, { |
| 67 | extra: { |
| 68 | origin: 'post page', |
| 69 | ...extra, |
| 70 | }, |
| 71 | }), |
| 72 | ); |
| 73 | }, |
| 74 | [logEvent, ad], |
| 75 | ); |
| 76 | |
| 77 | const onViewable = useCallback( |
| 78 | (data: ViewabilityData) => |
| 79 | onAdAction(AdActions.Viewable, viewabilityLogExtra(data)), |
| 80 | [onAdAction], |
| 81 | ); |
| 82 | |
| 83 | const promotedText = useScrambler( |
| 84 | !ad ? undefined : `Promoted by ${ad.source}`, |
| 85 | ); |
| 86 | |
| 87 | useEffect(() => { |
| 88 | if (!ad || ad?.impressionStatus === ImpressionStatus.LOGGED) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | onAdAction(AdActions.Impression); |
| 93 | ad.impressionStatus = ImpressionStatus.LOGGED; |
| 94 | }, [ad, onAdAction]); |
| 95 |
nothing calls this directly
no test coverage detected