handlePriorityCreative
The handlePriorityCreative hook allows you to control the behavior when a priority creative is available. Priority creatives are special ads (typically from Xandr) that are guaranteed to win the auction. This hook lets you customize what happens when such creatives are encountered.
Example
Section titled “Example”window.htag = window.htag || {};window.htag.handlePriorityCreative = function (elementId, winnerAdId) { // Log priority creative usage for analytics console.log(`Priority creative displayed for element: ${elementId}`);
// Apply custom tracking for priority creatives if (typeof gtag !== 'undefined') { gtag('event', 'priority_creative_shown', { element_id: elementId, ad_id: winnerAdId || 'unknown', }); }
// Return the winner ad ID to proceed with default behavior return winnerAdId;};Parameters
Section titled “Parameters”- elementId (string): The ID of the placement element where the priority creative will be displayed
- winnerAdId (string): The ID of the winning ad
Return Value
Section titled “Return Value”- string: The ad ID to use for rendering the priority creative
- undefined: Skip rendering the priority creative
Related Concepts
Section titled “Related Concepts”- Priority Creative IDs: Learn about priority creative management
- setPriorityCreativeIds: Set priority creative IDs
- getPriorityCreativeIds: Get current priority creative IDs
- handleEmptyGoogle: Handle empty Google responses
- reduceBidRequest: Modify bid requests
- reducePlacementConfig: Modify placement configuration
- isDisabled: Check if htag is disabled