Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ad slot by slot name

Tags:

google-dfp

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.

like image 406
Satish Gadhave Avatar asked Nov 23 '25 06:11

Satish Gadhave


1 Answers

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

like image 156
OscarDOM Avatar answered Nov 24 '25 20:11

OscarDOM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!