Skip to main content

Add Event Listener

1. Add ad event listener

Use gladsdk.addEventListener() to add an event listener for events occurring during the ad slot rendering.

2. Event Type

EventEvent TypeDescription
Ad Loadgladsdk.event.AD_LOADEDOccurs when an ad is loaded in an ad slot
Ad Clickgladsdk.event.AD_CLICKEDOccurs when the ad creative rendered in an ad slot is clicked
Ad Impressedgladsdk.event.AD_IMPRESSEDOccurs when the exposure criteria for the ad creative rendered in the ad slot are met
Ad Errorgladsdk.event.ERROROccurs when ad loading fails or execution error occurs
Ad Mutegladsdk.event.AD_MUTE_COMPLETEDOccurs when ad mute reason is clicked
danger

Ad slots should not be deleted when an Ad error event occurs.

NAM SDK identifies valid ad exposures even when rendering has failed. Therefore, do not remove or hide the ad container by calls such as adSlotElement.remove() nor apply display: none;.

window.gladsdk = window.gladsdk || { cmd: [] };

window.gladsdk.cmd.push(function () {
window.gladsdk.addEventListener(window.gladsdk.event.AD_LOADED, function (ad) {
console.debug(window.gladsdk.event.AD_LOADED);

var adSlot = ad.slot;
var adUnitId = adSlot.getAdUnitId();
var adSlotElementId = adSlot.getAdSlotElementId();
});

window.gladsdk.addEventListener(window.gladsdk.event.AD_CLICKED, function (ad) {
console.debug(window.gladsdk.event.AD_CLICKED);
});

window.gladsdk.addEventListener(window.gladsdk.event.AD_IMPRESSED, function (ad) {
console.debug(window.gladsdk.event.AD_IMPRESSED);
});

window.gladsdk.addEventListener(window.gladsdk.event.ERROR, function (ad, error) {
console.debug(window.gladsdk.event.ERROR);
});

window.gladsdk.addEventListener(window.gladsdk.event.AD_MUTE_COMPLETED, function (ad) {
console.debug(window.gladsdk.event.AD_MUTE_COMPLETED);
});

var adSlotInfo = {
adUnitId: 'WEB_nw_banner-N345765840',
adSlotElementId: 'division',
};

var adSlot = window.gladsdk.defineAdSlot(adSlotInfo);
window.gladsdk.displayAd(adSlot);
});

3. Remove ad event listener

Removing a specific event listener

Use gladsdk.removeEventListener() to remove a specific event listener.

var listener = function (ad) {
console.debug(window.gladsdk.event.AD_CLICKED);
}
window.gladsdk.addEventListener(window.gladsdk.event.AD_CLICKED, listener);
window.gladsdk.removeEventListener(window.gladsdk.event.AD_CLICKED, listener);

Removing all event listeners

Use gladsdk.removeAllEventListener() to remove all event listeners.

window.gladsdk.removeAllEventListener();