Skip to content

Cookbook

This cookbook doesn't 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?

You can disable/enable the semi-sensitive targeting parameters such as, device network type and device advertising identifier by using 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 easily set maximum ad space size that they want to show inside their app using the following code snippet:

ad.setMaxDimension(new Size(200, 200));

Note

Please note that the provided max dimension needs 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 easily clear cookies using the following code snippet:

if(Build.VERSION.SDK_INT >= 21)
    CookieManager.getInstance().removeAllCookies(null);
else
    CookieManager.getInstance().removeAllCookie();

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 eneble a secure communication in ADvantage

You developers can simply enable a secure communication by using HTTP over TLS/SSL (HTTPS) with the following code snippet:

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 simply upgrade the ADvantage SDK to version 2.4.8.1 or later and integrate parallax ad into their 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 parential views. For instance, if 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 simply disable this feature -scroll event- with a line of 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/ScollView 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 AD-server. 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 you add targeting parameters please contact first your ad-serving partner. All of the keyword targeting parameters must be added to your ad server before you can use it and in some cases they must be in a special format like the profile targeting on Adition 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, the publishers are able to take over the control when a new URI with a predefined custom protocol is about to be loaded in the ADvantage WebView by implementing the 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!
}