Prebid Video Module | Instream Example with VideoJS Submodule

An example of an instream pre-roll ad using the Prebid.js Video Module and the VideoJS submodule.

Important: This example uses a test version of Prebid.js hosted on our CDN that is not recommended for production use. It includes all available adapters. Production implementations should build from source or customize the build using the Download page to make sure only the necessary bidder adapters are included.

Warning: Do not forget to exchange the placementId in the code examples with your own placementId!

Place this code in the page header.

          
          <script async src="//cdn.jsdelivr.net/npm/prebid.js@latest/dist/not-for-prod/prebid.js"></script>
          <link href="https://vjs.zencdn.net/7.20.2/video-js.css" rel="stylesheet" />
          <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.9.0/videojs-contrib-ads.css"
                  integrity="sha512-0gIqgiX1dWTChdWUl8XGIBDFvLo7aTvmd6FAhJjzWx5bzYsCJTiPJLKqLF3q31IN4Kfrc0NbTO+EthoT6O0olQ=="
                  crossorigin="anonymous" referrerpolicy="no-referrer" />
          <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-ima/1.11.0/videojs.ima.css"
                  integrity="sha512-vvsEsf+dZDp6wbommO1Jbb2bpFhVQjw6pIzfE5fUY5Fgkmsgn/16sQWegqrd236T69kK5F1SbGZ+yK46a9il5A=="
                  crossorigin="anonymous" referrerpolicy="no-referrer" />
          <script src="https://vjs.zencdn.net/7.20.2/video.min.js"></script>
          <script src="https://imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.9.0/videojs-contrib-ads.js"
                        integrity="sha512-XjyyAijQGlXZET35toG8igvVs8HvfVgKXGnbfAs2EpZ0o8vjJoIrxL9RBBQbQjzAODIe0jvWelFfZOA3Z/vdWg=="
                        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-ima/1.11.0/videojs.ima.js"
                        integrity="sha512-9ocW9fl8CKJhZp4cmDpLDGPuTQ93gvw1iIS6daMYc5Y0Xh1all8iwdoI+iNmZpiydpdDGyKMTriXDX0wfs2OEg=="
                        crossorigin="anonymous" referrerpolicy="no-referrer"></script>

          <script async src="../../../build/dev/prebid.js"></script>


        <!--This demo configures the video provider to use GAM Ad Server as mediation. Listens to Video events that are fired when an ad impression or ad error came from a bid. -->

        <script>
            // Setup ad units
            var adUnits = [{
                code: 'div-gpt-ad-51545-0',
                mediaTypes: {
                    video: {}
                },
                video: {
                    divId: 'player', // required to indicate which player is being used to render this ad unit.
                },
                bids: [{
                    bidder: 'ix',
                    params: {
                        siteId: '300',
                    }
                }]
            }];

            var pbjs = pbjs || {};
            pbjs.que = pbjs.que || [];

            pbjs.que.push(function () {
                pbjs.setConfig({
                    video: {
                        providers: [{
                            divId: 'player',
                            vendorCode: 2, // videojs vendorCode
                            playerConfig: {
                                params: {
                                    adPluginConfig: {
                                        numRedirects: 10,
                                        adLabel: "Using Prebid Video Module!"
                                    },
                                    vendorConfig: {
                                        controls: true,
                                        autoplay: true,
                                        preload: "auto",
                                    }
                                }
                            },
                            // Configure your Ad Server Integration
                            adServer: {
                                vendorCode: 'gam',
                                baseAdTagUrl: 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_preroll_skippable&sz=640x480&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator='
                            },
                        },]
                    },
                    cache: {
                        url: 'https://prebid.adnxs.com/pbc/v1/cache'
                    },
                    targetingControls: {
                        allowTargetingKeys: ['BIDDER', 'AD_ID', 'PRICE_BUCKET', 'SIZE', 'DEAL', 'SOURCE', 'FORMAT', 'UUID', 'CACHE_ID', 'CACHE_HOST', 'ADOMAIN']
                    },
                });

                pbjs.addAdUnits(adUnits);

                pbjs.onEvent('videoSetupComplete', e => {
                    // Load media with its Metadata when the video player is done instantiating.
                    videojs('player').loadMedia({
                        id: 'XYXYXYXY',
                        src: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/SubaruOutbackOnStreetAndDirt.mp4',
                        title: 'Subaru Outback On Street And Dirt',
                        description: 'Smoking Tire takes the all-new Subaru Outback to the highest point we can find in hopes our customer-appreciation Balloon Launch will get some free T-shirts into the hands of our viewers.',
                        type: 'video/mp4'
                    });
                });

                pbjs.onEvent('videoSetupFailed', e => {
                    console.log('The player setup failed: ', e);
                });

                pbjs.onEvent('videoAdRequest', (e) => {
                    console.log('An ad request was made: ', e);
                });

                pbjs.onEvent('videoBidError', e => {
                    console.log('An Ad Error came from a Bid: ', e);
                });

                pbjs.onEvent('videoBidImpression', e => {
                    console.log('An Ad Impression came from a Bid: ', e);
                });

                pbjs.requestBids(adUnits);
            });
        </script>

                

Place this code in the page body.

                  
                  <div class="example-video-container">
                    <video id="player" class="vjs-big-play-centered"></video>
                  </div>