handleEmptyGoogle
The handleEmptyGoogle hook runs when Google Ad Manager reports an empty slot (isEmpty: true). By default, htag will fall back to a prebid-universal-creative with winning ad ID from the prebid auction, but this hook lets you customize that behavior, including completely skipping the prebid-universal-creative fallback.
If GAM serves a mediation creative without a Prebid bid, it reports isEmpty: false and this hook is not called. The placement still emits element.resolve without an ad ID.
When Prioritize GAM is enabled for a placement, an empty GAM response leaves the placement empty and skips this hook.
Example
Section titled “Example”window.htag = window.htag || {};window.htag.handleEmptyGoogle = function (elementId, winnerAdId) { // Log empty Google responses for monitoring console.log(`Google returned no ad for element: ${elementId}`);
// Skip Google fallback for specific placements if (elementId === 'footer-ad') { console.log('Skipping Google fallback for footer placement'); return undefined; }
// Use default behavior (prebid-universal creative) for other placements return winnerAdId;};Parameters
Section titled “Parameters”- elementId (string): The ID of the placement element where Google returned no ad
- winnerAdId (string | undefined): The ID of the winning ad that would be used for fallback
Return Value
Section titled “Return Value”- string: The ad ID to use with prebid-universal-creative (typically the same as input)
- undefined: Skip the prebid-universal-creative entirely
Use Cases
Section titled “Use Cases”Selective prebid-universal-creative
Section titled “Selective prebid-universal-creative”Skip prebid-universal-creative for specific placements or conditions:
window.htag.handleEmptyGoogle = function (elementId, winnerAdId) { // Skip fallback for mobile placements const isMobile = window.innerWidth <= 768; if (isMobile && elementId.includes('desktop')) { return undefined; }
// Skip fallback for premium placements if (elementId.includes('premium')) { return undefined; }
return winnerAdId;};Related Concepts
Section titled “Related Concepts”- handlePriorityCreative: Handle priority creative behavior
- reduceBidRequest: Modify bid requests
- reducePlacementConfig: Modify placement configuration
- isDisabled: Check if htag is disabled