Skip to content

Instantly share code, notes, and snippets.

@mkendall07
Last active September 8, 2015 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkendall07/6ba9968aba4fec275fe3 to your computer and use it in GitHub Desktop.
Save mkendall07/6ba9968aba4fec275fe3 to your computer and use it in GitHub Desktop.

Prebid.js

Setup and manage header bidding advertising partners without writing code or confusing line items. Prebid.js is open source and free.

Many SSPs, bidders, and publishers have all contributed to this project.

Check out the overview and documentation at http://prebid.org.

No more week-long development. Header bidding is made easy by prebid.js :)

Table of Contents

Usage

Download the integration example here.

Example code

Include the prebid.js libraray Note that you need to host prebid.js locally or on a CDN and update the reference in the code snippet below for cdn.host.com/prebid.min.js

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

Setup ad units

pbjs.que.push(function(){
	var adUnits = [{
        code: '{id}',
        sizes: [[300, 250], [300, 600]],
        bids: [
            {
                bidder: 'amazon',
                params: {
                    aid: '{id}'
                }
            },
            {
                bidder: 'appnexus',
                params: {
                    placementId: '{id}'
                }
            }
        ]
    }];
	//add the adUnits
    pbjs.addAdUnits(adUnits);
    }];

Request Bids

pbjs.que.push(function(){
    pbjs.requestBids({
        bidsBackHandler: function(bidResponses) {
            //do stuff when the bids are back
        }
    })
});

Contribute

Add an Bidder Adapter

Follow the guide outlined here to add an adapter.

install

$ sudo npm install

Build

$ gulp build

Configure

Edit ./integrationExamples/gpt/pbjs_example_gpt.html

Change {id} values appropriately

Run

$ gulp serve

Navigate to http://localhost:9999/integrationExamples/gpt/pbjs_example_gpt.html to run the example file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment