Search code examples
prebid.js

Prebid.js isn't passing bid to DFP


I've taken an example from Prebid.js and changed the bidder in the code.

The strange thing is that although I'm having a bid response, it's not passed to DFP through prev_scp param, not rendered and not shown in getAllPrebidWinningBids

pbjs.getBidResponse() returns a bid

pbjs.getAllWinningBids() returns an empty array

pbjs.getAllPrebidWinningBids() returns an empty array

enter image description here

HTML:

        <script async src="//www.googletagservices.com/tag/js/gpt.js"></script>
        <script async src="//acdn.adnxs.com/prebid/not-for-prod/1/prebid.js"></script>
        <script>
            var sizes = [
                [300, 250]
            ];
            var PREBID_TIMEOUT = 1700;

            var adUnits = [{
                code: '/19968336/header-bid-tag-1',
                mediaTypes: {
                    banner: {
                        sizes: sizes
                    }
                },
                bids: [{
                    "bidder": "ix",
                    "params": {
                        "id": "07",
                        "siteId": "272669",
                        "size": [
                            300,
                            250
                        ],
                        "floor": 0.6,
                        "bidfloorcur": "USD"
                    }
                }]
            }];

            // ======== DO NOT EDIT BELOW THIS LINE =========== //
            var googletag = googletag || {};
            googletag.cmd = googletag.cmd || [];
            googletag.cmd.push(function() {
                googletag.pubads().disableInitialLoad();
            });

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

            pbjs.que.push(function() {
                pbjs.addAdUnits(adUnits);
                pbjs.requestBids({
                    bidsBackHandler: initAdserver
                });
            });

            function initAdserver() {
                if (pbjs.initAdserverSet) return;
                pbjs.initAdserverSet = true;
                googletag.cmd.push(function() {
                    pbjs.que.push(function() {
                        pbjs.setTargetingForGPTAsync();
                        googletag.pubads().refresh();
                    });
                });
            }

            setTimeout(function() {
                initAdserver();
            }, PREBID_TIMEOUT);

            googletag.cmd.push(function() {
                googletag.defineSlot('/19968336/header-bid-tag-1', sizes, 'div-1')
                    .addService(googletag.pubads());
                googletag.pubads().enableSingleRequest();
                googletag.enableServices();
            });

        </script>

    </head>

    <body>
        <h2>Basic Prebid.js Example</h2>
        <h5>Div-1</h5>
        <div id='div-1'>
            <script type='text/javascript'>
                googletag.cmd.push(function() {
                    googletag.display('div-1');
                });
            </script>
        </div>
    </body>

What am I missing to make it work?


Solution

  • OK. The problem was with PREBID_TIMEOUT. initAdserver was fired before the auction completed. After increasing the timeout everything worked as expected.