Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question/Bug?] onBidWon is not called when my adapter won the auction #6026

Closed
sebbes-at-missena opened this issue Nov 24, 2020 · 3 comments
Assignees

Comments

@sebbes-at-missena
Copy link

Type of issue

Question/Bug

Description

I'm building an adapter which defines an onBidWon method. However, this method doesn't seem to be called when the adapter win the auction (in this method, I perform some logs which don't appear at all in the console, even if I have logs telling me I won the auction).

Below are the adapter I have so far and the testing page I use.

// adapter
import * as utils from "../src/utils.js";
// import { config } from '../src/config.js';
import { NATIVE, BANNER } from "../src/mediaTypes.js";
import { registerBidder } from "../src/adapters/bidderFactory.js";

const BIDDER_CODE = "missena";
const ENDPOINT_URL = "http://localhost:1234/";

export const spec = {
  code: BIDDER_CODE,
  aliases: [BIDDER_CODE], // short code
  supportedMediaTypes: [NATIVE, BANNER],
  /**
   * Determines whether or not the given bid request is valid.
   *
   * @param {BidRequest} bid The bid params to validate.
   * @return boolean True if this is a valid bid, and false otherwise.
   */
  isBidRequestValid: function (bid) {
    return typeof bid == "object";
  },

  /**
   * Make a server request from the list of BidRequests.
   *
   * @param {validBidRequests[]} - an array of bids
   * @return ServerRequest Info describing the request to the server.
   */
  buildRequests: function (validBidRequests) {
    utils.logMessage("hallo");
    /* Log when Prebid wins the ad server auction */
    
    return validBidRequests.map((bidRequest) => {
      return {
        method: "POST",
        url: ENDPOINT_URL,        
        data: {requestId: bidRequest.bidId, payload: "hey"},
      };
    });
  },
  /**
   * Unpack the response from the server into a list of bids.
   *
   * @param {ServerResponse} serverResponse A successful response from the server.
   * @return {Bid[]} An array of bids which were nested inside the server.
   */
  interpretResponse: function (serverResponse, bidRequest) {
    // const serverBody  = serverResponse.body;
    // const headerValue = serverResponse.headers.get('some-response-header');
    utils.logMessage(serverResponse);
    const bidResponses = [];
    const bidResponse = serverResponse.body;
    utils.logMessage("response", bidResponse);
    bidResponses.push(bidResponse);
    return bidResponses;
  },

  /**
   * Register the user sync pixels which should be dropped after the auction.
   *
   * @param {SyncOptions} syncOptions Which user syncs are allowed?
   * @param {ServerResponse[]} serverResponses List of server's responses.
   * @return {UserSync[]} The user syncs which should be dropped.
   */
  getUserSyncs: function (
    syncOptions,
    serverResponses,
    gdprConsent,
    uspConsent
  ) {
    const syncs = [];

    var gdprParams;
    if (typeof gdprConsent.gdprApplies === "boolean") {
      gdprParams = `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${
        gdprConsent.consentString
      }`;
    } else {
      gdprParams = `gdpr_consent=${gdprConsent.consentString}`;
    }

    if (syncOptions.iframeEnabled) {
      syncs.push({
        type: "iframe",
        url:
          "//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html?" +
          gdprParams,
      });
    }
    if (syncOptions.pixelEnabled && serverResponses.length > 0) {
      syncs.push({
        type: "image",
        url: serverResponses[0].body.userSync.url + gdprParams,
      });
    }
    return syncs;
  },

  /**
   * Register bidder specific code, which will execute if a bid from this bidder won the auction
   * @param {Bid} The bid that won the auction
   */
  onBidWon: function (bid) {
    utils.logMessage("yeah, I won!");
    utils.logMessage(bid);

  },
};

registerBidder(spec);
<html>
  <head>
    <link rel="icon" type="image/png" href="/favicon.png" />
    <!-- <script async src="//acdn.adnxs.com/prebid/not-for-prod/1/prebid.js"></script> -->
    <script
      type="text/javascript"
      src="../../build/dev/prebid.js"
      async
    ></script>
    <script>
      window.pbjs = window.pbjs || {};
      window.pbjs.que = window.pbjs.que || [];
      var bidCallback = function (bidResponses) {
        console.log("adwdebug bidCallback", bidResponses);
        var winner = pbjs.getAdserverTargetingForAdUnitCode(
          "missena-ad-unit-code"
        );
        var sspWinner = winner["hb_bidder"];
        var cpm = parseFloat(winner["hb_pb"]);
        console.log("winner : ", sspWinner, ", at that price : ", cpm, winner);
      };

      var PREBID_TIMEOUT = 3000;

      var date = new Date().getTime();

      pbjs.que.push(function () {
        pbjs.setConfig({
          debug: true,
          userSync: {
            iframeEnabled: true,
          },
        });

        var adUnits = [
          {
            code: "missena-ad-unit-code",

            mediaTypes: {
              banner: {
                sizes: [80, 80],
              },
            },
            bids: [
              {
                bidder: "missena",
                params: {},
              },
            ],
          },
        ];

        pbjs.addAdUnits(adUnits);
        pbjs.requestBids({
          bidsBackHandler: bidCallback,
        });
      });
    </script>

    <script></script>
  </head>

  <body>
    <h2>Prebid Native</h2>
    <div id="div-1">
      <p>No response</p>
      <script type="text/javascript"></script>
    </div>

    <br />
    <br />

    <div id="div-2">
      <p>No response</p>
    </div>
  </body>
</html>
@fasenderos
Copy link
Contributor

Hi @sebbes-at-missena I'm also developing an adapter (only native support), but ended up at the same point where you are. #6010
I have tried with and without DFP (Post-bid), read all the documentation and asked everywhere (here, stackoverflow, reddit) without success. I hope someone would give us good advices.

If you like we can join forcess and discuss in pvt ( discord? ). Two heads are better than one

@bretg
Copy link
Collaborator

bretg commented Nov 24, 2020

Just to make sure we're on the same page: onBidWon is called on render -- i.e. after the ad server chooses the winner. Specifically, it's called indirectly from pbjs.renderAd and the safeframe version of that function.

With ?pbjs_debug=true, if you see the call to render, then you should see onBidWon() called.

Getting the ad to render means having your line items set up correctly in the ad server. Or if you're using Post-Bid, then calling render yourself.

@bretg bretg self-assigned this Nov 24, 2020
@sebbes-at-missena
Copy link
Author

sebbes-at-missena commented Nov 24, 2020

ok thanks @bretg , I tottally missed the fact I had to call the .renderAd function.

Thank you for you answer!

For the record, here is the updated working html file:

<html>
  <head>
    <link rel="icon" type="image/png" href="/favicon.png" />
    <!-- <script async src="//acdn.adnxs.com/prebid/not-for-prod/1/prebid.js"></script> -->
    <script
      type="text/javascript"
      src="../../build/dev/prebid.js"
      async
    ></script>
    <script>
      window.pbjs = window.pbjs || {};
      window.pbjs.que = window.pbjs.que || [];
      var bidCallback = function (bidResponses) {
        console.log("adwdebug bidCallback", bidResponses);
        var winner = pbjs.getAdserverTargetingForAdUnitCode(
          "missena-ad-unit-code"
        );
        var sspWinner = winner["hb_bidder"];
        var cpm = parseFloat(winner["hb_pb"]);
        console.log("winner : ", sspWinner, ", at that price : ", cpm, winner);

        
        var iframe = document.getElementById('div-1');

        if (winner && winner['hb_adid']) {
            iframe.parentElement.style.position = "relative";
            iframe.style.display = "block";
            pbjs.renderAd(iframe.contentDocument, winner['hb_adid']);
        }
      };

      var PREBID_TIMEOUT = 3000;

      var date = new Date().getTime();

      pbjs.que.push(function () {
        pbjs.setConfig({
          debug: true,
          userSync: {
            iframeEnabled: true,
          },
        });

        var adUnits = [
          {
            code: "missena-ad-unit-code",

            mediaTypes: {
              banner: {
                sizes: [1, 1],
              },
            },
            bids: [
              {
                bidder: "missena",
                params: {},
              },
            ],
          },
        ];

        pbjs.addAdUnits(adUnits);
        pbjs.requestBids({
          bidsBackHandler: bidCallback,
        });
      });
    </script>

    <script></script>
  </head>

  <body>
    <h2>Prebid Native</h2>
    <iframe id="div-1">
      <p>No response</p>
    </iframe>



  </body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants