Giter VIP home page Giter VIP logo

prebid.js's Introduction

Build Status Percentage of issues still open Coverage Status

Prebid.js

A free and open source library for publishers to quickly implement header bidding.

This README is for developers who want to contribute to Prebid.js. Additional documentation can be found at the Prebid homepage. Working examples can be found in the developer docs.

Prebid.js is open source software that is offered for free as a convenience. While it is designed to help companies address legal requirements associated with header bidding, we cannot and do not warrant that your use of Prebid.js will satisfy legal requirements. You are solely responsible for ensuring that your use of Prebid.js complies with all applicable laws. We strongly encourage you to obtain legal advice when using Prebid.js to ensure your implementation complies with all laws where you operate.

Table of Contents

Usage (as a npm dependency)

Note: Requires Prebid.js v1.38.0+

Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for configuring webpack to work with Prebid.js.

With Babel 7:

// webpack.conf.js
let path = require('path');
module.exports = {
  mode: 'production',
  module: {
    rules: [
      
      // this rule can be excluded if you don't require babel-loader for your other application files
      {
        test: /\.m?js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        }
      },
      
      // this separate rule is required to make sure that the Prebid.js files are babel-ified.  this rule will
      // override the regular exclusion from above (for being inside node_modules).
      {
        test: /.js$/,
        include: new RegExp(`\\${path.sep}prebid\\.js`),
        use: {
          loader: 'babel-loader',
          // presets and plugins for Prebid.js must be manually specified separate from your other babel rule.
          // this can be accomplished by requiring prebid's .babelrc.js file (requires Babel 7 and Node v8.9.0+)
          // as of Prebid 6, babelrc.js only targets modern browsers. One can change the targets and build for
          // older browsers if they prefer, but integration tests on ie11 were removed in Prebid.js 6.0
          options: require('prebid.js/.babelrc.js')
        }
      }
    ]
  }
}

Or for Babel 6:

            // you must manually install and specify the presets and plugins yourself
            options: {
              plugins: [
                "transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign" 
                                           // must be installed as part of your package.
                require('prebid.js/plugins/pbjsGlobals.js') // required!
              ],
              presets: [
                ["env", {                 // you can use other presets if you wish.
                  "targets": {            // this example is using "babel-presets-env", which must be installed if you
                    "browsers": [         // follow this example.
                      ... // your browser targets. they should probably match the targets you're using for the rest 
                          // of your application
                    ]
                  }
                }]
              ]
            }

Then you can use Prebid.js as any other npm dependency

import pbjs from 'prebid.js';
import 'prebid.js/modules/rubiconBidAdapter'; // imported modules will register themselves automatically with prebid
import 'prebid.js/modules/appnexusBidAdapter';
pbjs.processQueue();  // required to process existing pbjs.queue blocks and setup any further pbjs.queue execution

pbjs.requestBids({
  ...
})

Install

$ git clone https://github.com/prebid/Prebid.js.git
$ cd Prebid.js
$ npm ci

Note: You need to have NodeJS 12.16.1 or greater installed.

Note: In the 1.24.0 release of Prebid.js we have transitioned to using gulp 4.0 from using gulp 3.9.1. To comply with gulp's recommended setup for 4.0, you'll need to have gulp-cli installed globally prior to running the general npm ci. This shouldn't impact any other projects you may work on that use an earlier version of gulp in its setup.

