File tree 2 files changed +17
-11
lines changed
packages/gitbook/src/components/Ads
2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -73,14 +73,13 @@ export function Ad({
73
73
74
74
let cancelled = false ;
75
75
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' ;
77
78
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 ) )
84
83
85
84
if ( ! realZoneId ) {
86
85
return ;
@@ -91,7 +90,8 @@ export function Ad({
91
90
placement,
92
91
ignore : ignore || preview ,
93
92
zoneId : realZoneId ,
94
- mode : adRenderMode ,
93
+ mode,
94
+ source : showPlaceholderAd ? 'placeholder' : 'live'
95
95
} ) ;
96
96
97
97
if ( cancelled ) {
Original file line number Diff line number Diff line change @@ -13,11 +13,17 @@ interface FetchAdOptions {
13
13
/** ID of the zone to fetch Ads for */
14
14
zoneId : string ;
15
15
/** Mode to render the Ad */
16
- mode : 'classic' | 'auto' | 'cover' | 'placeholder' ;
16
+ mode : 'classic' | 'auto' | 'cover' ;
17
17
/** Name of the placement for the ad */
18
18
placement : string ;
19
19
/** If true, we'll not track it as an impression */
20
20
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' ;
21
27
}
22
28
23
29
/**
@@ -26,9 +32,9 @@ interface FetchAdOptions {
26
32
* and properly access user-agent and IP.
27
33
*/
28
34
export async function renderAd ( options : FetchAdOptions ) {
29
- const { mode } = options ;
35
+ const { mode, source = 'live' } = options ;
30
36
31
- const result = mode !== 'placeholder ' ? await fetchAd ( options ) : getPlaceholderAd ( ) ;
37
+ const result = source === 'live ' ? await fetchAd ( options ) : getPlaceholderAd ( ) ;
32
38
if ( ! result || ! result . ad . description || ! result . ad . statlink ) {
33
39
return null ;
34
40
}
You can’t perform that action at this time.
0 commit comments