Skip to content

handleEmptyGoogle

The handleEmptyGoogle hook allows you to control the behavior when Google Ad Manager has no ad to serve. 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.

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;
};
  • 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
  • string: The ad ID to use with prebid-universal-creative (typically the same as input)
  • undefined: Skip the prebid-universal-creative entirely

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;
};