A header bidding library built on Prebid.js for use to connect to TheTradeDesk's OpenAds service
This README is for developers who want to contribute to OpenAds.js.
Table of Contents
$ git clone https://github.com/OpenAds-Auction/OpenAdsJs.git
$ cd OpenAdsJs
$ npm ci
Note: You need to have NodeJS 12.16.1 or greater installed.
Note: This project uses gulp 4.0. You'll need to have gulp-cli installed globally prior to running npm ci.
If you have a previous version of gulp installed globally, remove it first: npm rm gulp -g
Then install gulp-cli globally: npm install gulp-cli -g
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/openads.js- Full source code for dev and debug./build/dev/openads.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 run:
$ gulp serve
The standard build output contains all the available modules from within the modules folder.
You can specify the modules to be included with the --modules CLI argument.
For example: gulp serve --modules=openadsServerBidAdapter,userId,uid2IdSystem
Build standalone openads.js
-
Clone the repo, run
npm ci -
Then run the build:
$ gulp build --modules=openadsServerBidAdapter,userId,uid2IdSystem
Alternatively, a .json file can be specified that contains a list of modules:
$ gulp build --modules=modules.json
With modules.json containing the following:
[
"openadsServerBidAdapter",
"userId",
"uid2IdSystem"
]Build once, bundle multiple times
If you need to generate multiple distinct bundles from the same version, you can reuse a single build with:
gulp build
gulp bundle --tag one --modules=one.json
gulp bundle --tag two --modules=two.json
You may instruct the build to exclude code for some features:
gulp build --disable NATIVE --modules=openadsServerBidAdapter,userId,uid2IdSystem
Features that can be disabled this way are:
VIDEO- support for video bidsNATIVE- support for native bidsUID2_CSTG- support for UID2 client side token generationGREEDY- disables the use of blocking, "greedy" promisesLOG_NON_ERROR- support for non-error console messagesLOG_ERROR- support for error console messages
You can get a version of the code that's unminified for debugging with build-bundle-dev:
gulp build-bundle-dev --modules=bidderA,module1,...The results will be in build/dev/openads.js.
For compatibility with older parsers or environments that require ES5 syntax, use the --ES5 flag:
gulp build-bundle-dev --modules=bidderA,module1,... --ES5To lint the code:
gulp lintTo run the unit tests:
gulp testTo run the unit tests for a particular file:
gulp test --file "test/spec/modules/openadsServerBidAdapter_spec.js" --nolintTo generate and view the code coverage reports:
gulp test-coverage
gulp view-coverageFor 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/openads.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/openads.js';
var target = document.getElementsByTagName('head')[0];
target.insertBefore(pbs, target.firstChild);
})();Build and run the project locally with:
gulp serveThis 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 openads.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.
We welcome contributions to OpenAdsJs in form of issues and PRs in this repository. If your change applies to both Prebid.js as well as OpenAdsJs, please submit it to the Prebid.js repository as we will pull in relevant upstream changes.
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.
$ gulp test --watch --browsers=chrome
This will run tests and keep the Karma test browser open. If your openads.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.
Prebid.js is supported on IE11 and modern browsers until 5.x. 6.x+ transpiles to target >0.25%; not dead. 11.21+ removes not dead and adds not ios_saf 11.
Review our governance model here.