definePlacements
Overview
Section titled “Overview”The definePlacements callback method allows you to define multiple ad placements in bulk. This callback is automatically invoked by the configure method when placement data is provided, enabling efficient setup of multiple placements with placement-specific keywords.
Custom Implementation
Section titled “Custom Implementation”The definePlacements callback can be reassigned to implement custom placement workflows. You can customize it to transform configs, add custom logic, or create different placement types based on your needs.
// Custom implementation examplewindow.htag.definePlacements = function (configs, settings) { configs.forEach((config) => { // Transform config based on custom logic const customConfig = { ...config, sizes: config.sizes.filter((size) => size[0] >= 300), keywords: [...(config.keywords || []), { key: 'custom', values: ['processed'] }], }; window.htag.api('1').definePlacement(customConfig); });};Parameters
Section titled “Parameters”-
configs (required): An array of placement configuration objects, each containing:
- 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
- sizes: Array of ad sizes in format [width, height]
- keywords: Array of keyword objects with
keyandvaluesproperties for placement-specific targeting - minWidth: Minimum viewport width for this placement to be active
- skipGoogle: Whether to skip Google Ad Manager
- preloadGroup: String value for coordinated loading
- 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
- All other standard placement configuration options
-
settings: The settings object passed from the configure method
Return Value
Section titled “Return Value”This is a callback function and doesn’t return a value. It processes configurations and sets up placements internally.
Related Methods
Section titled “Related Methods”- definePlacement: Define individual placements manually
- configure: Main configuration method that triggers definePlacements
- refreshAds: Refresh ads after placement changes
Related Concepts
Section titled “Related Concepts”- Placements: Learn more about placement configuration
- Dynamic Placements: Alternative approach for dynamic placement creation