I'm using DFP to show ads on a web page.
Is there any way to refer to particular ad slot by name? e.g. googletag.getSlotByName('abc')
My intension is to refresh ads in particular slots.
Yes. The pubads.defineSlot method returns a reference to the slot. This reference can be saved in a variable so you can use it later to refresh it. This would be an example:
googletag.cmd.push(function() {
var slotABC = googletag.defineSlot("/12345678/SLotABC", [728, 90],
"div-gpt-ad-1327312723268-0").addService(googletag.pubads());
googletag.enableServices();
googletag.display("div-gpt-ad-1327312723268-0");
//Then you can refer to it and refresh it like this:
googletag.pubads().refresh([slotABC]);
})
More info: here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With