• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / #286

07 Mar 2025 06:46PM UTC coverage: 90.439% (-0.01%) from 90.452%
#286

push

travis-ci

prebidjs-release
Prebid 9.34.0 release

42290 of 53025 branches covered (79.75%)

62792 of 69430 relevant lines covered (90.44%)

226.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.23
/modules/debugging/responses.js
1
import {BANNER, NATIVE, VIDEO} from '../../src/mediaTypes.js';
2
import {Renderer} from '../../src/Renderer.js';
3
import {getGptSlotInfoForAdUnitCode} from '../../libraries/gptUtils/gptUtils.js';
4

5
const ORTB_NATIVE_ASSET_TYPES = ['img', 'video', 'link', 'data', 'title'];
1✔
6

7
export default {
8
  [BANNER]: (bid, bidResponse) => {
9
    if (!bidResponse.hasOwnProperty('ad') && !bidResponse.hasOwnProperty('adUrl')) {
18!
10
      let [size, repeat] = (bidResponse.width ?? bidResponse.wratio) < (bidResponse.height ?? bidResponse.hratio) ? [bidResponse.width, 'repeat-y'] : [bidResponse.height, 'repeat-x'];
18!
11
      size = size == null ? '100%' : `${size}px`;
18!
12
      bidResponse.ad = `<html><body><div style="display: inline-block; height: ${bidResponse.height == null ? '100%' : bidResponse.height + 'px'}; width: ${bidResponse.width == null ? '100%' : bidResponse.width + 'px'}; background-image: url(https://vcdn.adnxs.com/p/creative-image/27/c0/52/67/27c05267-5a6d-4874-834e-18e218493c32.png); background-size: ${size}; background-repeat: ${repeat}"></div></body></html>`;
18!
13
    }
14
  },
15
  [VIDEO]: (bid, bidResponse) => {
16
    if (!bidResponse.hasOwnProperty('vastXml') && !bidResponse.hasOwnProperty('vastUrl')) {
×
17
      bidResponse.vastXml = '<?xml version="1.0" encoding="UTF-8"?><VAST version="3.0"><Ad><InLine><AdSystem>GDFP</AdSystem><AdTitle>Demo</AdTitle><Description><![CDATA[Demo]]></Description><Creatives><Creative><Linear ><Duration>00:00:11</Duration><VideoClicks><ClickThrough><![CDATA[https://prebid.org/]]></ClickThrough></VideoClicks><MediaFiles><MediaFile delivery="progressive" width="640" height="360" type="video/mp4" scalable="true" maintainAspectRatio="true"><![CDATA[https://s3.amazonaws.com/files.prebid.org/creatives/PrebidLogo.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>';
×
18
      bidResponse.renderer = Renderer.install({
×
19
        url: 'https://cdn.jwplayer.com/libraries/l5MchIxB.js',
20
      });
21
      bidResponse.renderer.setRender(function (bid, doc) {
×
22
        const parentId = getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId ?? bid.adUnitCode;
×
23
        const div = doc.createElement('div');
×
24
        div.id = `${parentId}-video-player`;
×
25
        doc.getElementById(parentId).appendChild(div);
×
26
        const player = window.jwplayer(div.id).setup({
×
27
          debug: true,
28
          width: bidResponse.width,
29
          height: bidResponse.height,
30
          advertising: {
31
            client: 'vast',
32
            outstream: true,
33
            endstate: 'close'
34
          },
35
        });
36
        player.on('ready', async function () {
×
37
          if (bid.vastUrl) {
×
38
            player.loadAdTag(bid.vastUrl);
×
39
          } else {
40
            player.loadAdXml(bid.vastXml);
×
41
          }
42
        });
43
      })
44
    }
45
  },
46
  [NATIVE]: (bid, bidResponse) => {
47
    if (!bidResponse.hasOwnProperty('native')) {
×
48
      bidResponse.native = {
×
49
        ortb: {
50
          link: {
51
            url: 'https://www.link.example',
52
            clicktrackers: ['https://impression.example']
53
          },
54
          assets: bid.nativeOrtbRequest.assets.map(mapDefaultNativeOrtbAsset)
55
        }
56
      }
57
    }
58
  }
59
}
60

61
function mapDefaultNativeOrtbAsset(asset) {
62
  const assetType = ORTB_NATIVE_ASSET_TYPES.find(type => asset.hasOwnProperty(type));
×
63
  switch (assetType) {
×
64
    case 'img':
65
      return {
×
66
        ...asset,
67
        img: {
68
          type: 3,
69
          w: 600,
70
          h: 500,
71
          url: 'https://vcdn.adnxs.com/p/creative-image/27/c0/52/67/27c05267-5a6d-4874-834e-18e218493c32.png',
72
        }
73
      }
74
    case 'video':
75
      return {
×
76
        ...asset,
77
        video: {
78
          vasttag: '<?xml version=\"1.0\" encoding=\"UTF-8\"?><VAST version=\"3.0\"><Ad><InLine><AdSystem>GDFP</AdSystem><AdTitle>Demo</AdTitle><Description><![CDATA[Demo]]></Description><Creatives><Creative><Linear ><Duration>00:00:11</Duration><VideoClicks><ClickThrough><![CDATA[https://prebid.org/]]></ClickThrough></VideoClicks><MediaFiles><MediaFile delivery=\"progressive\" width=\"640\" height=\"360\" type=\"video/mp4\" scalable=\"true\" maintainAspectRatio=\"true\"><![CDATA[https://s3.amazonaws.com/files.prebid.org/creatives/PrebidLogo.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>'
79
        }
80
      }
81
    case 'data': {
82
      return {
×
83
        ...asset,
84
        data: {
85
          value: '5 stars'
86
        }
87
      }
88
    }
89
    case 'title': {
90
      return {
×
91
        ...asset,
92
        title: {
93
          text: 'Prebid Native Example'
94
        }
95
      }
96
    }
97
  }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc