Skip to content

Commit a75f640

Browse files
committed
review: revisit render mode and rely on source param for placeholder
1 parent 3e02a46 commit a75f640

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

packages/gitbook/src/components/Ads/Ad.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ export function Ad({
7373

7474
let cancelled = false;
7575

76-
const preview = new URL(window.location.href).searchParams.has('ads_preview');
76+
const previewParam = new URL(window.location.href).searchParams.get('ads_preview');
77+
const preview = !!previewParam && previewParam !== 'placeholder';
7778
const realZoneId = preview ? PREVIEW_ZONE_ID : zoneId;
78-
const adRenderMode =
79-
preview &&
80-
siteAdsStatus &&
81-
(siteAdsStatus === SiteAdsStatus.Pending || siteAdsStatus === SiteAdsStatus.InReview)
82-
? 'placeholder'
83-
: mode;
79+
const showPlaceholderAd =
80+
previewParam === 'placeholder' ||
81+
(siteAdsStatus &&
82+
(siteAdsStatus === SiteAdsStatus.Pending || siteAdsStatus === SiteAdsStatus.InReview))
8483

8584
if (!realZoneId) {
8685
return;
@@ -91,7 +90,8 @@ export function Ad({
9190
placement,
9291
ignore: ignore || preview,
9392
zoneId: realZoneId,
94-
mode: adRenderMode,
93+
mode,
94+
source: showPlaceholderAd ? 'placeholder' : 'live'
9595
});
9696

9797
if (cancelled) {

packages/gitbook/src/components/Ads/renderAd.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ interface FetchAdOptions {
1313
/** ID of the zone to fetch Ads for */
1414
zoneId: string;
1515
/** Mode to render the Ad */
16-
mode: 'classic' | 'auto' | 'cover' | 'placeholder';
16+
mode: 'classic' | 'auto' | 'cover';
1717
/** Name of the placement for the ad */
1818
placement: string;
1919
/** If true, we'll not track it as an impression */
2020
ignore: boolean;
21+
/**
22+
* Source of the ad (live: from the platform, placeholder: static placeholder)
23+
*
24+
* Defaults to live.
25+
* */
26+
source?: 'live' | 'placeholder';
2127
}
2228

2329
/**
@@ -26,9 +32,9 @@ interface FetchAdOptions {
2632
* and properly access user-agent and IP.
2733
*/
2834
export async function renderAd(options: FetchAdOptions) {
29-
const { mode } = options;
35+
const { mode, source = 'live' } = options;
3036

31-
const result = mode !== 'placeholder' ? await fetchAd(options) : getPlaceholderAd();
37+
const result = source === 'live' ? await fetchAd(options) : getPlaceholderAd();
3238
if (!result || !result.ad.description || !result.ad.statlink) {
3339
return null;
3440
}

0 commit comments

Comments
 (0)