Skip to content

Commit 63bacaa

Browse files
authored
Ensure pending or in-review sites still get placeholder ads even without preview query param (#2535)
1 parent e3a3d6a commit 63bacaa

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,22 @@ export function Ad({
8282
(siteAdsStatus === SiteAdsStatus.Pending ||
8383
siteAdsStatus === SiteAdsStatus.InReview));
8484

85-
if (!realZoneId) {
85+
if (!realZoneId && !showPlaceholderAd) {
8686
return;
8787
}
8888

8989
(async () => {
90-
const result = await renderAd({
91-
placement,
92-
ignore: ignore || preview,
93-
zoneId: realZoneId,
94-
mode,
95-
source: showPlaceholderAd ? 'placeholder' : 'live',
96-
});
90+
const result = showPlaceholderAd
91+
? await renderAd({ source: 'placeholder' })
92+
: realZoneId
93+
? await renderAd({
94+
placement,
95+
ignore: ignore || preview,
96+
zoneId: realZoneId,
97+
mode,
98+
source: 'live',
99+
})
100+
: undefined;
97101

98102
if (cancelled) {
99103
return;

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { AdPixels } from './AdPixels';
88
import adRainbow from './assets/ad-rainbow.svg';
99
import { AdItem, AdsResponse } from './types';
1010

11-
interface FetchAdOptions {
11+
type FetchAdOptions = FetchLiveAdOptions | FetchPlaceholderAdOptions;
12+
13+
interface FetchLiveAdOptions {
14+
/**
15+
* Source of the ad (live: from the platform)
16+
*/
17+
source: 'live';
1218
/** ID of the zone to fetch Ads for */
1319
zoneId: string;
1420
/** Mode to render the Ad */
@@ -17,12 +23,13 @@ interface FetchAdOptions {
1723
placement: string;
1824
/** If true, we'll not track it as an impression */
1925
ignore: boolean;
26+
}
27+
28+
interface FetchPlaceholderAdOptions {
2029
/**
21-
* Source of the ad (live: from the platform, placeholder: static placeholder)
22-
*
23-
* Defaults to live.
24-
* */
25-
source?: 'live' | 'placeholder';
30+
* Source of the ad (placeholder: static placeholder ad)
31+
*/
32+
source: 'placeholder';
2633
}
2734

2835
/**
@@ -31,9 +38,9 @@ interface FetchAdOptions {
3138
* and properly access user-agent and IP.
3239
*/
3340
export async function renderAd(options: FetchAdOptions) {
34-
const { mode, source = 'live' } = options;
41+
const mode = options.source === 'live' ? options.mode : 'classic';
3542

36-
const result = source === 'live' ? await fetchAd(options) : getPlaceholderAd();
43+
const result = options.source === 'live' ? await fetchAd(options) : getPlaceholderAd();
3744
if (!result || !result.ad.description || !result.ad.statlink) {
3845
return null;
3946
}
@@ -56,7 +63,7 @@ async function fetchAd({
5663
zoneId,
5764
placement,
5865
ignore,
59-
}: FetchAdOptions): Promise<{ ad: AdItem; ip: string } | null> {
66+
}: FetchLiveAdOptions): Promise<{ ad: AdItem; ip: string } | null> {
6067
const { ip, userAgent } = getUserAgentAndIp();
6168

6269
const url = new URL(`https://srv.buysellads.com/ads/${zoneId}.json`);

0 commit comments

Comments
 (0)