Skip to content

Event Handlers

ADvantage sends a couple of events you have to take care of. On this page you will see different events.

ADvantageNoCampaignEvent

This event will be called when the ad server didn't deliver a campaign.

case "ADvantageNoCampaignEvent":
    // ad server didn't deliver a campaign
    // in this case you can use a backfill service e.g. Google adsense, etc.
    this.hide(); // hide the ADvantage iframe
    //do something
    break;

No Campaign

To get this event a "no campaign"-campaign has to be setup on the ad server as default campaign.

If you're not getting this event, please contact your ad serving agency to update your ad server system.

ADvantageAdvertisementEvent

is called when an advertisement is loaded successfully.

case "ADvantageAdvertisementEvent":
    //an ADvantage advertisement is loaded
    this.show(); // show the advertisement
    //do something
    break;

ADvantageIframeLoadedEvent

is called when the onload function from iframe is successfully loaded.

case "ADvantageIframeLoadedEvent":
    // Content inside of the iframe loaded
    //do something
    break;

ADvantageUpdateLayoutEvent

This event will be fired when the creative is using the dynamic banner function. It will change the current height of the ad space.

When this event is fired, you will get the new height in the event data field ev.data. This event data field contains an object with the new dimensions of the ad space. In case of "ADvantageUpdateLayoutEvent" it is only the new height. The object will return an formatted CSS dimension e.g. 200px.

Here is an example how you can access this object.

...
case "ADvantageUpdateLayoutEvent":
        //creative is using update layout for the current instance
        console.log(ev.data.height); // output e.g. "200px"
        break;

ADvantageResizeEvent

This event will be fired when the creative is using our resize function. It will change the current width and height of the ad space.

When this event fires you will get the new ad space dimensions in the event data field ev.data. ev.data contains an object with the new dimensions of the ad space. In case of ADvantageResizeEvent, this would be the width and height. The object will return an formatted CSS dimension e.g. 200px.

Here is an example how you can access this object.

...
case "ADvantageUpdateLayoutEvent":
    //creative is using update layout for the current instance
    console.log(ev.data.height); // output e.g. "200px"
    console.log(ev.data.width); // output e.g. "320px"
    break;

ADvantageResizeClosedEvent

This event will be fired when an advertisement is going back from resize state to the default state.

case "ADvantageResizeClosedEvent":
    //the creative is going back to the default size
    //do something
    break;

ADvantageForwardEvent

will be called when an advertisement forwards events information from the creative to the publisher page.

This event is only needed in some special cases (e.g. Native Ads). You will get from us information, if you have to use it and how.

case "ADvantageForwardEvent":
    // some Events will be forwarded from the creative to you, in this case you will find the content in "ev.data" as an object
    //do something
    break;

ADvantageCloseEvent

will be called when the advertisement is closed via a close button or close function from creative.

case "ADvantageCloseEvent":
    // advertisement closed
    //do something
    break;

Example script

This is an example code snippet on how ADvantage events can be recieved.

window.onload = function(){
    banner = new ADvantage_WebSDK( 'advertisement' )
        .setLicenseKey( '[LICENSE KEY]' )
        .setSiteId('[SITEID]')
        .setPosition('[POSITION]')
        .setWidth( '320px' )
        .setHeight( '50px' )
        .addEvent(function(ev){
            switch (ev.status){
                case "ADvantageNoCampaignEvent":
                    // adserver didn't deliver a campaign
                    // in this case you can use a backfill service e.g. Google adsense, etc.
                    this.hide(); // hide the ADvantage Iframe
                    //do something
                    break;
                case "ADvantageAdvertisementEvent":
                    //an ADvantage advertisement is loaded
                    this.show(); // show the advertisement
                    //do something
                    break;
                case "ADvantageIframeLoadedEvent":
                    // content inside of the iframe loaded
                    //do something
                    break;
                case "ADvantageUpdateLayoutEvent":
                    //the creative is using update layout for the current instance
                    //do something
                    break;
                case "ADvantageResizeEvent":
                    //the creative is using resize for the current instance
                    //do something
                    break;
                case "ADvantageResizeClosedEvent":
                    //the creative is going back to the default size
                    //do something
                    break;
                case "ADvantageForwardEvent":
                    // some Events will be forwarded from Creative to you, in this case you will find the content in "ev.data" as an object
                    //do something
                    break;
                case "ADvantageCloseEvent":
                    // advertisement closed
                    //do something
                    break;
            }

        })
        .initialize();
};

Events on AJAX websites

We recommend following these steps before you load a new page via AJAX:

  1. Remove all event listeners from your ADvantage instance [your ADvantage instance variable].removeEvent(). The behaviour is the same as when using removeEventListeners
  2. Destroy the ADvantage instance with the ADvantage Method [your ADvantage instance variable].destroy()
  3. Delete your ADvantage instance variable e.g. delete [your ADvantage instance variable]
  4. Create a new ADvantage instance for the new page

Please refer to the ADvantage lifecycle for further information on destroying and creating new Advantage objects.

Tip

Check out the cookbook on how to handle the events for sticky banner implementation.