reducePlacementConfig
The reducePlacementConfig hook allows you to modify placement configuration before htag processes it. This is useful for dynamically adjusting placement settings, adding or modifying bid configurations, or applying conditional logic based on the current environment.
Example
Section titled “Example”window.htag = window.htag || {};window.htag.reducePlacementConfig = function (config) { // Add additional bid configurations for premium placements if (config.elementId.includes('premium')) { return { ...config, bids: [ ...config.bids, { bidder: 'premium-exchange', bidderAlias: 'premium-exchange', params: { publisherId: 'pub123' }, sizes: config.sizes, mediaTypes: config.mediaTypes, geoTargetings: [], geoTargetingMode: 'INCLUDE', }, ], }; }
// Adjust reload timer based on placement type return { ...config, reloadTimer: config.elementId.includes('sidebar') ? 60000 : 30000, };};Parameters
Section titled “Parameters”- config (object): The original placement configuration object
- elementId (string): The ID of the placement element
- mediaTypes (array): Supported media types for this placement
- adUnitPath (string): The ad unit path for Google Ad Manager
- bids (array): Array of bid configurations for different bidders
- sizes (array): Array of ad sizes in format [width, height]
- minWidth (number): Minimum viewport width for this placement
- skipGoogle (boolean): Whether to skip Google Ad Manager
- maxGoogleCpm (number): Maximum CPM threshold for Google
- reloadTimer (number): Auto-refresh interval in milliseconds
- css (string): Custom CSS for the placement
- preloadGroup (string): Group identifier for coordinated loading
- lazyloading (boolean): Whether to use lazy loading
Return Value
Section titled “Return Value”- object: The modified placement configuration object
// ✅ Correct - returns new objectwindow.htag.reducePlacementConfig = function (config) { return { ...config, bids: [...config.bids, newBid], // New array with new bid };};
// ❌ Wrong - modifies original objectwindow.htag.reducePlacementConfig = function (config) { config.bids.push(newBid); // Mutates original array return config;};Related Concepts
Section titled “Related Concepts”- Placements: Learn about placement configuration
- Bid Config Extension: Learn about bidder configuration
- reduceBidRequest: Modify bid requests
- definePlacement: Define new placements
- handlePriorityCreative: Handle priority creative behavior
- handleEmptyGoogle: Handle empty Google responses
- isDisabled: Check if htag is disabled