Interacting with an ad

Functions

Calling new OwAd() will return a javascript object which you can later use to control and interact with the displayed ad. The object has the following functions you can call to achieve the interaction:

Function Description
refreshAd
  • Refresh ad and load a new one
  • Please note that this will cause the ad to scroll into view (if not visible)
removeAd
  • Removes the current ad from the DOM

 

Events

You can use the Overwolf ad object (the one created by calling new OwAd()) to listen to events related to the displayed ad. Registering for an event can be done by calling the function addEventListner on the ad object. Like many other libs, the first param sent to addEventListner is the name of the event, and the second is a handler function for the event.

The following events are supported:

Event Name Fired when
player_loaded
  • Ad video player was successfully loaded on the page
play
  • Ad started playing
impression
  • Video “impression” – video played for more than 3 seconds
complete
  • Video ad was played until its end *
error
  • Error occurred while trying to load ad *

* – Only relevant for video ads

Example of interaction with an ad

function onOwAdReady(){
    var myOverwolfAd = new OwAd(document.getElementById("ad-div"))

    myOverwolfAd.addEventListner('impression', function(){

        setTimeout(function{}{
            myOverwolfAd.pause();
        },1000);

        setTimeout(function{}{
            myOverwolfAd.play();
        },2000);
    });
}

In this example:

  1. We wait until we receive the impression event which means the video has been playing for 3 seconds.
  2. Wait one second and pause the video.
  3. Wait for two seconds to resume the video.

Running this code, you should see a video playing for about 4 seconds, then pauses for 1 second, then resumes playing again.

Showing multiple ads

If for some reason you wish to show more than one ad on your app, you can easily do so by creating multiple instances of OwAd. Just make sure you pass a different container element for each instance.