If you have a previous version of gulp installed globally, you'll need to remove it before installing gulp-cli. You can check if this is installed by running gulp -v and seeing the version that's listed in the CLI field of the output. If you have the gulp package installed globally, it's likely the same version that you'll see in the Local field. If you already have gulp-cli installed, it should be a lower major version (it's at version 2.0.1 at the time of the transition).

To remove the old package, you can use the command: npm rm gulp -g

Once setup, run the following command to globally install the gulp-cli package: npm install gulp-cli -g

Build for Development

To build the project on your local machine we recommend, running:

$ gulp serve-and-test --file <spec_file.js>

This will run testing but not linting. A web server will start at http://localhost:9999 serving from the project root and generates the following files:

  • ./build/dev/prebid.js - Full source code for dev and debug
  • ./build/dev/prebid.js.map - Source map for dev and debug
  • ./build/dev/prebid-core.js
  • ./build/dev/prebid-core.js.map

Development may be a bit slower but if you prefer linting and additional watch files you can also still run just:

$ gulp serve 

Build Optimization

The standard build output contains all the available modules from within the modules folder. Note, however that there are bid adapters which support multiple bidders through aliases, so if you don't see a file in modules for a bid adapter, you may need to grep the repository to find the name of the module you need to include.

You might want to exclude some/most of them from the final bundle. To make sure the build only includes the modules you want, you can specify the modules to be included with the --modules CLI argument.

For example, when running the serve command: gulp serve --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter

Building with just these adapters will result in a smaller bundle which should allow your pages to load faster.

Build standalone prebid.js

  • Clone the repo, run npm ci

  • Then run the build:

      $ gulp build --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter
    

Alternatively, a .json file can be specified that contains a list of modules you would like to include.

$ gulp build --modules=modules.json

With modules.json containing the following

[
  "openxBidAdapter",
  "rubiconBidAdapter",
  "sovrnBidAdapter"
]

Build prebid.js using npm for bundling

In case you'd like to explicitly show that your project uses prebid.js and want a reproducible build, consider adding it as an npm dependency.

  • Add prebid.js as a npm dependency of your project: npm install prebid.js

  • Run the prebid.js build under the node_modules/prebid.js/ folder

      $ gulp build --modules=path/to/your/list-of-modules.json
    

Most likely your custom prebid.js will only change when there's:

  • A change in your list of modules
  • A new release of prebid.js

Having said that, you are probably safe to check your custom bundle into your project. You can also generate it in your build process.

Build once, bundle multiple times

If you need to generate multiple distinct bundles from the same Prebid version, you can reuse a single build with:

gulp build
gulp bundle --tag one --modules=one.json
gulp bundle --tag two --modules=two.json

This generates slightly larger files, but has the advantage of being much faster to run (after the initial gulp build). It's also the method used by the Prebid.org download page.

Excluding particular features from the build

Since version 7.2.0, you may instruct the build to exclude code for some features - for example, if you don't need support for native ads:

gulp build --disable NATIVE --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter # substitute your module list

Or, if you are consuming Prebid through npm, with the disableFeatures option in your Prebid rule:

  {
    test: /.js$/,
    include: new RegExp(`\\${path.sep}prebid\\.js`),
    use: {
      loader: 'babel-loader',
      options: require('prebid.js/babelConfig.js')({disableFeatures: ['NATIVE']})
    }
  }

Note: this is still a work in progress - at the moment, NATIVE is the only feature that can be disabled this way, resulting in a minimal decrease in size (but you can expect that to improve over time).

Test locally

To lint the code:

gulp lint

To lint and only show errors

gulp lint --no-lint-warnings

To run the unit tests:

gulp test

To run the unit tests for a particular file (example for pubmaticBidAdapter_spec.js):

gulp test --file "test/spec/modules/pubmaticBidAdapter_spec.js" --nolint

To generate and view the code coverage reports:

gulp test-coverage
gulp view-coverage

Local end-to-end testing can be done with:

gulp e2e-test --local

For Prebid.org members with access to BrowserStack, additional end-to-end testing can be done with:

gulp e2e-test --host=test.localhost

To run these tests, the following items are required:

  • setup an alias of localhost in your hosts file (eg 127.0.0.1 test.localhost); note - you can use any alias. Use this alias in the command-line argument above.
  • access to BrowserStack account. Assign the following variables in your bash_profile:
export BROWSERSTACK_USERNAME='YourUserNameHere'
export BROWSERSTACK_ACCESS_KEY='YourAccessKeyHere'

You can get these BrowserStack values from your profile page.

For development:

(function() {
    var d = document, pbs = d.createElement('script'), pro = d.location.protocol;
    pbs.type = 'text/javascript';
    pbs.src = ((pro === 'https:') ? 'https' : 'http') + './build/dev/prebid.js';
    var target = document.getElementsByTagName('head')[0];
    target.insertBefore(pbs, target.firstChild);
})();

For deployment:

(function() {
    var d = document, pbs = d.createElement('script'), pro = d.location.protocol;
    pbs.type = 'text/javascript';
    pbs.src = ((pro === 'https:') ? 'https' : 'http') + './build/dist/prebid.js';
    var target = document.getElementsByTagName('head')[0];
    target.insertBefore(pbs, target.firstChild);
})();

Build and run the project locally with:

gulp serve

This runs lint and test, then starts a web server at http://localhost:9999 serving from the project root. Navigate to your example implementation to test, and if your prebid.js file is sourced from the ./build/dev directory you will have sourcemaps available in your browser's developer tools.

To run the example file, go to:

  • http://localhost:9999/integrationExamples/gpt/hello_world.html

As you make code changes, the bundles will be rebuilt and the page reloaded automatically.

Contribute

Many SSPs, bidders, and publishers have contributed to this project. Hundreds of bidders are supported by Prebid.js.

For guidelines, see Contributing.

Our PR review process can be found here.

Add a Bidder Adapter

To add a bidder adapter module, see the instructions in How to add a bidder adapter.

Code Quality

Code quality is defined by .eslintrc and errors are reported in the terminal.

If you are contributing code, you should configure your editor with the provided .eslintrc settings.

Unit Testing with Karma

    $ gulp test --watch --browsers=chrome

This will run tests and keep the Karma test browser open. If your prebid.js file is sourced from the ./build/dev directory you will also have sourcemaps available when using your browser's developer tools.

  • To access the Karma debug page, go to http://localhost:9876/debug.html

  • For test results, see the console

  • To set breakpoints in source code, see the developer tools

Detailed code coverage reporting can be generated explicitly with

    $ gulp test --coverage

The results will be in

    ./build/coverage

Note: Starting in June 2016, all pull requests to Prebid.js need to include tests with greater than 80% code coverage before they can be merged. For more information, see #421.

For instructions on writing tests for Prebid.js, see Testing Prebid.js.

Supported Browsers

Prebid.js is supported on IE11 and modern browsers until 5.x. 6.x+ transpiles to target >0.25%; not Opera Mini; not IE11.

Governance

Review our governance model here.

END

prebid.js's People

Contributors

anand-venkatraman avatar asurovenko-zeta avatar bjorn-lw avatar bretg avatar chrishuie avatar ckbo3hrk avatar dbemiller avatar dependabot[bot] avatar dgirardi avatar fawke avatar genegenie avatar guiann avatar jaiminpanchal27 avatar jbartek25 avatar jongosonobi avatar jsalis avatar jsnellbaker avatar leonardlabat avatar matthewlane avatar matthieularere-msq avatar mkendall07 avatar mmoschovas avatar osazos avatar patmmccann avatar pm-harshad-mane avatar prebidjs-release avatar robertrmartinez avatar smenzer avatar snapwich avatar themediagrid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prebid.js's Issues

New Feature for One-off Calls

As a publisher, I'd like to have one-off calls to certain ad units. For example, I have an interstitial format only after a user has interacted with my site for a bit. I don't need to call it right away, because some users would not stay on the page for that long.

Better Adaptor for Criteo

Anyone with a Criteo pre-bid spec, would love to get the adaptor updated with the latest implementation!

OpenX documentation confusing/different across docs

Taking a look at these urls
https://github.com/prebid/Prebid.js/blob/master/src/adapters/openx.js#L26-L40
https://github.com/prebid/Prebid.js/blob/master/src/adapters/openx.js#L57

Params should be:

    {
        unit: "unit",
        pageURL: "something"
        refererURL: "something"
        jstag_url: "something"
        pgid: "something"
    }

and from the gpt example pgid is missing, is it optional? take a look at the url
https://github.com/prebid/Prebid.js/blob/master/integrationExamples/gpt/pbjs_example_gpt.html#L58-L64

And from bidders page another param appear(auid) and some dissapear? http://prebid.org/bidders.html#openx

If you can point me to the correct one i can help send a PR with the fix to the docs.

No arguments from bidsBackHandler

Even when I get a bid response, this callback gets called with no arguments.

bidsBackHandler: function(bidResponses) {
    console.log(bidResponses); // undefined
    console.log(arguments); // []
    initAdserver();
},

Is this an error in the documentation? Does that callback never get called with arguments?

Misleading docs for downloading script

From reading the docs, it seems you would be able to add that code into your page to load this library. However, https://cdn.site.com/prebid.js isn't a real url, so I guess that this code is more to suggest that if you have a CDN you're using, this is the pattern you could follow. I think this could be made much more explicit, I was definitely confused.

Also, is there a better way to load the most up to date version? Right now it seems like you have to manually download from here and host it yourself.

Help With Implementing OpenX

Hey guys just starting in on this. For the bid params i see pgid ( pageId) and unit (ad unit ID) . Not sure i understand what these are exactly. Ad unit ID im assuming is the DFP ID for the ad unit ?

Adjustment of Price from Bidders

As a publisher, I'd like to adjust the price from bidders to account for the fee, so that what it's bidding reflects what I'd make. This is because some bidders today bid in the gross amount (vs net).

AOL adaptor read sizes from adUnit

Today size still has to be passed into AOL via the params object. However, this can be taken as the first value from the adUnit's sizes array.

Validate bid request params for all the adapters

Each adapter should call a common validation routine with a passed array of required parameters. If all the required parameters are not present in the bid request configuration, the bid request should abort.

Package managers

Any thought of releasing this to a/some package manager(s) (npm, bower, jspm etc...)?

A different type of timeout

As a publisher, I want prebid.js to trigger DFP immediately after the first bid came back after a specified time, so that I can speed up the adserver latency.

Today's setTimeout behavior:

If setTimeout is at 500ms, bidder A took 600ms, bidder B took 800ms, no header bidding happens.

New timeout behavior:

If the "soft" timeout is at 500ms, bidder A took 600ms, bidder B took 800ms, at 500ms, prebid.js will wait until the first bid is back. Thus at 600ms, prebid.js will attach bidder A's bid to the adserver impression and triggers adserver.

To prevent all bids took forever to return, the publisher should still set the normal setTimeout at a number larger than the "soft" timeout, e.g. 700ms in this case.

Bids are caps unclear/inconsistent

  1. why are there different bid caps for granularity levels? If the true bid is $10.37, the granularity levels look like they'll respond with $5, $10.30, and $10.37 respectively. I'm not sure how is this useful, or why as a pub, we'd want this. We just want the $10.37.

  2. is there any particular reason why bids are hard-capped at $20? We regularly break that limit on AdX meaning prebid.js would be handicapping itself regularly with non-competitive bids.

Refresh Bids API call

As a site that caches pre-bid calls, I'd like a new API function to request new rounds of bids for all my bidders, so that my site won't have latency for pre-bid calls.

Creating line items with DFP API

What has been done in looking into making a prebid/LineItemMaker type project that uses DFP's API to generate line items? Prebid.js is great, but it seems like line item creation is still too large of a barrier.

Errors in the prebid que are not reported

If an error gets thrown inside of the prebid que, it does not get bubbled up, so it fails silently and makes debugging harder.

I can add some code examples about how to recreate this if it would be helpful.

IE 9+ Compatability

I'm getting "Invalid calling object" when processQue gets ran. Put in a quick fix, but still getting some cryptic errors when I browser test anything in IE.

exchanges replying with "estimates" or "averages"

As described in the docs for prebid, and on appnexus, some exchanges don't actually respond with their true bid value. Instead, they reply with estimates, ranges, or averages.

This defeats the entire purpose of header bidding. Mathematically, there's little difference in this from the days of waterfalls and line item averages... but now it's implemented manually instead of letting DFP do the work.

_If an exchange does not respond with their true bid value for that impression, they should not be supported_. Alternatively, is there a chart that shows who responds with true bid values, and who doesn't?

Custom Bidder Adaptor Support

As a publisher, I'd like to add my own adaptor for bidders that are not in the list, so that I can either test the adaptor before submitting to Github, or just to keep it to myself.

Amazon adapter removal

I am trying to use Prebid with OpenX, Yieldbot and Amazon A9. I see where the Amazon adapter used to be part of Prebid, but it was removed not long ago. Can you tell us why it was removed?

pubads should not be called as a function if undefined

This conditional

if(!window.googletag || !window.googletag.pubads() || !window.googletag.pubads().getSlots())

does not safely execute. If googletag = {}, then googletag.pubads is undefined. Calling it as a function will throw an error, so the conditional should check that it's a function ahead of time:

(!window.googletag || typeof(window.googletag.pubads) !== 'function' || !window.googletag.pubads() || typeof(window.googletag.pubads().getSlots) !== 'function' || !window.googletag.pubads().getSlots())

404 from haso.pubmatic.com with PubMatic adapter

Hi,

We're testing prebid.org and trying to get it set up to integrate with our PubMatic account.

We see a request go off to http://ads.pubmatic.com/AdServer/js/gshowad.js OK, but that generates a request to, eg:

http://haso.pubmatic.com/ads//GRPBID/index.html?SAVersion=1000&pageURL=&inIframe=1&pubId=&kltstamp=2015-10-20%2018%3A55%3A42&timezone=2&screenResolution=2560x1440&ranreq=0.7003979368600994&adslots=&lmk=1445360142996

...but that results in a 404. Consequently, progKeyValueMap is not populated a JS error results.

Can you suggest what the problem could be here?

Support DFP Premium Same Ad Unit Multiple Slots

As a publisher, I would like Prebid.js to support the case where I have one ad unit reused across multiple slots. For example:

googletag.defineSlot('/1234/Leaderboard', [728, 90], 'div-gpt-ad-5678-2').setTargeting('Position',['bottom']).addService(googletag.pubads());

googletag.defineSlot('/1234/Leaderboard', [[970, 90],[970, 250],[728, 90]], 'div-gpt-ad-5678-3').setTargeting('Position',['top']).addService(googletag.pubads());

(In this case, the same ad unit is served into multiple ad slots)

googletag.defineSlot('/1234/Leaderboard', [728, 90], 'div-gpt-ad-5678-2').setTargeting('Position',['bottom']).addService(googletag.pubads());

googletag.defineSlot('/1234/MobileMediumRectangle', [[300, 250],[320,100]], 'div-gpt-ad-5678-2').setTargeting('Position',['bottom']).addService(googletag.pubads());

(In this case, multiple ad units serve into the same ad slot)

We need to come up with an example to support the above cases.

RequireJS requirement

We're having issues attempting to implement on a site that does not already have RequireJS implemented - could the integration example file be updated to include RequireJS and exaplin for people who do not use it regularly how to implement? As it is now our site breaks when we follow the integration example that is posted...

Adapters for non bidding tags

Hey there,

I was wondering if you could foresee your framework being used, not just for bidding adapters, but also for custom tagging solutions too? IE, we add certain information to DFP calls that are custom to a user/device/journey etc. They may not need to make a request anywhere, just simply add some tags to the DFP call. One example would be that we send certain tags dependent on the users' browser resolution.

Do you think that Prebid.js should really be used just for bidder tags, or can you envisage adding other custom tags? It would make sense to me that amongst your code base you are already doing something like this and it would be nice to keep everything in one place. If so, how would you go about it?

Callback for Bids all back per slot

As a site that has a lot of slots, I want to have a callback for when all bids are returned for every slot (not just for all slots), so that I can respond more quickly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.