8.45.0 • Published 4 days ago

prebid.js v8.45.0

Weekly downloads
7,810
License
Apache-2.0
Repository
github
Last release
4 days ago

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

8.45.0

4 days ago

8.44.0

11 days ago

8.43.0

18 days ago

8.42.0

28 days ago

8.41.0

1 month ago

8.40.0

2 months ago

8.39.0

2 months ago

8.38.0

2 months ago

8.37.0

2 months ago

8.36.0

2 months ago

8.35.0

3 months ago

8.34.0

3 months ago

8.32.0

3 months ago

8.33.0

3 months ago

8.31.0

3 months ago

8.30.0

4 months ago

8.29.0

4 months ago

8.28.0

4 months ago

8.27.0

5 months ago

8.19.0

6 months ago

8.20.0

6 months ago

8.21.0

6 months ago

8.22.0

6 months ago

8.23.0

6 months ago

8.24.0

5 months ago

8.25.0

5 months ago

8.26.0

5 months ago

8.18.0

7 months ago

8.14.0

7 months ago

8.15.0

7 months ago

8.16.0

7 months ago

8.17.0

7 months ago

8.13.0

8 months ago

8.11.0

8 months ago

8.1.0

10 months ago

8.12.0

8 months ago

8.2.0

10 months ago

7.54.4

9 months ago

7.54.5

8 months ago

7.54.0

10 months ago

7.54.1

10 months ago

7.54.2

10 months ago

7.54.3

9 months ago

8.4.0

9 months ago

8.3.0

10 months ago

8.5.0

9 months ago

8.6.0

9 months ago

7.51.0

11 months ago

8.7.0

9 months ago

8.8.0

9 months ago

7.53.0

11 months ago

8.10.0

8 months ago

8.9.0

8 months ago

8.0.0

10 months ago

7.52.0

11 months ago

7.44.0

1 year ago

7.46.0

1 year ago

7.45.0

1 year ago

7.48.0

12 months ago

7.47.0

12 months ago

7.50.0

11 months ago

7.49.0

12 months ago

7.32.0

1 year ago

7.43.0

1 year ago

7.39.0

1 year ago

7.34.0

1 year ago

7.33.0

1 year ago

7.40.0

1 year ago

7.36.0

1 year ago

7.35.0

1 year ago

7.42.0

1 year ago

7.38.0

1 year ago

7.41.0

1 year ago

7.37.0

1 year ago

7.21.0

2 years ago

7.29.0

1 year ago

7.20.0

2 years ago

7.28.0

1 year ago

7.31.0

1 year ago

7.23.1

1 year ago

7.23.0

1 year ago

7.22.0

2 years ago

7.25.0

1 year ago

7.24.0

1 year ago

7.27.0

1 year ago

7.30.0

1 year ago

7.26.0

1 year ago

7.18.0

2 years ago

7.17.0

2 years ago

7.16.0

2 years ago

7.19.0

2 years ago

7.13.0

2 years ago

7.12.0

2 years ago

7.15.0

2 years ago

7.14.0

2 years ago

7.3.0

2 years ago

6.29.1

2 years ago

6.29.2

2 years ago

6.29.0

2 years ago

6.29.3

2 years ago

6.27.0

2 years ago

7.4.0

2 years ago

7.5.0

2 years ago

6.28.0

2 years ago

6.26.0

2 years ago

7.6.0

2 years ago

7.11.0

2 years ago

6.25.0

2 years ago

7.7.0

2 years ago

7.10.0

2 years ago

7.8.0

2 years ago

7.0.0

2 years ago

7.9.0

2 years ago

7.1.0

2 years ago

7.2.0

2 years ago

6.24.0

2 years ago

6.24.1

2 years ago

6.23.0

2 years ago

6.22.0

2 years ago

6.20.0

2 years ago

6.17.0

2 years ago

6.16.0

2 years ago

5.20.4

2 years ago

6.15.0

2 years ago

