@@ -8,7 +8,13 @@ import { AdPixels } from './AdPixels';
8
8
import adRainbow from './assets/ad-rainbow.svg' ;
9
9
import { AdItem , AdsResponse } from './types' ;
10
10
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' ;
12
18
/** ID of the zone to fetch Ads for */
13
19
zoneId : string ;
14
20
/** Mode to render the Ad */
@@ -17,12 +23,13 @@ interface FetchAdOptions {
17
23
placement : string ;
18
24
/** If true, we'll not track it as an impression */
19
25
ignore : boolean ;
26
+ }
27
+
28
+ interface FetchPlaceholderAdOptions {
20
29
/**
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' ;
26
33
}
27
34
28
35
/**
@@ -31,9 +38,9 @@ interface FetchAdOptions {
31
38
* and properly access user-agent and IP.
32
39
*/
33
40
export async function renderAd ( options : FetchAdOptions ) {
34
- const { mode, source = 'live' } = options ;
41
+ const mode = options . source === 'live' ? options . mode : 'classic' ;
35
42
36
- const result = source === 'live' ? await fetchAd ( options ) : getPlaceholderAd ( ) ;
43
+ const result = options . source === 'live' ? await fetchAd ( options ) : getPlaceholderAd ( ) ;
37
44
if ( ! result || ! result . ad . description || ! result . ad . statlink ) {
38
45
return null ;
39
46
}
@@ -56,7 +63,7 @@ async function fetchAd({
56
63
zoneId,
57
64
placement,
58
65
ignore,
59
- } : FetchAdOptions ) : Promise < { ad : AdItem ; ip : string } | null > {
66
+ } : FetchLiveAdOptions ) : Promise < { ad : AdItem ; ip : string } | null > {
60
67
const { ip, userAgent } = getUserAgentAndIp ( ) ;
61
68
62
69
const url = new URL ( `https://srv.buysellads.com/ads/${ zoneId } .json` ) ;
@@ -101,7 +108,8 @@ function getPlaceholderAd(): { ad: AdItem; ip: string } {
101
108
rendering : 'carbon' ,
102
109
smallImage : adRainbow . src ,
103
110
statimp : '' ,
104
- statlink : 'https://www.gitbook.com/solutions/open-source' ,
111
+ statlink :
112
+ 'https://www.gitbook.com/solutions/open-source?utm_campaign=sponsored-content&utm_medium=ad&utm_source=content' ,
105
113
timestamp : Date . now ( ) . toString ( ) ,
106
114
width : '0' ,
107
115
zoneid : '' ,
0 commit comments