Last active
November 13, 2020 06:09
-
-
Save scott-thrillist/bf7d429f6c78a417fe4717a2e1791dc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Amazon APS TAM ad setup | |
* | |
* @param {string} options.slotId The ad slot ID | |
* @param {array} options.sizes Array of sizes in DFP sizeMapping format | |
*/ | |
const setupTamAd = options => { | |
const { slotId, sizes, adElementRef = {} } = options; | |
// request the bids for the googletag slots | |
window.apstag.fetchBids( | |
{ | |
slots: [ | |
{ | |
slotID: slotId, | |
slotName: this.pagePath, | |
sizes | |
} | |
] | |
}, | |
() => { | |
window.googletag.cmd.push(() => { | |
window.apstag.setDisplayBids(); | |
// deferring for reliability | |
setTimeout(() => { | |
DFPManager.refresh(slotId); | |
}, 0); | |
// IE11 | |
setTimeout(() => { | |
const slotEl = adElementRef.current || document.getElementById(slotId); | |
if (slotEl && slotEl.innerHTML === '') { | |
console.log('AD BACKUP REFRESH', slotId); | |
DFPManager.refresh(slotId); | |
} | |
}, 2000); | |
}); | |
} | |
); | |
}; | |
/**********************************/ | |
return ( | |
<DFPSlotsProvider | |
singleRequest | |
disableInitialLoad // required for TAM | |
dfpNetworkId={pubId} | |
targetingArguments={adAttributes} | |
> | |
<AdSlot | |
sizes={sizes} | |
sizeMapping={sizeMapping} | |
adUnit={pagePath} | |
className={wrapperClass} | |
onSlotRegister={setupTamAd} // required for TAM | |
onSlotRender={slotRendered} | |
targetingArguments={{ adType }} | |
/> | |
</DFPSlotsProvider> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment