Asynchronous tags for iBillboard Ad Server » Events in Asynchronous codes

Events in Asynchronous codes

Last modified by Pavlína Novotná on 2017/04/24 10:33
Comments (0) · Attachments (0)

Within the asynchronous codes, it is possible to create functions for specific Ad Server event. (Example of Ad Server event: Ad Server has / has not ad, and others.) The events are connected using „me.on“ method. Functions are connected to events as follows:

ibbAds.tag.on(EVENT_NAME, handlerFn)

In general, “ibbAds.tag” includes events of all Ad Servers. If you need to set event for specific Ad Server you can use this writing:

BbmEu.on(EVENT_NAME, handlerFn) // It registers events from Ad Server installation BbmEu only.
Remember that all event functions have to be registered (inserted) in DOM before requestAds() or requestAndPlaceAdS() calling.
ibbAds.tag.on(EVENT_NAME1, handlerFn)
ibbAds.tag.on(EVENT_NAME2, handlerFn)


ibbAds.tag.requestAndPlaceAds();

Supported events

Two events are actually supported by asynchronous codes. Each of them has its own unique name which has to be defined during function implementation. 

ADS_WRITTEN_TO_AD_SLOT

Occurs when Ad Server returns in its answer one or more Ads which are recorded into specific position.

For example, we want to display "Advertisement“ caption for position in page, simultaneously we need the caption display only in case when Ad Server returns some ad (ads) to the position.


ibbAds.tag.on("ADS_WRITTEN_TO_AD_SLOT", function (event) {
      var id = event.getData().slotId;
      document.getElementById(id).className = "isAdvertisement";  
      })

In the above example the function is assigned to ADS_WRITTEN_TO_AD_SLOT event. It means that the function will be called when Ad Server returns an ad to position in its answer. The function sets class name “isAdvertisement” for all positions into which is an ad returned. 

In CSS class "isAdvertisement" caption "Advertisement" is defined through "content" as you can see on the example below:


//CSS code block
.isAdvertisement:before {
       content: "Advertisement";
}

NO_AD_RETURNED_FOR_AD_SLOT

Occurs when Ad Server returns empty response without any ad to position.
For example, take a defined position on a page with fixed dimensions which you want to hide in case that Ad Server do not have any ad to the position. You can use event NO_AD_RETURNED_FOR_AD_SLOT:


ibbAds.tag.on("NO_AD_RETURNED_FOR_AD_SLOT", function(event) {
   var id = event.getData().getCustomId();
   document.getElementById(id).style.display= "none";
});

Now inline style “display= ”none” ” is set for position which do not have any ad and the position is hidden.

Tags:
Created by ZdVo on 2017/04/03 12:53

Navigation


This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 4.0 - Documentation