Banner

The VIS.X® SDK dynamically adjusts the size of an inline banner position to realize high-impact effects, such as the YOC Understitial Ad®.

To unlock the full potential of YOC’s high-impact advertising formats, it’s advised to integrate the banner placement inside scrollable content, e.g. inside a ScrollView or RecycleView and allow resizing of the adContainer upon request.

An adContainer holds the ad creative and is needed to perform an ad call. It requires a VIS.X® Ad Unit ID (provided by YOC).

  1. Preparing the AdContainer
  2. Calling and Rendering an Ad
  3. Providing the anchorView to the VisxAdManager
Preparing the AdContainer

First, set up an adContainer_ as layout XML and call the VisxAdManager from your Activity to load, render and dispose of ads.

<RelativeLayout 
    android:id="@+id/adContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

If you place the adContainer in a ConstraintLayout or FrameLayout, you need to adjust the layout.xml of the Activity to allow the width to remain flexible in its boundaries.

<FrameLayout
    android:id="@+id/inlineContainer"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

If working with a RecyclerView, multiple LayoutManager is supported, such as LinearLayoutManager, GridLayoutManager or StaggeredGridLayoutManager.

The banner integration requires an adjustable size, therefore android:layout_height should be set to wrap_content. If this is not possible you need to implement onAdSizeChanged from VisxCallbacks and apply size changes manually.

Calling and Rendering an Ad

Now you can continue the configuration within your Activity to request and render an ad.

First set up a VisxCallbacks object and overwrite onAdLoadingFinished, to define how to proceed after the ad is received and ready to be displayed. Also, we recommend overwriting onAdLoadingFailed, as this can be useful during the integration process.

Next, get an instance of the VisxAdManager with its related builder and .build()`.

Once an ad is received, the callback onAdLoadingFinished will allow you to add the provided VisxAdManager.adContainer as a subview to your adContainer.

class MyActivity : AppCompatActivity() {

    private lateinit var visxAdManager: VisxAdManager

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_article)

        var visxCallbacks = VisxCallbacks { 
            override fun onAdLoadingFinished(visxAdManager: VisxAdManager?, message: String?) {
                adContainer.removeAllViews()
                adContainer.addView(visxAdManager?.adContainer)
            }

            override fun onAdLoadingFailed(message: String?, errorCode: Int, isFinal: Boolean) {
                Log.i("onAdLoadingFailed() $message errorCode: $errorCode")
            }
         }
        
        visxAdManager = VisxAdManager.Builder()
                .context(this)
                .callback(visxCallbacks)
                .visxAdUnitID("123456")
                .adSize(Size(300, 250))
                .build()
    }
}
Builder Methods Description
.context(Context) The Activity’s Context, normally it would be this.

Please do not use the application context provided by Activity.getApplicationContext().
.visxAdUnitId(String) VIS.X® Ad Unit ID, provided by YOC
.adSize(Size) The default Size of your adContainer
.callback(VisxCallbacks) Reference to the VisxCallbacks used for all types of callbacks, as listed here.
Providing the anchorView to the VisxAdManager

This step is optional, but highly recommended for improved performance and monetization.

Some YOC ad formats, such as the YOC Understitial Ad®, YOC Mystery Scroller® or YOC Branded Takeover depend on listening to the OnScrollChange event of the anchorView, i.e. the ScrollView / RecycleView in which the adContainer is nested.

While the VisxAdManager has methods to detect its parent, we recommend providing us with this information explicitly as part of the builder. This is especially important in cases, where the OnScrollChangeListener of said anchorView is already used.

Builder Methods (optional) Description
.anchorView(ScrollView) The anchorView is the ScrollView or RecyclerView your adContainer is located in.
.setTopBottomOffset(int, int) In case the anchorView is overlayed by a static UI element on top or bottom, you can provide the offset height in density-independent pixel.
.setScrollListenerPresent(Boolean) Set to true if the OnScrollChangeListener of your anchorView is used on your end.

In case you’ve already registered an OnScrollChangeListener, please add the following line to your ScrollView.setOnScrollChangeListener() routine.

visxAdManager?.updateUnderstitialPosition()

Your inline placement is fully set up and ready for testing.

We advise you to share a build of your app with the YOC Service Team, to validate and fully test the integration together. Reach out to your contact at YOC to request test resources.