Skip to content

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.

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,
};
};
  • 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
  • object: The modified placement configuration object
// ✅ Correct - returns new object
window.htag.reducePlacementConfig = function (config) {
return {
...config,
bids: [...config.bids, newBid], // New array with new bid
};
};
// ❌ Wrong - modifies original object
window.htag.reducePlacementConfig = function (config) {
config.bids.push(newBid); // Mutates original array
return config;
};