Configure Responsive Ads
The sizeConfig object passed to pbjs.setConfig provides a powerful way to describe types of devices and screens using CSS media queries.
How it works
Before requestBids sends bid requests to adapters, it will evaluate and pick the appropriate label(s) based on the sizeConfig.mediaQuery and device properties and then filter the adUnit.bids array based on the labels defined. Ad units that don’t match the label definition are dropped.
Size config will also operate on adUnit.sizes, however adUnit.sizes is deprecated in favor of adUnit.mediaTypes
					
pbjs.setConfig({
    sizeConfig: [{
        'mediaQuery': '(min-width: 1600px)',
        'sizesSupported': [
            [1000, 300],
            [970, 90],
            [728, 90],
            [300, 250]
        ],
        'labels': ['desktop-hd']
    }, {
        'mediaQuery': '(min-width: 1200px)',
        'sizesSupported': [
            [970, 90],
            [728, 90],
            [300, 250]
        ],
        'labels': ['desktop']
    }, {
        'mediaQuery': '(min-width: 768px) and (max-width: 1199px)',
        'sizesSupported': [
            [728, 90],
            [300, 250]
        ],
        'labels': ['tablet']
    }, {
        'mediaQuery': '(min-width: 0px)',
        'sizesSupported': [
            [300, 250],
            [300, 100]
        ],
        'labels': ['phone']
    }]
});
					
				
Arguments:
  • sizeConfig: array

    An array of objects containing mediaQuery, sizeSupported and label values.

    Accepted Values
    Parameter Type Description Example
    mediaQuery Array An array of objects containing mediaQuery values. 'mediaQuery': '(min-width: 1600px)'
    sizesSupported Array An array of arrays, the contained arrays are comprised of integers for the supported sizes. 'sizesSupported': [ [1000, 300], [970, 90], [728, 90], [300, 250] ],
    labels Array An array of strings defining the display type the publisher's page will appear on. 'labels': ['phone']
Labels
There are two parts to defining responsive and conditional ad units with labels:
  1. Defining the labels.
  2. Defining the conditional ad unit targeting for the labels
Defining the labels
Labels may be defined in two ways:
  • Through sizeConfig
  • As an argument to pbjs.requestBids
    									
    pbjs.requestBids({labels: []});
    									
    								
Targeting labels
Labels may be targeted in the AdUnit structure by two conditional operators: labelAny and labelAll.

With the labelAny operator, just one label has to match for the condition to be true. In the example below, either A or B can be defined in the label array to activate the bid or ad unit:
									
labelAny: ["A", "B"]
									
								
With the labelAll conditional, every element of the target array must match an element of the label array in order for the condition to be true. In the example below, both A and B must be defined in the label array to activate the bid or ad unit:
								
labelAll: ["A", "B"]
								
							
Only one conditional may be specified on a given AdUnit or bid – if both labelAny and labelAll are specified, only the first one will be utilized and an error will be logged to the console. It is allowable for an AdUnit to have one condition and a bid to have another.

If either labeAny or labelAll values is an empty array, it evaluates to true.

It is important to note that labels do not act as filters for sizeConfig. In the example above, using a screen of 1600px wide and labelAll:["desktop"] will not filter out sizes defined in the desktop-hd sizeConfig. Labels in sizeConfig are only used for selecting or de-selecting AdUnits and AdUnit.bids.
Label targeting on the ad unit
								
pbjs.addAdUnits([{
    code: "ad-slot-1",
    mediaTypes: {
        banner: {
            sizes: [
                [970, 90],
                [728, 90],
                [300, 250],
                [300, 100]
            ]
        }
    },
    labelAny: ["visitor-uk"]
    /* The full set of bids, not all of which are relevant on all devices */
    bids: [{
            bidder: "pulsepoint",
            /* Labels flag this bid as relevant only on these screen sizes. */
            labelAny: ["desktop", "tablet"],
            params: {
                "cf": "728X90",
                "cp": 123456,
                "ct": 123456
            }
        },
        {
            bidder: "pulsepoint",
            labelAny: ["desktop", "phone"],
            params: {
                "cf": "300x250",
                "cp": 123456,
                "ct": 123456
            }
        },
        {
            bidder: "sovrn",
            labelAny: ["desktop", "tablet"],
            params: {
                "tagid": "123456"
            }
        },
        {
            bidder: "sovrn",
            labelAny: ["phone"],
            params: {
                "tagid": "111111"
            }
        }
    ]
}]);
								
							
See Conditional Ad Units for additional use cases around labels.
Response
Response Description
{ response: example }
  • param1: string

    String indicating some value that has to be passed as a string type.

  • param2: number

    Number indicating some value that has to be passed as a number type.

    Note: This number should be between 0 and infinity.