Skip to content

Visible and Viewable Event Handling

Jason Pell edited this page Jul 28, 2022 · 1 revision

The SDK (1.7.0 onwards) will no longer generate visible or viewable events by default.

Note: You can restore previous behaviour by using the loadAd variant with delayViewEvents=false.

The reason we did this is that previously the SDK was prematurely generating these events even where the ad was not visible on the device (for instance its off screen in a scroll view)!

By default these viewable and visible events will only be generated where its determined the ad is visible on the screen and for viewable events at least 50% of the ad is visible.

This is achieved by calling a new updateView(ScrollView scrollView) method on the AdnuntiusAdWebView.

Its important to call this function from the onAdResponse(AdnuntiusAdWebView view, AdResponseInfo response) and from onScrollChanged() on a OnScrollChangeListener attached to the ScrollView your ads are rendered into.

Functionality has been added to support ScrollView components. Additional use cases will be considered as they are encountered.

Unfortunately there is no easy way to encapsulate this requirement completely within the SDK (If you have an idea how we might do that, open an issue we would love to make this easier to use!)

Scroll View Integration

Important: If you have a simple application with a single ad that will always be visible as soon as the application is started, it would make more sense to just use the delayViewEvents=false loadAd variant.

A simple example is an application with a one or more ads which exists within a scroll view and these ads may not be visible as soon as the application is started.

You must keep a reference to the scrollView your AdnuntiusAdWebView will be displayed in as a class variable, as we will want to call updateView from the onAdResponse LoadAdHandler method.

This is required only where its possible ad will be visible in the application without scrolling. The reason why it must be in the onAdResponse method, is it must be called after the ad has been rendered.

adView.loadAd(request2, (view, info) -> view.updateView(MainActivity.this.scrollView));

You must also add it to the OnScrollChangeListener:

this.scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> {
    adView.updateView(scrollView);
});

Clone this wiki locally