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

Function useAdQuery

packages/shared/src/features/monetization/useAdQuery.ts:47–134  ·  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

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

Callers 14

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 10

useAdRequestConsentFunction · 0.90
useAdLifecycleFunction · 0.90
useAdSlotFetchFunction · 0.90
useAuthContextFunction · 0.90
useConditionalFeatureFunction · 0.90
useAdPageViewIdFunction · 0.90
useAdEntityRefFunction · 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