Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request prebid#72 in AOLP_ADS_JS/prebid.js from feature/Pr…
Browse files Browse the repository at this point in the history
…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
vzhukovsky committed Mar 7, 2017
2 parents a8df144 + e145489 commit 7d32ed1
Show file tree
Hide file tree
Showing 38 changed files with 2,685 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Thank you for your pull request. Please make sure this PR is scoped to one change, and that any added or changed code includes tests with greater than 80% code coverage. See http://prebid.org/dev-docs/testing-prebid.html for documentation on testing Prebid.js.
Thank you for your pull request. Please make sure this PR is scoped to one change, and that any added or changed code includes tests with greater than 80% code coverage. See https://github.com/prebid/Prebid.js/blob/master/CONTRIBUTING.md#testing-prebidjs for documentation on testing Prebid.js.
-->

## Type of change
Expand Down
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"sinon": false,
"beforeEach": false,
"afterEach": false,
"JSON": true
"JSON": true,
"Criteo": true
}
}
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
AOL Prebid 1.13.0
----------------
Updated to Prebid 0.18.0


AOL Prebid 1.12.0
----------------
Updated to Prebid 0.17.0


AOL Prebid 1.11.0
----------------
Added functionality of cookie syncing upon bid response.
Expand Down
84 changes: 82 additions & 2 deletions CONTRIBUTING.md
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/)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ If you experience errors after a version update, try a fresh install:

<a name="Build"></a>

## Build
## Build for Dev

To build the project on your local machine, run:

$ gulp build
$ gulp serve

This runs some code quality checks and generates the following files:
This runs some code quality checks, starts a web server 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
Expand Down Expand Up @@ -124,7 +124,7 @@ Having said that, you are probably safe to check your custom bundle into your pr

<a name="Run"></a>

## Run
## Test locally

To configure Prebid.js to run locally, edit the example file `./integrationExamples/gpt/pbjs_example_gpt.html`:

Expand Down
11 changes: 11 additions & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"pulsepoint",
"rhythmone",
"rubicon",
"smartyads",
"smartadserver",
"sekindoUM",
"sonobi",
"sovrn",
"springserve",
Expand All @@ -35,7 +38,10 @@
"jcm",
"underdogmedia",
"memeglobal",
"criteo",
"centro",
"xhb",
"sharethrough",
"roxot",
"vertoz",
"widespace",
Expand Down Expand Up @@ -68,6 +74,11 @@
"appnexus": {
"alias": "featureforward"
}
},
{
"adkernel": {
"alias": "headbidding"
}
}

]
21 changes: 13 additions & 8 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,12 @@
impid: 36
}
},
{
bidder: 'sekindo',
params: {
spaceId: 14071, // REQUIRED int. To get one, contact http://www.sekindo.com
bidfloor: 0.2 // OPTIONAL float bid floor in $ CPM
}
},
{
bidder: 'sekindoUM',
params: {
spaceId: 14071 // REQUIRED int. To get one, contact http://www.sekindo.com
}
},
{
bidder: 'memeglobal',
params: {
Expand Down Expand Up @@ -226,11 +225,17 @@
}
},
{
bidder: 'widespace',
bidder: 'widespace',
params: {
sid: '7b6589bf-95c8-4656-90b9-af9737bb9ad3',
cur: 'EUR'
}
},
{
bidder: 'smartyads',
params: {
banner_id: 0
}
}
]
}, {
Expand Down
56 changes: 56 additions & 0 deletions integrationExamples/gpt/x-domain/creative.js
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();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prebid.js",
"version": "0.17.0",
"version": "0.18.0",
"description": "Header Bidding Management Library",
"main": "src/prebid.js",
"scripts": {
Expand Down
63 changes: 63 additions & 0 deletions src/adapters/analytics/sharethrough_analytics.js
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;
}
});
Loading

0 comments on commit 7d32ed1

Please sign in to comment.