You can connect your mobile app directly to premium brand demand through the DV+ ecosystem with the Magnite in-app SDK.
With this lightweight, reliable integration layer in DV+ you get the following:
The information below describes the basic procedure for integrating Magnite in-app ads into your Android apps.
Notes
Add the below repository to your app-level build.gradle file:
repositories { mavenCentral() } dependencies { implementation ("com.magnite.sdk:ads-sdk:1.0.+") }
You can add the following optional permissions under the main <manifest> element:
<uses-permission android:name="android.permission.BLUETOOTH" />
The SDK supports two methods of initialization. Use only one in a single application.
Add the following metadata tag with your MagniteApp ID under the <application> section in your manifest file:
<meta-data android:name="com.magnite.sdk.APPLICATION_ID" android:value="YOUR_APP_ID" />
MagniteSDK.initParams(this, "YOUR_APP_ID") .setCallback(() -> /* ready to request ads */) .init();
For either method, replace “YOUR_APP_ID” with the value Magnite provides at onboarding.
If your app targets children (as defined under applicable laws, such as 13 in the US and 16 in the EU), and you integrated the SDK version through Maven, remove the wi-fi permission from your manifest merger. To do this, follow these steps:
Add the following line to the manifest element:
xmlns:tools="http://schemas.android.com/tools"
Add this line to your permission list
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" tools:node="remove"/>
If your app targets children (such as under 16 in the European Economic Area (EEA) or under 13 in other countries), Google Play requires you to participate in the Designed for Families program and comply with Google Play’s Families Policy Requirements.
Important: Don’t use Magnite Services on applications distributed by Google Play and primarily directed at children.
If your app is designed for everyone, including children and families, follow these steps:
Example:
<meta-data android:name="com.magnite.sdk.MIXED_AUDIENCE" android:value="true"/>
The indication of whether a specific end-user is a child should be done by setting a “is_child_directed” flag value to “true” or “false.”
<meta-data android:name="com.magnite.sdk.CHILD_DIRECTED" android:value="true"/>
The API should be set before initializing the SDK.
If you set “is_mixed_audience” flag as “true,” then your app won’t transmit the Advertising ID for children and end-users for unknown ages.
As required under GDPR, you should report to the SDK users’ consent by a consent flag (“pas”), via the API detailed below.
The user consent flag indicates whether a user based in the EU has provided consent for sharing their app data for the purpose of ads personalization. Based on this consent flag, Magnite targets the most relevant ads to your users. If a user hasn’t consented, we won’t show personalized ads to this user.
Important:
Use this method in case the user has consented:
MagniteSDK.setUserConsent (this, "pas", System.currentTimeMillis(), true);
Use this method in case the user hasn’t consented:
MagniteSDK.setUserConsent (this, "pas", System.currentTimeMillis(), false);
Note: The timestamp parameter should represent the specific time a consent was given by the user.
Magnite SDK supports publishers to restrict the sale of end users’ personal information under the California Consumer Privacy Act (CCPA).
The notification about opt-out of specific users located in California should be handled based on IAB US privacy string.
To set the IAB US privacy string, use the following API:
MagniteSDK.getExtras(this) .edit() .putString("IABUSPrivacy_String", "1YNN") .apply();
To determine what value to use for the US privacy string, refer to this IAB document. Note that the privacy string value is case-sensitive.
Example values:
Interstitial ads are full-page ads displayed before or after a certain content page or action, such as upon entering a page, between stages, while waiting for an action, upon exiting the application, and more.
Use the showAD() method to show an interstitial ad at a specific location in your app.
Call MagniteInterstitialAd.showAd(this) in the appropriate place(s) in the activity where you’d like to show the ad. The showAd method returns true in case the ad was displayed successfully, or false if not (for example, if an ad isn’t ready yet).
Important: loading an ad might take a few seconds. In case you call showAd() while the ad hasn’t been successfully loaded yet, nothing will be displayed.
Add the following view inside your activity layout XML:
<com.magnite.sdk.ads.banner.MagniteBannerAdView android:id="@+id/magniteBanner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" />
Note: The code places a view inside your activity. You also have the option to add more attributes for placing in the desired location in your activity.
For a full integration guide, refer to the Banner ads advanced usage in the appendix below.
MRec is a 300x250 rectangular ad integrated in an app’s layout. The ad is refreshed automatically.
<com.magnite.sdk.ads.banner.MagniteMrecAdView android:id="@+id/magniteMrec" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" />
For adding MRec programmatically, instead of using the layout XML:
// Get the Main relative layout of the entire activity RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id.mainLayout); // Define Magnite Mrec MagniteMrecAdView magniteAppMrec = new MagniteMrecAdView(this); RelativeLayout.LayoutParams mrecParameters = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); mrecParameters.addRule(RelativeLayout.CENTER_HORIZONTAL); mrecParameters.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); // Add to main Layout mainLayout.addView(magniteAppMrec, mrecParameters);
Rewarded video ads are interstitial video ads that provide a reward to the user in exchange for watching an entire video ad. The reward might be in-app goods, virtual currency, or any premium content provided by the app. Because users actually opt-in to watch a rewarded video and are granted with something valuable in return, rewarded ads are an effective and clean monetization solution for stronger user retention and keeping users engaged in your app for a longer amount of time.
To show a rewarded ad, pass the following AdMode parameter when calling the loadAd() method:
MagniteRewardedAd rewardedAd = new MagniteRewardedAd(context); magniteRewardedAd.loadAd(adPreferences, new AdEventListener() { public void onReceiveAd(@NonNull Ad ad) { // ad is ready } public void onFailedToReceiveAd(@Nullable Ad ad) { // check ad.getErrorMessage() for details } });
Implement the following listener to get a callback when the user completes watching the video and is eligible for getting the reward:
rewardedAd.setOnUserRewardedListener (new OnUserRewardedListener() { public void onUserRewarded() { // Grant user with the reward } }); rewardedAd.showAd();
Native ads are raw representations of ads without any predefined wrapping UI, giving you the freedom to design and control the ad exactly how you want. With native ads, you can design an ad experience that fits your app’s scene, content, and functionality.
For a full integration guide, refer to the native ads advanced usage in the appendix below.
You can find a sample project from Magnite here.
The Magnite In-App SDK operates as part of the broader Magnite ecosystem, enabling unified activation across mobile and CTV inventory within DV+.
For assistance, contact your Magnite representative or visit https://help.magnite.com
Below, you’ll find advanced usage and personal customization options, not required for integration.
Implement interstitial ads with objects for gaining more control over your ads, like using callbacks or using multiple ads with different properties.
To initialize an interstitial ad object, create a member variable in your activity as follows:
AdPreferences adPreferences = new AdPreferences(); adPreferences.setAdTag(adTag); MagniteInterstitialAd interstitialAd = new MagniteInterstitialAd(context); interstitialAd.loadAd(adPreferences, new AdEventListener() { public void onReceiveAd(@NonNull Ad ad) { // ad is ready, call the interstitialAd.showAd() when needed } public void onFailedToReceiveAd(@Nullable Ad ad) { // check ad.getErrorMessage() for details } });
Call showAd() in the appropriate place(s) in the activity where you would like to show the Ad:
interstitialAd.showAd(); // call when you want to show the ad The following is an example of showing an Interstitial Ad between Activities: public void btnOpenActivity (View view){ Intent nextActivity = new Intent(this, NextActivity.class); startActivity(nextActivity); interstitialAd.showAd();
Selecting an interstitial ad type
We highly recommend using our Automatic mode, which automatically selects the best Interstitial Ad to display, meaning the type of Ads that will generate the most revenue for you.To add an automatic Interstitial Ad, please refer to the Interstitial Ads section earlier in this guide. If you do not wish to use the automatic mode, MagniteIntersitialAd.loadAd() can be directed to load specific Ads to be shown later using the AdMode parameter. The options for the AdMode parameter are:
Parameter Name
Description
Specific Ad Load Example
AUTOMATIC
(Recommended)
Auto-selection of the best next Interstitial Ad to display, meaning the type of Ads that will generate the most revenue for you. The ad type can be Display or Video. This is the default
magniteInterstitialAd.loadAd()
magniteInterstitialAd.loadAd(AdMode.AUTOMATIC)
VIDEO
Use this parameter when you're interested in getting Video ads only
magniteInterstitialAd.loadAd(AdMode.VIDEO)
Adding Interstitial Callbacks
Adding a Callback when an Interstitial Ad is loaded
magniteInterstitialAd.loadAd() can be called before showing the ad, and get an implementation of AdEventListener as a parameter. To get a callback when an Ad is loaded, pass the object that implements AdEventListener (this may be your Activity) as a parameter to the loadAd method. This object must implement the following methods:
@Override public void onReceiveAd(Ad ad) { } @Override public void onFailedToReceiveAd(Ad ad) { }
interstitialAd.loadAd(new AdEventListener() { @Override public void onReceiveAd(Ad ad) { } @Override public void onFailedToReceiveAd(Ad ad) { } });
Important: Do not call loadAd() from within onFailedToReceiveAd(). The SDK will automatically try to reload an ad upon a failure.
Adding a Callback when an Interstitial Ad is shown
magniteInterstitialAd.showAd() can get a parameter implementation of AdDisplayListener. To get a callback when an Ad is shown, pass the object that implements AdDisplayListener (this may be your Activity) as a parameter of the method. This object must implement the following methods:
@Override public void adHidden(Ad ad) { //Called when the ad has been Closed. } @Override public void adDisplayed(Ad ad) { //Called when the ad has been rendered. } @Override public void adClicked(Ad ad) { } @Override public void adNotDisplayed(Ad ad) { //Called when the ad failed to render. }
interstitialAd.showAd(new AdDisplayListener() { @Override public void adHidden(Ad ad) { } @Override public void adDisplayed(Ad ad) { } @Override public void adClicked(Ad ad) { } @Override public void adNotDisplayed(Ad ad) { } });
Loading a Banner
You can load a banner without attaching it to a view, enabling you to attach it when available at a later stage.
AdPreferences adPreferences = new AdPreferences(); adPreferences.setAdTag(adTag); new BannerRequest(getApplicationContext()) .setAdFormat(BannerFormat.BANNER) // BannerFormat.MREC, BannerFormat.COVER .setAdPreferences(adPreferences) .load((creator, error) -> { if (creator != null) { View adView = creator.create(context, new BannerListener() { public void onReceiveAd(View banner) { // called when the ad is reloaded } public void onFailedToReceiveAd(View banner) { // check the error, ((MagniteAdView) banner).getErrorMessage() } public void onImpression(View banner) { // called when the impression has been recorded } public void onClick(View banner) { // called when click event has been recorded } }); bannerContainer.addView(adView); } else { // check the error } });
Adding Banner Callbacks
If you implemented the banner programmatically, simply pass an implementation of a BannerListener to the banner's constructor:
MagniteAdView banner = new MagniteBannerAdView(context, new BannerListener() { @Override public void onReceiveAd(View view) { // called when HTML data was received via network } @Override public void onFailedToReceiveAd(View view) { // called if no ads are available or some network error has happened } @Override public void onImpression(View view) { // called when viewable impression by IAB rules have been generated } @Override public void onClick(View view) { // called when a user clicked the banner } });
Initializing and Loading a Magnite NativeAd Object
In your Activity, create a member variable, as follows:
private MagniteNativeAd magniteNativeAd = new MagniteNativeAd(this);
To load your native ad, call the loadAd() method with a NativeAdPreferences object:
MagniteNativeAd.loadAd(new NativeAdPreferences());
NativeAdPreferences can be used to customize some of the native ad properties to suit your needs, such as the number of ads to load, the image size of the ad, or whether the image should be pre-cached or not. For a full description of the NativeAdPreferences, please refer to Native Ad Preferences API.
NOTE:
By default, Magnite NativeAd retrieves the image URL of the ad. The SDK is also capable of auto-loading the image as a BITMAP object. This feature is turned off by default. For enabling it, set autoBitmapDownload in NativeAdPreferences to true
You can register your Magnite NativeAd object for callbacks by passing an AdEventListener object to the loadAd() method:
magniteNativeAd.loadAd(new NativeAdPreferences(), new AdEventListener() { @Override public void onReceiveAd(Ad arg0) { // Native Ad Received } @Override public void onFailedToReceiveAd(Ad arg0) { // Native Ad failed to receive } });
Using the Native Ad Object
After initializing and loading your Magnite NativeAd object, use the getNativeAds() method to obtain an array of NativeAdDetails objects for all returning ads. The NativeAdDetails object provides access to each ad's details, such as the ad's title, description, image, etc. This object also provides methods for firing an impression once the ad is displayed, and for executing the user's click on the ad. For a full description of the NativeAdDetails object, please refer to Native Ad Details API.
Example: the following is an example of how to a native ad with a pre-cached images of 150x150 pixels size, and logging their details once ready (using callbacks)
// Declare Native Ad Preferences NativeAdPreferences nativePrefs = new NativeAdPreferences() .setAutoBitmapDownload(true) // Retrieve Images object .setPrimaryImageSize(2); // 150x150 image // Declare Ad Callbacks Listener AdEventListener adListener = new AdEventListener() { // Callback Listener @Override public void onReceiveAd(Ad arg0) { // Native Ad received ArrayList ads = magniteNativeAd.getNativeAds(); // Print all ads details to log Iterator iterator = ads.iterator(); while(iterator.hasNext()){ Log.d("MyApplication", iterator.next().toString()); } } @Override public void onFailedToReceiveAd(Ad arg0) { // Native Ad failed to receive Log.e("MyApplication", "Error while loading Ad"); } }; // Load Native Ads magniteNativeAd.loadAd(nativePrefs, adListener);
Note:
Our SDK is expecting one native ad per request.
Tracking the Native Ad
The SDK will log the impression and handle the click automatically. Please note that you must register the ad's view with the ad object. To make all ad elements of the view clickable register it using:
nativeAdDetails.registerViewForInteraction(yourViewForClicksInterception);
Native Ad Preferences API
Set the number of Native ads to retrieve
public NativeAdPreferences setAdsNumber(int adsNumber){is even supported}
set number of native ads to be received from the server.
ParametersadsNumber - integer of the ads number
Return ValueNativeAdPreferences – current object
Ad's image configuration
public NativeAdPreferences setAutoBitmapDownload(boolean autoBitmapDownload)
You can choose between two options to obtain the ad's image:
get the image pre-cached as a BITMAP.
get the image URL only.
ParametersadsNumber - integer of the ads number autoBitmapDownload - Boolean:
true – native ad object will be loaded automatically with bitmap object
false – native ad wont load the image automatically
Return ValueNatvieAdPreferences – current object
Set Ad's image size
public NativeAdPreferences setPrimaryImageSize(int imageSize)
Set the image size of the ad to be retrieved.
ParametersimageSize - imageSize can get the following values:
0 – for image size 72px X 72px
1 – for image size 100px X 100px
2 – for image size 150px X 150px
3 – for image size 340px X 340px
4 – for image size 1200px X 628px
Default Value is 2
Set Ad's secondary icon size
public NativeAdPreferences setSecondaryImageSize(int imageSize)
Set a secondary icon size of the ad to be retrieved.
Native Ad Details API
Get the Ad's title
public String getTitle()
Return Value: String
Get the Ad's description
public String getDescription()
Get the Ad's rating
public String getRating()
Get the rating of the ad in the Google Play store. The rating range is 1-5.
Return Value: Float
Get the Ad's image URL
public String getImageUrl()
Get the image URL of the ad, according to the selected size.
Get the Ad's image bitmap
public Bitmap getImageBitmap()
Get the image of the ad as a pre-cached bitmap, if requested using the NativeAdPreferences.setAutoBitmapDownload() method.
Return Value: Bitmap
Get the Ad's secondary icon URL
public String getSecondaryImageUrl()
Get the secondary icon URL of the ad, according to the selected size.
Get the Ad's secondary icon bitmap
public Bitmap getSecondaryImageBitmap()
Get the secondary icon of the ad as a pre-cached bitmap, if requested using the NativeAdPreferences.setAutoBitmapDownload() method.
Get the Ad's installs numbers
public String getInstalls()
Get the amount of installs in Google Play store.
Get the Ad's category
public String getCategory()
Get the category of the ad in the Google Play store.
Get the Ad's package name
public String getPackageName()
Get the ad's package name in the Google Play store (for example, "com.magnite.quicksearchbox") in case the ad is "app install" ad.
Get the Ad's call to action
public MagniteNativeAd.CampaignAction getCampaignAction()
Either Launch app or open Google Play.
Return Value: Enum
Get the Ad's call to action text
public MagniteNativeAd.callToAction getCallToAction()
Get a short text to place on the "call to action" button\area.
Child-Directed Ad Serving
In case your app target children, you can pass to Magnite an indication for a child user by sending the user's age. Magnite will use it for applying a child-directed ad serving in case of a child user (under the age of 16)
You can send the user age upon initialization, after providing your DevId and AppId, pass the SDKAdPreferences object with its data:
MagniteSDK.init(this, "Your App ID", new SDKAdPreferences() .setAge(35));
NOTE: Apps that flagged as Designated For Kids in Magnite Portal are treated automatically as child-directed for all ad requests.
Adding Ad Tags
You can add tags to your ad placements. A tag is simply a free style string identifier that can be attached to any ad. Ad Tags will help you optimize your monetization by finding the right balance between ads and the perfect ad-viewing experience for your users.
For example, if you implement a couple of interstitial ads in different places in your application, you can give each of them a different tag, one of them could be "Level1Complete", the other "AfterScoresBoard", then, you can monitor which placement convert better and get more engagement from your users.
To add tags, you simply need to add them to the right places in your code:
Banner, Mrec
AdPreferences prefs = new AdPreferences(); prefs.setAdTag("top_banner"); MagniteBannerAdView banner = new MagniteBannerAdView(this, prefs);
Interstitials
AdPreferences prefs = new AdPreferences(); prefs.setAdTag("game_over"); MagniteInterstitialAd ad = new MagniteInterstitialAd(this); ad.loadAd(prefs);
Native ads
NativeAdPreferences prefs = new NativeAdPreferences(); prefs.setAdTag("level_failed"); MagniteNativeAd nativeAd = new MagniteNativeAd(this); nativeAd.loadAd(prefs);
Ad Tags can only be named using English letters and no more than 200 characters
After getting some traffic, you could see those tags in the portal reports automatically, without extra setup.