Skip to content

Cookbook

This cookbook does not describe how to use ADvantage nor how to program in Java. It only contains suggestions and explanations for some common use cases.

How to enable/disable sensitive targeting parameters?

To enable/disable the semi-sensitive targeting parameters such as, device network type and device advertising identifier use the following code snippet:

//Disable the semi-sensitive targeting parameters!
ad.setSensitiveTargetingParamEnabled(false);

Note

Please note that sending sensitive targeting parameters is enabled by default.

How to set the maximum dimension for the inline banner

You can set maximum ad space size which they want to show inside their app using the following code snippet:

ad.setMaxDimension(new Size(expectedWidth, expectedHeight));

Note

Please note that the provided max dimension has to be specified as density independent pixels (dps).

How to change margin of the corner ad

Corner ad margin can be set using the following code snippet:

ad.setCornerAdVerticalMargin(100);
ad.setCornerAdHorizontalMargin(100);

How to clear cookies

You can clear cookies using following code snippet:

CookieManager.getInstance().removeAllCookies(null);

How to use Social advertisement (P2P)

Bob

ad.setOnSocialAdListener(new OnSocialAdListener() {
    @Override
    public void onSocialAdReceived(String target) {
    //Pass the given target to Alice (It MUST be done by the publisher)
    }
});

Alice

//Pass the Social target which is received from Bob's
//device to ADvantage instance and show the ad...
ad.showAd(socialTarget);
How to enable a secure communication in ADvantage

To enable a secure communication by using HTTP over TLS/SSL (HTTPS) use following code:

Advantage ad = new Advantage(this, "XXXXXXXX", "XXXX", "XX");
ad.setSSLEnabled(true);

Note

You have to enable SSL before calling showAd().

How to integrate the parallax (understitial) ad?

You can upgrade the ADvantage SDK to version 2.4.8.1 or more recent versions and integrate parallax ad into your applications like a normal banner.

The parallax ad is designed to be used inside of a scroll view(ScrollView, ListView, GridView, RecyclerView and etc.). Therefore it's highly recommended to disable the ADvantage scrolling event as shown in the following code:

//Disable ScrollEvent consumption!
parallax.setAllowAdWebViewToHandleScrollEvent(false);

//Set desired banner size (density independent pixel)
parallax.setMaxDimension(new Size(width, height));

Known Limitation

The parallax ad listens to OnScrollChange() event of its parent and in a very rare case this event fires with a short delay!

How to disable ADvantage's scroll event inside of a ListView or ScrollViews?

ADvantage handles and consumes ScrollEvents on its view per default. That means that TouchEvents are not forwarded to parent views. For instance, if you are using Advantage inside ListView or ScrollView, you might want to disable this functionality in order to give your ListView or ScrollView a smoother scrolling behavior.

You can disable this feature -scroll event- with following code:

ad.setAllowAdWebViewToHandleScrollEvent(false);

setAllowAdWebViewToHandleScrollEvent(false) means, ADvantage instance does not want the parent(Scrollable view) and its ancestors to intercept touch events and it will force the ADvantage object to pass the touch events onto its parents.

In ADvantage version 2.4.7 or later, a threshold is defined for vertical scrolling which enable the clients to scroll the ListView/ScrollView vertically while they are touching the ADvantage objects (If the vertical scroll distance is more than predefined distance threshold).

The default value of the distance threshold is 100px. But, developers can modify this value by employing the setAllowAdWebViewToHandleScrollEvent(Boolean, int threshold) function.

Add and remove targeting for the advertisement

To target advertisement for specific user groups (i.e. age, sex) it is possible to transmit additional parameters to the adserver. The corresponding method has to be called before requesting ad, since for a working targeting it is required to send the AD-provider a list of the name-value-pairs.

Targeting Keywords

Before adding targeting parameters please contact your ad-serving partner first. All of the keyword targeting parameters have to be added to your ad server before you are able to use it and in some cases they have to be a special format like the profile targeting on the Addition ad server.

Add Custom AdServerParameter

banner.addAdserverParameter("age", "20");
banner.addAdserverParameter("sex", "male");

banner.showAd();

Remove Custom AdServerParameter

boolean success = banner.removeAdserverParameter("age");

Define a custom protocol(in-app deep link feature)

After ADvantage version 2.5.0.1, publishers are able to take over control, if a new URI with a predefined custom protocol is about to be loaded in the ADvantage WebView by implementing following code:

Custom protocol registration

//Define the custom protocol(s)...
List<String> protocols = new ArrayList<String>();
protocols.add("my_app_protocol");

//Register the protocols...
banner.registerCustomProtocol(protocols, this);

Custom protocol event

@Override
public void onCustomUrlChanged(String url) {
// Do the required actions here!
}