Prebid.js: How do I generate ad markup within a bid adapter?

Created on 28 May 2020  路  2Comments  路  Source: prebid/Prebid.js

Type of issue

question

Description

I'm working on a bid adapter which will receive ad markup which I can't pass back directly within the Prebid bid, since it's a JSON that looks like this:

img: {
    url: 'http://host/static/ad.jpg',
    w: 320,
    h: 50,
    ctaurl: 'http://host/track/ctaurl'
  },
  impressiontrackers: [
    'http://host/track/imp/1',
    'http://host/track/imp/2'
  ],
  clicktrackers: [
    'http://host/track/click/1'
  ]
}

So I'm thinking I will have to generate HTML (an img tag for the ad, pixel images for the impression trackers) and pass it in bid.ad. How would I go about adding event handlers to img tags or setting e.g. .style.display='none'. I'm assuming I can't change the DOM directly and the HTML returned has to be self contained. So would I add JavaScript to my markup that adds event handlers, or would this have to be an iframe?

Would be nice to know if I'm thinking into the right direction or if you could point me to adapters that already do something simular.

question

Most helpful comment

So basically you need a custom 'renderer' to parse the JSON and make something that can be displayed. This is a topic we've discussed, and our draft position is detailed in https://docs.google.com/document/d/1kK0ifXV-vzyV7VchPKoyGuz375H7fzbTJFt_oWeCiRo/edit#

One adapter we're aware of that does something along these lines is astraoneBidAdapter.js. We caution against copying this adapter's approach directly because we're going to make them change it in a future release. (heads up @astraone-ssp ). Specifically, references to external code (https://st.astraone.io/prebidrenderer.js) will have to change so that they're better controlled and transparent.

Below is the most relevant section about loading external code. If you can get away with something lighter and built right into the adapter, that would be better.

  • Modules must not(*) load outside code files unless those libraries are approved and open source.

    • External modules may be used at build-time at the discretion of the relevant Prebid committee. Build-time modules must be locked to a particular version so that any upgrades must be done via Prebid pull request.

    • Exceptions may be made if:

    • The publisher has control over whether the file is loaded and which version. The base module should be able to work without the auxiliary file.

    • If run-time code is not needed for the auction, it should support a deferred load. E.g. User ID modules.

    • The file loaded must be locked to a particular version so that any upgrades must be done via Prebid pull request.

    • A prominent disclosure must be made about the loading of the file, why they need the file, and a size warning if it鈥檚 greater than 10KB.

  • If a functionality is supported by Prebid core or an existing module, Prebid modules must prefer the Prebid version of that functionality rather than an externally coded version.
  • The build-time or run-time loading of required or optional external files must be disclosed. (See the disclosure section below.)

All 2 comments

So basically you need a custom 'renderer' to parse the JSON and make something that can be displayed. This is a topic we've discussed, and our draft position is detailed in https://docs.google.com/document/d/1kK0ifXV-vzyV7VchPKoyGuz375H7fzbTJFt_oWeCiRo/edit#

One adapter we're aware of that does something along these lines is astraoneBidAdapter.js. We caution against copying this adapter's approach directly because we're going to make them change it in a future release. (heads up @astraone-ssp ). Specifically, references to external code (https://st.astraone.io/prebidrenderer.js) will have to change so that they're better controlled and transparent.

Below is the most relevant section about loading external code. If you can get away with something lighter and built right into the adapter, that would be better.

  • Modules must not(*) load outside code files unless those libraries are approved and open source.

    • External modules may be used at build-time at the discretion of the relevant Prebid committee. Build-time modules must be locked to a particular version so that any upgrades must be done via Prebid pull request.

    • Exceptions may be made if:

    • The publisher has control over whether the file is loaded and which version. The base module should be able to work without the auxiliary file.

    • If run-time code is not needed for the auction, it should support a deferred load. E.g. User ID modules.

    • The file loaded must be locked to a particular version so that any upgrades must be done via Prebid pull request.

    • A prominent disclosure must be made about the loading of the file, why they need the file, and a size warning if it鈥檚 greater than 10KB.

  • If a functionality is supported by Prebid core or an existing module, Prebid modules must prefer the Prebid version of that functionality rather than an externally coded version.
  • The build-time or run-time loading of required or optional external files must be disclosed. (See the disclosure section below.)

The originator gave a thumbs up on the explanation, so closing this. Thanks.

Was this page helpful?
0 / 5 - 0 ratings