MCPcopy Create free account
hub / github.com/dailydotdev/apps / useAdQuery

Function useAdQuery

packages/shared/src/features/monetization/useAdQuery.ts:46–127  ·  view source on GitHub ↗
({
  queryKey,
  enabled = true,
  staleTime,
  gcTime,
  placement,
  active,
  retry,
  onTransition,
  refreshOnPageView = false,
  isRefreshable = false,
}: UseAdQueryOptions)

Source from the content-addressed store, hash-verified

44}
45
46export const useAdQuery = ({
47 queryKey,
48 enabled = true,
49 staleTime,
50 gcTime,
51 placement,
52 active,
53 retry,
54 onTransition,
55 refreshOnPageView = false,
56 isRefreshable = false,
57}: UseAdQueryOptions) => {
58 const consent = useAdRequestConsent(enabled);
59 const { resolveAd } = useAdLifecycle(enabled);
60 const onFetchTransition = useAdSlotFetch(consent, onTransition);
61 const { isAuthReady, isLoggedIn, isAndroidApp } = useAuthContext();
62 const { value: refreshEngine, isLoading: isRefreshEngineLoading } =
63 useConditionalFeature({
64 feature: featureAdRefreshEngine,
65 shouldEvaluate: enabled && isRefreshable,
66 });
67 const isRefreshEngine =
68 isRefreshable && refreshEngine === AdRefreshEngineVersion.V2;
69 const registered = isAuthReady ? isLoggedIn : undefined;
70 const pageViewId = useAdPageViewId();
71 const fetchOptions = useMemo(
72 () => ({
73 ...resolveAdFetchOptions({
74 placement,
75 active,
76 consent: consent ?? undefined,
77 registered,
78 pageViewId,
79 }),
80 ...(isRefreshEngine && {
81 refresh: { platform: getAdRefreshPlatform(isAndroidApp), count: 0 },
82 }),
83 }),
84 [
85 placement,
86 active,
87 consent,
88 registered,
89 pageViewId,
90 isRefreshEngine,
91 isAndroidApp,
92 ],
93 );
94
95 return useQuery<Ad | null>({
96 // the page-view id, for page-owned ads, so each page view gets a fresh
97 // ad. It is sent with every request either way. Then the consent
98 // fingerprint so ads refetch when the user answers the CMP banner, and
99 // login state so signing in swaps an anonymous-only ad
100 queryKey: [
101 ...queryKey,
102 ...(refreshOnPageView ? [pageViewId] : []),
103 consent?.gdprApplies,

Callers 13

CommentAdFunction · 0.90
InlineAdFunction · 0.90
SidebarAdFunction · 0.90
useFeedHeroAdFunction · 0.90
AdAsCommentFunction · 0.90
PostSidebarAdWidgetFunction · 0.90
usePromotedSquadFunction · 0.90
useSimilarSquadsFunction · 0.90
SlotFunction · 0.90
useTestAdQueryFunction · 0.90
renderAdQueryFunction · 0.90

Calls 9

useAdRequestConsentFunction · 0.90
useAdLifecycleFunction · 0.90
useAdSlotFetchFunction · 0.90
useAuthContextFunction · 0.90
useConditionalFeatureFunction · 0.90
useAdPageViewIdFunction · 0.90
resolveAdFetchOptionsFunction · 0.90
getAdRefreshPlatformFunction · 0.90
fetchAdByPlacementFunction · 0.90

Tested by 4

SlotFunction · 0.72
useTestAdQueryFunction · 0.72
renderAdQueryFunction · 0.72
renderRefreshableFunction · 0.72