definePlacement
Overview
Section titled “Overview”Define an ad placement on your page. This method configures how ads will be displayed in a specific element on your website.
Example
Section titled “Example”window.htag.api('1').definePlacement({ elementId: 'div-1', mediaTypes: ['BANNER'], adUnitPath: '/123456/site/leaderboard', keywords: [ { key: 'section', values: ['header'] }, { key: 'premium', values: ['true'] }, ], bids: [ { bidder: 'appnexus', bidderAlias: 'appnexus', params: { placementId: '12345' }, sizes: [[728, 90]], mediaTypes: ['BANNER'], geoTargetings: [], geoTargetingMode: 'INCLUDE', }, ], minWidth: 0, sizes: [[728, 90]], skipGoogle: false, preloadGroup: 'group_1', lazyloading: false, renderOptions: { directRenderWrapper: 'div', // Optional: wrap iframe in a div },});Parameters
Section titled “Parameters”- placementConfig (required): An object with the following properties:
- elementId: The ID of the HTML element where the ad will be displayed
- mediaTypes: Array of supported ad formats (e.g., ‘BANNER’, ‘VIDEO’)
- adUnitPath: The ad unit path for Google Ad Manager
- bids: Array of bid configurations for different bidders
- keywords: Array of keyword objects with
keyandvaluesproperties for placement-specific targeting - minWidth: Minimum viewport width for this placement to be active
- sizes: Array of ad sizes for Google Ad Manager in format [width, height]
- css: Custom CSS to apply to the placement
- reloadTimer: Time in milliseconds before the ad is auto refreshed
- skipGoogle: Whether to skip Google Ad Manager
- maxGoogleCpm: If the CPM of the winning bid is higher than this value, the request will not be sent to Google
- preloadGroup: String value for coordinated loading. Placements with identical string values will be loaded together. Empty strings are treated as no group. Case-sensitive.
- lazyloading: Whether to use lazy loading for this placement
- renderOptions: Optional rendering configuration object:
- directRenderWrapper: HTML tag name to wrap the iframe when using direct rendering (e.g., ‘div’, ‘section’)
Return Value
Section titled “Return Value”Returns the Htag API object, allowing for method chaining.
Related Methods
Section titled “Related Methods”- definePlacements: Define multiple placements in bulk using a callback
Related Concepts
Section titled “Related Concepts”- Placements: Learn more about placement configuration
- Lazy Loading: Learn about delayed loading of placements
- Preload Groups: Learn about coordinated loading of placements