You are here: Publishers > Header bidding solutions > OpenX Bidder > Advanced functions

Bidder advanced functions

Last updated on December 15, 2016

OX.dfp_bidder object

OpenX exposes the OX.dfp_bidder object. Click on the name of a method below for more details and examples of method usage.

Method

Description

OX.dfp_bidder.setOxTargeting(slots)

Returns OpenX key-value pairs defined by OX_dfp_ads. Specific slots can be defined for dynamic inventoryAd space available on a website or app. The basic unit of inventory for OpenX is an ad unit..

This is OpenX's recommended approach to add custom targetingA targeting dimension that describes custom key-value pairs that a publisher defines based on what they know about their visitors. to GPT ad calls.

OX.dfp_bidder.getPriceMap

Returns ad, bid_id, cpm, deal_id, price, and size all mapped slots. The div is used as the key.

OX.dfp_bidder.refresh(callback, [slots]) Refreshes prices from OpenX.

 


OX.dfp_bidder.setOxTargeting(slots)

Note: Due to the simplicity and usefulness of OX.dfp_bidder.setTargeting(slots), this is OpenX’s preferred method to add custom targeting to GPT ad calls.

Without specifying any slots, the setOxTargeting function returns the OpenX key-value pairs for all ad slots defined by OX_dfp_ads.

Example values returned

'oxb','300x250_240'

Usage

Example 1: Non-defined slots

In this example, no ad slotThe area on a web page set aside for the display of ads. is specified for setOxTargeting. This will set an OpenX key-value pair for each of the ad slots defined by OX_dfp_ads. The added if condition prevents an OpenX disruption from preventing ad load.


googletag.defineSlot('/12345/abc/zone1', [728, 90], 'div1').addService(googletag.pubads()); 
googletag.defineSlot('/12345/abc/zone2', [[160, 600],[300,600]], 'div2').addService(googletag.pubads());
if (OX && OX.dfp_bidder) {
   OX.dfp_bidder.setOxTargeting();
}
googletag.enableServices();

Example 2: Defined slots

In this example, slot1 is specified for setOxTargeting. This is will set an OpenX key-value pair for only slot1. Specifying ad slots is useful on pages with dynamic inventory such as responsive design or infinite scroll.


var slot1 = googletag.defineSlot('/12345/abc/zone1', [728, 90], 'div1').addService(googletag.pubads()); 
var slot2 = googletag.defineSlot('/12345/abc/zone2', [[160, 600],[300,600]],'div2').addService(googletag.pubads()); 
if (OX && OX.dfp_bidder) {
   OX.dfp_bidder.setOxTargeting([slot1]);
}
googletag.enableServices();


OX.dfp_bidder.getPriceMap()

Use this function when you want to access the ad, bid_id, cpm, deal_id, price, and size returned by OpenX for all mapped slots. The div name is used as the key. The information returned can be used to pass additional information into the ad call, for example deal_id.

Example values returned

{'div1':{'ad': '<html>', 'bid_id': '575ab12c9d1234', 'cpm': 0.01, 'deal_id': 'OX-Abc-zYxw1', 'price':'5', 'size': '300x250'}}

Usage


var ox_map = OX.dfp_bidder.getPriceMap(); 

googletag.defineSlot('/12345/abc/zone3', [[160, 600],[300,250]], 
  'div3').addService(googletag.pubads()).setTargeting('oxb',ox_map['div3'][ 'size'] + 
  '_' +ox_map['div3']['price']).setTargeting('deal_id',ox_map['div3'][ 'deal_id'];
		


OX.dfp_bidder.refresh(callback,[slots])

Use this function for sites using the googletag.pubads().refresh() function. This method will refresh prices from OpenX before initiating the GPT ad refresh.

Property Type Example Required?
callback Object cb Yes
[slots] String (Array)

var refresh_slots = {

slot1: googletag.defineSlot().addService(googletag.pubads());

slot2: googletag.defineSlot().addService(googletag.pubads());

}

No

Usage

Example 1: Refreshing all slots. In this example, no ad slots are specified for refresh(cb). This will refresh all ad slots defined by OX_dfp_ads.


// refresh all slots:
cb = function() {
   if (OX && OX.dfp_bidder) {
      OX.dfp_bidder.setOxTargeting ();
      googletag.pubads().refresh();
   }
}
OX.dfp_bidder.refresh(cb);

Example 2: Refreshing some slots . In this example, refresh(cb,[slots]) specifies slot1 and slot2. This will refresh only slot1 and slot2.


// refresh some slots:
var refresh_slots = {
   slot1: googletag.defineSlot().addService(googletag.pubads());
   slot2: googletag.defineSlot().addService(googletag.pubads());
}
cb = function() {
   if (OX && OX.dfp_bidder) {
      OX.dfp_bidder.setOxTargeting (refresh_slots)    
      googletag.pubads().refresh(refresh_slots);
   }
} 
OX.dfp_bidder.refresh(cb,refresh_slots);
		

Feedback form