6.16.0-pre

2 years ago

6.19.0

2 years ago

6.21.1

2 years ago

6.21.0

2 years ago

6.18.0

2 years ago

6.14.0

2 years ago

6.5.0

2 years ago

6.6.0

2 years ago

6.7.0

2 years ago

5.20.3

2 years ago

5.20.2

2 years ago

5.20.1

2 years ago

6.8.0

2 years ago

6.9.0

2 years ago

6.13.0

2 years ago

6.12.0

2 years ago

6.3.0

2 years ago

6.11.0

2 years ago

6.4.0

2 years ago

6.10.0

2 years ago

6.1.0

2 years ago

6.2.0

2 years ago

5.20.0

2 years ago

6.0.0

2 years ago

5.17.0

3 years ago

5.18.0

3 years ago

5.19.0

3 years ago

5.16.0

3 years ago

5.15.0

3 years ago

5.14.0

3 years ago

5.13.0

3 years ago

5.12.0

3 years ago

5.11.0

3 years ago

5.10.0

3 years ago

5.9.0

3 years ago

5.8.0

3 years ago

4.43.4

3 years ago

5.7.0

3 years ago

4.43.3

3 years ago

5.6.0

3 years ago

5.5.0

3 years ago

5.4.0

3 years ago

4.43.2

3 years ago

5.3.0

3 years ago

5.2.0

3 years ago

4.43.1

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

4.42.1

3 years ago

4.42.0

3 years ago

4.41.0

3 years ago

4.43.0

3 years ago

4.37.0

3 years ago

4.40.0

3 years ago

4.36.0

3 years ago

4.39.0

3 years ago

4.38.0

3 years ago

4.35.0

3 years ago

4.34.0

3 years ago

4.33.0

3 years ago

4.32.0

3 years ago

4.31.0

3 years ago

4.30.0

3 years ago

4.29.0

3 years ago

4.28.0

3 years ago

4.27.0

3 years ago

4.26.0

3 years ago

4.25.0

3 years ago

4.24.0

3 years ago

4.23.0

3 years ago

4.22.0

3 years ago

4.21.0

3 years ago

4.20.0

3 years ago

4.19.0

3 years ago

4.18.0

3 years ago

4.17.0

3 years ago

4.16.0

3 years ago

4.15.0

3 years ago

4.14.0

3 years ago

4.13.0

4 years ago

4.12.0

4 years ago

4.11.0

4 years ago

4.10.0

4 years ago

4.9.0

4 years ago

4.8.0

4 years ago

4.7.0

4 years ago

4.6.0

4 years ago

4.5.0

4 years ago

4.4.0

4 years ago

3.27.1

4 years ago

4.3.0

4 years ago

4.2.0

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.0

4 years ago

3.27.0

4 years ago

3.26.0

4 years ago

3.25.0

4 years ago

3.24.0

4 years ago

3.23.0

4 years ago

3.22.0

4 years ago

3.21.0

4 years ago

3.20.0

4 years ago

3.19.0

4 years ago

3.18.0

4 years ago

3.17.0

4 years ago

3.16.0

4 years ago

3.15.0

4 years ago

3.14.0

4 years ago

3.13.0

4 years ago

3.12.0

4 years ago

3.11.0

4 years ago

3.10.0

4 years ago

3.9.0

4 years ago

3.8.0

4 years ago

3.7.1

4 years ago

3.7.0

4 years ago

2.44.7

4 years ago

3.6.0

4 years ago

2.44.6

4 years ago

3.5.0

4 years ago

2.44.5

4 years ago

2.44.4

4 years ago

3.4.0

4 years ago

2.44.3

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

2.44.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

2.44.1

4 years ago

2.44.0

4 years ago

3.0.0

4 years ago

2.43.0

4 years ago

2.42.0

4 years ago

2.41.0

4 years ago

2.40.0

4 years ago

2.39.0

4 years ago

2.38.0

4 years ago

2.37.0

5 years ago

2.36.0

5 years ago

2.35.0

5 years ago

2.34.0

5 years ago

2.33.0

5 years ago

2.32.0

5 years ago

2.31.0

5 years ago

2.30.0

5 years ago

2.29.0

5 years ago

2.28.0

5 years ago

2.27.0

5 years ago

2.26.0

5 years ago

2.25.0

5 years ago

2.24.0

5 years ago

2.23.0

5 years ago

2.22.0

5 years ago

2.21.0

5 years ago

2.20.0

5 years ago

2.19.0

5 years ago

2.18.0

5 years ago

2.17.0

5 years ago

2.16.0

5 years ago

2.15.0

5 years ago

2.14.0

5 years ago

2.13.0

5 years ago

2.13.0-pre

5 years ago

2.12.0

5 years ago

2.11.0

5 years ago

2.10.0

5 years ago

2.9.0

5 years ago

2.8.0

5 years ago

2.7.0

5 years ago

2.6.0

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.0

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.2.0-pre

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.40.0

5 years ago

1.39.0

5 years ago

1.38.0

5 years ago

1.37.0

5 years ago

1.36.0

5 years ago

1.35.0

5 years ago

1.34.0

5 years ago

1.33.0

5 years ago

1.32.0

5 years ago

1.31.0

5 years ago

1.30.0

5 years ago

1.29.0

6 years ago

1.28.0

6 years ago

1.27.0

6 years ago

1.26.0

6 years ago

1.25.0

6 years ago

0.34.22

6 years ago

1.24.1

6 years ago

1.24.0

6 years ago

1.23.0

6 years ago

1.22.0

6 years ago

0.34.21

6 years ago

1.21.0

6 years ago

0.34.20

6 years ago

1.20.0

6 years ago

0.34.19

6 years ago

1.19.0

6 years ago

0.34.18

6 years ago

1.18.0

6 years ago

1.17.0

6 years ago

0.34.17

6 years ago

1.16.0

6 years ago

0.34.16

6 years ago

1.15.0

6 years ago

0.34.15

6 years ago

1.14.0

6 years ago

0.34.14

6 years ago

1.13.0

6 years ago

0.34.13

6 years ago

1.12.0

6 years ago

0.34.12

6 years ago

1.11.0

6 years ago

0.34.10

6 years ago

1.10.0

6 years ago

1.9.0

6 years ago

0.34.9

6 years ago

1.8.0

6 years ago

0.34.8

6 years ago

0.34.7

6 years ago

1.7.0

6 years ago

0.34.6

6 years ago

1.6.0

6 years ago

0.34.5

6 years ago

1.5.0

6 years ago

0.34.4

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

0.34.3

6 years ago

1.3.0

6 years ago

0.34.2

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.34.1

6 years ago

0.34.0

6 years ago

0.33.0

6 years ago

0.32.0

6 years ago

0.31.0

7 years ago

0.30.1

7 years ago

0.30.0

7 years ago

0.29.0

7 years ago

0.28.0

7 years ago

0.27.1

7 years ago

0.27.0

7 years ago

0.26.1

7 years ago

0.26.0

7 years ago

0.25.0

7 years ago

0.26.0-pre

7 years ago

0.24.1

7 years ago

0.24.0

7 years ago

0.23.1

7 years ago

0.23.0

7 years ago

0.22.2

7 years ago

0.21.0

7 years ago

0.20.0

7 years ago

0.19.0

7 years ago

0.18.0

7 years ago

0.17.0

7 years ago

0.16.0

7 years ago

0.15.2

7 years ago

0.15.1

7 years ago

0.15.0

7 years ago

0.14.0

7 years ago

0.13.1

8 years ago

0.13.0

8 years ago

0.12.0

8 years ago

0.11.0

8 years ago

0.10.0

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.1

8 years ago

0.6.0

8 years ago

0.7.0

8 years ago

0.8.0

8 years ago

0.5.0

8 years ago