This repository has been archived by the owner on Feb 13, 2021. It is now read-only.
forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request prebid#72 in AOLP_ADS_JS/prebid.js from feature/Pr…
…ebid-official-0.18.0 to release/1.13.0 * commit 'e145489bc5dd6d292cf16e7fe80adfdf991562ac': (27 commits) Add changelog entry. Prebid 0.18.0 Release Add Criteo adapter (prebid#928) add an event that fires when requestBids is called (prebid#939) Xaxis adapter submitted by Daniel hoffmann (prebid#938) Add flash detection to TripleLift adapter (prebid#855) OpenX Adapter: Fixed bug regarding cross-domain iframe support (prebid#931) Emit event when setTargetingForGPTAsync is called (prebid#873) Maintenance/refactor hb deal (prebid#935) Reset hb_* keys only for registered aduniits (prebid#934) update code style - smartyads adapter Catch errors in bidsBackHandler. Also fix test cleanup in pbjs api spec. (prebid#905) Smartyads Adapter (prebid#895) Appnexus targeting function (prebid#920) There are 2 changes- (prebid#913) Adding support for all AST parameters (prebid#923) GumGum adapter - include the bid timeout as `tmax` (prebid#908) Add pixel size (prebid#892) enable postMessage listener for cross-domain iframe support (prebid#885) Add Sharethrough adapter (prebid#865) ...
- Loading branch information
Showing
38 changed files
with
2,685 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
"sinon": false, | ||
"beforeEach": false, | ||
"afterEach": false, | ||
"JSON": true | ||
"JSON": true, | ||
"Criteo": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,91 @@ | ||
# Contributing to Prebid.js | ||
Thank you for taking the time to contribute to Prebid.js! | ||
Contributions are always welcome. To contribute, [fork](https://help.github.com/articles/fork-a-repo/) Prebid.js, commit your changes, and [open a pull request](https://help.github.com/articles/using-pull-requests/). | ||
|
||
## Pull Requests | ||
Please make sure that pull requests are scoped to one change, and that any added or changed code includes tests with greater than 80% code coverage. See [Testing Prebid.js](http://prebid.org/dev-docs/testing-prebid.html) for help on writing tests. | ||
Please make sure that pull requests are scoped to one change, and that any added or changed code includes tests with greater than 80% code coverage. See [Testing Prebid.js](#testing-prebidjs) for help on writing tests. | ||
|
||
## Issues | ||
[prebid.org](http://prebid.org/) contains documentation that may help answer questions you have about using Prebid.js. If you can't find the answer there, try searching for a similar issue on the [issues page](https://github.com/prebid/Prebid.js/issues). If you don't find an answer there, [open a new issue](https://github.com/prebid/Prebid.js/issues/new). | ||
|
||
## Documentation | ||
If you have a documentation issue or pull request, please open a ticket or PR in the [documentation repository](https://github.com/prebid/prebid.github.io). | ||
|
||
## Testing Prebid.js | ||
Pull requests to the Prebid.js library will need to include tests with greater than 80% code coverage for any changed/added code before they can be merged into master. | ||
|
||
This section describes how to test code in the Prebid.js repository to help prepare your pull request. | ||
|
||
### Writing tests | ||
When you are adding code to Prebid.js, or modifying code that isn't covered by an existing test, test the code according to these guidelines: | ||
|
||
- If the module you are working on is already partially tested by a file within the `test` directory, add tests to that file | ||
- If the module does not have any tests, create a new test file | ||
- Group tests in a `describe` block | ||
- Test individual units of code within an `it` block | ||
- Within an `it` block, it may be helpful to use the "Arrange-Act-Assert" pattern | ||
- _Arrange_: set up necessary preconditions and inputs | ||
- e.g., creating objects, spies, etc. | ||
- _Act_: call or act on the unit under test | ||
- e.g., call the function you are testing with the parameters you set up | ||
- _Assert_: check that the expected results have occurred | ||
- e.g., use Chai assertions to check that the expected output is equal to the actual output | ||
- Test the public interface, not the internal implementation | ||
- If using global `pbjs` data structures in your test, take care to not completely overwrite them with your own data as that may affect other tests relying on those structures, e.g.: | ||
- **OK**: `pbjs._bidsRequested.push(bidderRequestObject);` | ||
- **NOT OK**: `pbjs._bidsRequested = [bidderRequestObject];` | ||
- If you need to check `adloader.loadScript` in a test, use a `stub` rather than a `spy`. `spy`s trigger a network call which can result in a `script error` and cause unrelated unit tests to fail. `stub`s will let you gather information about the `adloader.loadScript` call without affecting external resources | ||
- When writing tests you may use ES2015 syntax if desired | ||
|
||
### Running tests | ||
After checking out the Prebid.js repository and installing dev dependencies with `npm install`, use the following commands to run tests as you are working on code: | ||
|
||
- `gulp test` will run the test suite once (`npm test` is aliased to call `gulp test`) | ||
- `gulp serve` will run tests once and stay open, re-running tests whenever a file in the `src` or `test` directory is modified | ||
|
||
### Checking results and code coverage | ||
Check the test results using these guidelines: | ||
|
||
- Look at the total number of tests run, passed, and failed in the shell window. | ||
- If all tests are passing, great. | ||
- Otherwise look for errors printed in the console for a description of the failing test. | ||
- You may need to iterate on your code or tests until all tests are passing. | ||
- Make sure existing tests still pass. | ||
- There is a table below the testing report that shows code coverage percentage, for each file under the `src` directory. | ||
- Each time you run tests, a code coverage report is generated in `build/coverage/lcov/lcov-report/index.html`. | ||
- This is a static HTML page that you can load in your browser. | ||
- On that page, navigate to the file you are testing to see which lines are being tested. | ||
- Red indicates that a line isn't covered by a test. | ||
- Gray indicates a line that doesn't need coverage, such as a comment or blank line. | ||
- Green indicates a line that is covered by tests. | ||
- The code you have added or modified must have greater than 80% coverage to be accepted. | ||
|
||
### Examples | ||
Prebid.js already has lots of tests. Read them to see how Prebid.js is tested, and for inspiration: | ||
|
||
- Look in `test/spec` and its subdirectories | ||
- Tests for bidder adaptors are located in `test/spec/adapters` | ||
|
||
A test module might have the following general structure: | ||
|
||
```JavaScript | ||
// import or require modules necessary for the test, e.g.: | ||
import { expect } from 'chai'; // may prefer 'assert' in place of 'expect' | ||
import adapter from 'src/adapters/<adapter>'; | ||
|
||
describe('<Adapter>', () => { | ||
it('<description of unit or feature being tested>', () => { | ||
// Arrange - set up preconditions and inputs | ||
// Act - call or act on the code under test | ||
// Assert - use chai to check that expected results have occurred | ||
}); | ||
|
||
// Add other `describe` or `it` blocks as necessary | ||
}); | ||
``` | ||
|
||
### Resources | ||
The Prebid.js testing stack contains some of the following tools. It may be helpful to consult their documentation during the testing process. | ||
|
||
- [Mocha - test framework](http://mochajs.org/) | ||
- [Chai - BDD/TDD assertion library](http://chaijs.com/) | ||
- [Sinon - spy, stub, and mock library](http://sinonjs.org/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// this script can be returned by an ad server delivering a cross domain iframe, into which the | ||
// creative will be rendered, e.g. DFP delivering a SafeFrame | ||
|
||
// set these domains as fits your environment and ensure matching protocols | ||
// alternatively this can be passed as a macro on the query string of the ad server call, for | ||
// example `%%PUBLISHER_DOMAIN%%`. | ||
const publisherDomain = 'http://localhost:9999'; | ||
const adServerDomain = 'http://tpc.googlesyndication.com'; | ||
|
||
function renderAd(ev) { | ||
var key = ev.message ? 'message' : 'data'; | ||
var adObject = {}; | ||
try { | ||
adObject = JSON.parse(ev[key]); | ||
} catch (e) { | ||
return; | ||
} | ||
|
||
if (adObject.ad || adObject.adUrl) { | ||
var doc = window.document; | ||
var ad = adObject.ad; | ||
var url = adObject.adUrl; | ||
var width = adObject.width; | ||
var height = adObject.height; | ||
|
||
if (adObject.mediaType === 'video') { | ||
console.log('Error trying to write ad.'); | ||
} else | ||
|
||
if (ad) { | ||
doc.write(ad); | ||
doc.close(); | ||
} else if (url) { | ||
doc.write('<IFRAME SRC="' + url + '" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true" WIDTH="' + width + '" HEIGHT="' + height + '"></IFRAME>'); | ||
doc.close(); | ||
} else { | ||
console.log('Error trying to write ad. No ad for bid response id: ' + id); | ||
} | ||
} | ||
} | ||
|
||
function requestAdFromPrebid() { | ||
var message = JSON.stringify({ | ||
message: 'Prebid Request', | ||
adId: '%%PATTERN:hb_adid%%', | ||
adServerDomain | ||
}); | ||
window.parent.postMessage(message, publisherDomain); | ||
} | ||
|
||
function listenAdFromPrebid() { | ||
window.addEventListener('message', renderAd, false); | ||
} | ||
|
||
listenAdFromPrebid(); | ||
requestAdFromPrebid(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import adapter from 'AnalyticsAdapter'; | ||
const utils = require('../../utils'); | ||
|
||
const emptyUrl = ''; | ||
const analyticsType = 'endpoint'; | ||
const STR_BIDDER_CODE = "sharethrough"; | ||
const STR_VERSION = "0.1.0"; | ||
|
||
export default utils.extend(adapter( | ||
{ | ||
emptyUrl, | ||
analyticsType | ||
} | ||
), | ||
{ | ||
STR_BEACON_HOST: document.location.protocol + "//b.sharethrough.com/butler?", | ||
placementCodeSet: {}, | ||
|
||
track({ eventType, args }) { | ||
if(eventType === 'bidRequested' && args.bidderCode === 'sharethrough') { | ||
var bids = args.bids; | ||
var keys = Object.keys(bids); | ||
for(var i = 0; i < keys.length; i++) { | ||
this.placementCodeSet[bids[keys[i]].placementCode] = args.bids[keys[i]]; | ||
} | ||
} | ||
|
||
if(eventType === 'bidWon') { | ||
this.bidWon(args); | ||
} | ||
}, | ||
|
||
bidWon(args) { | ||
const curBidderCode = args.bidderCode; | ||
|
||
if(curBidderCode !== STR_BIDDER_CODE && (args.adUnitCode in this.placementCodeSet)) { | ||
let strBid = this.placementCodeSet[args.adUnitCode]; | ||
this.fireLoseBeacon(curBidderCode, args.cpm, strBid.adserverRequestId, "headerBidLose"); | ||
} | ||
}, | ||
|
||
fireLoseBeacon(winningBidderCode, winningCPM, arid, type) { | ||
let loseBeaconUrl = this.STR_BEACON_HOST; | ||
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, "winnerBidderCode", winningBidderCode); | ||
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, "winnerCpm", winningCPM); | ||
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, "arid", arid); | ||
loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, "type", type); | ||
loseBeaconUrl = this.appendEnvFields(loseBeaconUrl); | ||
|
||
this.fireBeacon(loseBeaconUrl); | ||
}, | ||
appendEnvFields(url) { | ||
url = utils.tryAppendQueryString(url, 'hbVersion', '$prebid.version$'); | ||
url = utils.tryAppendQueryString(url, 'strVersion', STR_VERSION); | ||
url = utils.tryAppendQueryString(url, 'hbSource', 'prebid'); | ||
|
||
return url; | ||
}, | ||
fireBeacon(theUrl) { | ||
const img = new Image(); | ||
img.src = theUrl; | ||
} | ||
}); |
Oops, something went wrong.