This article provides code examples of how to integrate impression level revenue from your Mediation to SolarEngine.
Here is an example chart showing the meaning of each parameter and how you should report them.
SDK Field | Max | TopOn | Gromore | Admob | ironSource | Unity | |
Mediation Platform | MediationPlatform | max | topon | Gromore | admob | ironsource | unity |
Monetization Network | adNetworkPlatform | networkName | getNetworkFirmId() Note: Please map the platform names and then reported. | getAdNetworkPlatformName() | getAdSourceName() | adNetwork | getAdSourceName() |
Please provide enum values. | |||||||
Monetization Network Ad Placement ID | adNetworkADID | networkPlacement | getNetworkPlacementId() | getAdNetworkRitId() | getAdUnitId() | instanceId | getAdSourceInstance() |
Ad Type | adType | format | getTopOnAdFormat() | Send different values when integrating different ad placements. | Send different values when integrating different ad placements. | adUnit | Send different values when integrating different ad placements. |
Enum Values 1:Rewarded 2:Splash 3:Interstitial 4:Fullscreen Video 5:Banner 6:Native 7:Native Video 8:Banner (MPU) 9:Instream Video 10:MREC 0:Other | |||||||
Ad eCPM | ecpm | revenue*1000 | getEcpm() | getPreEcpm()/100 | getValueMicros()/1000 | revenue*1000 | getPublisherRevenuePerImpression()*1000 |
Currency | currencyType | USD | getCurrency() | Please confirm with gromore. | getCurrencyCode() | USD | getCurrency() |
Whether rendered successfully | isRenderSuccess | TRUE | TRUE | TRUE | TRUE | TRUE | TRUE |
Google Admob Guide: https://developers.google.com/admob/android/impression-level-ad-revenue
Each ad format has an OnPaidEventListener. During the lifecycle of an ad event, the Google Mobile Ads SDK monitors impression events and invokes the handler with an earned value.
Here is a sample code showing how to process Admob rewarded ads.
import com.google.android.gms.ads.rewarded.RewardedAd;
public class MainActivity extends Activity {
private RewardedAd rewardedAd;
private final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
AdRequest adRequest = new AdRequest.Builder().build();
RewardedAd.load(this, "AD_UNIT_ID",
adRequest, new RewardedAdLoadCallback(){
@Override
public void onAdLoaded(@NonNull RewardedAd ad) {
rewardedAd = ad;
// Set paid event listener
rewardedAd.setOnPaidEventListener(new OnPaidEventListener() {
@Override
public void onPaidEvent(AdValue adValue) {
// TODO: Send the impression-level ad revenue information to your
//preferred analytics server directly within this callback.
// Extract the impression-level ad revenue data.
double valueMicros = adValue.getValueMicros();
String currencyCode = adValue.getCurrencyCode();
int precision = adValue.getPrecisionType();
// Get the ad unit ID.
String adUnitId = rewardedAd.getAdUnitId();
AdapterResponseInfo loadedAdapterResponseInfo = rewardedAd.getResponseInfo().
getLoadedAdapterResponseInfo();
String adSourceName = loadedAdapterResponseInfo.getAdSourceName();
String adSourceId = loadedAdapterResponseInfo.getAdSourceId();
String adSourceInstanceName = loadedAdapterResponseInfo.getAdSourceInstanceName();
String adSourceInstanceId = loadedAdapterResponseInfo.getAdSourceInstanceId();
Bundle extras = rewardedAd.getResponseInfo().getResponseExtras();
String mediationGroupName = extras.getString("mediation_group_name");
String mediationABTestName = extras.getString("mediation_ab_test_name");
String mediationABTestVariant = extras.getString("mediation_ab_test_variant");
//SE SDK processing logic
SEAdImpEventModel seAdImpEventModel = new SEAdImpEventModel();
//Monetization Platform Name
seAdImpEventModel.setAdNetworkPlatform(adSourceName);
//Mediation Platform Name (e.g. admob SDK as "admob")
seAdImpEventModel.setMediationPlatform("admob");
//Displayed Ad Type (Taking Rewarded Ad as an example, adType = 1)
seAdImpEventModel.setAdType(1);
//Monetization Platform App ID
seAdImpEventModel.setAdNetworkAppID(adSourceId);
//Monetization Platform Ad Unit ID
seAdImpEventModel.setAdNetworkADID(adUnitId);
//Ad eCPM
seAdImpEventModel.setEcpm(valueMicros/1000);
//Monetization Platform Currency Type
seAdImpEventModel.setCurrencyType(currencyCode);
//True: rendered success
seAdImpEventModel.setRenderSuccess(true);
//You can add custom properties as needed. Here we do not give examples.
SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel);
//end
}
});
}
});
}
}
ironSource Guide: https://developers.is.com/ironsource-mobile/android/ad-revenue-measurement-integration/
Here is a sample code showing how to process ironSource rewarded ads.
/**
Invoked when the ad was displayed successfully and the impression data was recorded
**/
@Override
public void onImpressionSuccess(ImpressionData impressionData) {
// The onImpressionSuccess will be reported when the rewarded video and interstitial ad is opened.
// For banners, the impression is reported on load success. Log.d(TAG, "onImpressionSuccess" + impressionData);
if (impressionData != null)
{
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.AD_PLATFORM, "ironSource");
bundle.putString(FirebaseAnalytics.Param.AD_SOURCE,impressionData.adNetwork());
bundle.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getAdUnit());
bundle.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.getInstanceName());
bundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
bundle.putDouble(FirebaseAnalytics.Param.VALUE, impressionData.getRevenue());
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, bundle);
//SE SDK processing logic
SEAdImpEventModel seAdImpEventModel = new SEAdImpEventModel();
//Monetization Platform Name
seAdImpEventModel.setAdNetworkPlatform(impressionData.adNetwork());
//Mediation Platform Name, IronSource SDK set "ironSource"
seAdImpEventModel.setMediationPlatform("ironSource");
//Displayed Ad Type (Taking Rewarded Ad as an example, adType = 1) For specific details, refer to adType field in the doc
seAdImpEventModel.setAdType(1);
//Monetization Platform App ID (optional) You can input the appKey in SE SDK.
seAdImpEventModel.setAdNetworkAppID("---SE SDK的appKey---");
//Monetization Platform Ad Unit ID
seAdImpEventModel.setAdNetworkADID(impressionData.getInstanceId());
//Ad eCPM
seAdImpEventModel.setEcpm(impressionData.getRevenue()*1000);
//Monetization Platform Currency Type (Default USD)
seAdImpEventModel.setCurrencyType("USD");
//True: rendered success
seAdImpEventModel.setRenderSuccess(true);
//You can add custom properties as needed. Here we do not give examples.
SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel);
//end
}
}
Max Guide: https://developers.applovin.com/en/android/overview/advanced-settings/
Here is a sample code showing how to process Max rewarded ads.
@Override
void onAdRevenuePaid(final MaxAd ad)
{
double revenue = ad.getRevenue(); // In USD
// Miscellaneous data
String countryCode = AppLovinSdk.getInstance( context ).getConfiguration().getCountryCode(); // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
String networkName = ad.getNetworkName(); // Display name of the network that showed the ad
String adUnitId = ad.getAdUnitId(); // The MAX Ad Unit ID
MaxAdFormat adFormat = ad.getFormat(); // The ad format of the ad (e.g. BANNER, MREC, INTERSTITIAL, REWARDED)
String placement = ad.getPlacement(); // The placement this ad's postbacks are tied to
String networkPlacement = ad.getNetworkPlacement(); // The placement ID from the network that showed the ad
//SE SDK processing logic
SEAdImpEventModel seAdImpEventModel = new SEAdImpEventModel();
//Monetization Platform Name
seAdImpEventModel.setAdNetworkPlatform( ad.getNetworkName());
//Mediation Platform Name (Max SDK set as "Max")
seAdImpEventModel.setMediationPlatform("Max");
//Displayed Ad Type (If rewarded ad, adType = 1)
seAdImpEventModel.setAdType(1);
//Monetization Platform App ID (optional) You can input the appKey in SE SDK.
seAdImpEventModel.setAdNetworkAppID("---SE SDK appKey---");
//Monetization Platform Ad Unit ID
seAdImpEventModel.setAdNetworkADID(ad.getNetworkPlacement());
//Ad eCPM
seAdImpEventModel.setEcpm(ad.getRevenue()*1000);
//Monetization Platform Currency Type (USD)
seAdImpEventModel.setCurrencyType('USD');
//True: rendered success
seAdImpEventModel.setRenderSuccess(true);
SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel);
//You can add custom properties as needed. Here we do not give examples.
//end
}
TopOn Guide: https://docs.toponad.com/#/en-us/android/android_doc/android_sdk_callback_access
Here is a sample code showing how to process TopOn rewarded ads.
ATAdSourceStatusListener adSourceStatusListener = new ATAdSourceStatusListener() {
@Override
public void onAdSourceBiddingAttempt(ATAdInfo adInfo) {
Log.i(TAG, "onAdSourceBiddingAttempt: " + adInfo.toString());
//SE SDK processing logic
SEAdImpEventModel seAdImpEventModel = new SEAdImpEventModel();
//Monetization Platform Name (Please refer to network_firm_id for specific values. If network_firm_id = 6, it represents Mintegral.)
//network_firm_id can be found via https://docs.toponad.com/#/zh-cn/ios/ios_doc/ios_sdk_callback_access?id=network_firm_id
seAdImpEventModel.setAdNetworkPlatform('"Mintegral");
//Mediation Platform Name (TopOn SDK set as "TopOn")
seAdImpEventModel.setMediationPlatform("TopOn");
//Displayed Ad Type (If rewarded ad, adType = 1)
seAdImpEventModel.setAdType(1);
//Monetization Platform App ID (optional) You can input the appKey in SE SDK.
seAdImpEventModel.setAdNetworkAppID("---SE SDK的appKey---");
//Monetization Platform Ad Unit ID
seAdImpEventModel.setAdNetworkADID(adInfo.getNetworkPlacementId());
//Ad eCPM
seAdImpEventModel.setEcpm(adInfo.getEcpm());
//Monetization Platform Currency Type (USD)
seAdImpEventModel.setCurrencyType(adInfo.getCurrency());
//True: rendered success
seAdImpEventModel.setRenderSuccess(true);
//You can add custom properties as needed. Here we do not give examples.
SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel);
//end
}
@Override
public void onAdSourceBiddingFilled(ATAdInfo adInfo) {
Log.i(TAG, "onAdSourceBiddingFilled: " + adInfo.toString());
}
@Override
public void onAdSourceBiddingFail(ATAdInfo adInfo, AdError adError) {
Log.i(TAG, "onAdSourceBiddingFail Info: " + adInfo.toString());
Log.i(TAG, "onAdSourceBiddingFail error: " + adError.getFullErrorInfo());
}
@Override
public void onAdSourceAttempt(ATAdInfo adInfo) {
Log.i(TAG, "onAdSourceAttemp: " + adInfo.toString());
}
@Override
public void onAdSourceLoadFilled(ATAdInfo adInfo) {
Log.i(TAG, "onAdSourceLoadFilled: " + adInfo.toString());
}
@Override
public void onAdSourceLoadFail(ATAdInfo adInfo, AdError adError) {
Log.i(TAG, "onAdSourceLoadFail Info: " + adInfo.toString());
Log.i(TAG, "onAdSourceLoadFail error: " + adError.getFullErrorInfo());
}
};
atRewardVideoAd.setAdSourceStatusListener(adSourceStatusListener);//Rewarded Ad
//atInterstitial.setAdSourceStatusListener(adSourceStatusListener);//Interstitial Ad
//atSplashAd.setAdSourceStatusListener(adSourceStatusListener);//Splash Ad
//atNative.setAdSourceStatusListener(adSourceStatusListener);//Native Ad
//atBannerView.setAdSourceStatusListener(adSourceStatusListener);//Banner
Example for displaying GMBannerAd advertisements:
import com.reyun.solar.engine.SolarEngineManager;
public void onAdShow() {
// banner ad information in the callback
GMAdEcpmInfo gmAdEcpmInfo;
// Monetization Platform Name (Send the non-blank PlatformName value with either of the two methods below)
String adNetworkPlatform = gmAdEcpmInfo.getAdNetworkPlatformName();
String adNetworkPlatform = gmAdEcpmInfo.getCustomAdNetworkPlatformName;
String medationPlatform = "gromore";
// Mediation Platform providing the ad
int adType = 5;
// Ad Type
String adNetworkAppID = "";
// Monetization Platform AppID, send "" if no value
String adNetworkADID = gmAdEcpmInfo.getAdNetworkRitId();
// Monetization Platform Ad Placement ID
float ecpm = gmAdEcpmInfo.getPreEcpm();
// Ad ECPM(Mini Unit: dollar), If Gromore unit is cent, please send ecpm/100.
String currencyType = "USD";
// Please contact Gromore side to confirm the currency type.
boolean isRenderSuccess = true;
// Whether ad is rendered successfully (true: success false: fail)
JSONObject customProperties = new JSONObject();
try {
// Developer custom properties in Json format
customProperties.put("key1","value1");
customProperties.put("key2","value2");
......
} catch (JSONException e) {
///
}
SEAdImpEventModel seAdImpEventModel = new SEAdImpEventModel(adNetworkPlatform, medationPlatform, adType, adNetworkAppID, adNetworkADID, ecpm, currencyType, isRenderSuccess,customProperties);
SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel);
Google Admob Guide: https://developers.google.com/admob/ios/impression-level-ad-revenue
Each ad format has a paidEventHandler property of type GADPaidEventHandler
. During the lifecycle of an ad event, the Google Mobile Ads SDK monitors impression events and invokes the handler with an earned value.
Sample Code
@import GoogleMobileAds;
@import UIKit;
@interface ViewController ()
@property(nonatomic, strong) GADRewardedAd *rewardedAd;
@end
@implementation ViewController
- (void)requestRewardedAd {
__weak ViewController *weakSelf = self;
GADRequest *request = [GADRequest request];
[GADRewardedAd
loadWithAdUnitID:@"AD_UNIT_ID"
request:request
completionHandler:^(GADRewardedAd *ad, NSError *error) {
if (error) {
NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
return;
}
self.rewardedAd = ad;
self.rewardedAd.paidEventHandler = ^void(GADAdValue *_Nonnull value){
ViewController *strongSelf = weakSelf;
NSDecimalNumber *value; = value.value;
GADAdNetworkResponseInfo *adInfo = strongSelf.rewardedAd.responseInfo.loadedAdNetworkResponseInfo;
SEAdImpressionEventAttribute *attribute = [[SEAdImpressionEventAttribute alloc] init];
// Monetization Platform Name
attribute.adNetworkPlatform = adInfo.adSourceName;
// Monetization Platform App ID
attribute.adNetworkAppID = adInfo.adSourceID;
// Displayed Ad Type (Please send values based on adType field description in the doc)
attribute.adType = 5;
// Monetization Platform Ad Unit ID
attribute.adNetworkPlacementID = strongSelf.rewardedAd.adUnitID;
// Currency
attribute.currency = value.currencyCode;
// admob SDK ecpm (Unit: dollar)
attribute.ecpm = [value.value doubleValue]*1000;
// Mediation Platform Name (admob SDK set as "admob")
attribute.mediationPlatform = @"admob";
// Whether ad is rendered successfully
attribute.rendered = YES;
[[SolarEngineSDK sharedInstance] trackAdImpressionWithAttributes:attribute];
};
]};
}
ironSource Guide: https://developers.is.com/ironsource-mobile/ios/ad-revenue-measurement-integration/
To add the ImpressionData listener:
+ (void)addImpressionDataDelegate:(id<ISImpressionDataDelegate>)delegate;
Demo Example
Set delegate and ImpressionData listener:
self.impressionDataDelegate = [[DemoImpressionDataDelegate alloc] init];
[IronSource addImpressionDataDelegate:self.impressionDataDelegate];
Create custom class to receive ironSource callback:
@interface DemoImpressionDataDelegate : NSObject<ISImpressionDataDelegate>
@end
@implementation DemoImpressionDataDelegate
Sample Code when ad is successfully displayed:
- (void)impressionDataDidSucceed:(ISImpressionData *)impressionData {
SEAdImpressionEventAttribute *attribute = [[SEAdImpressionEventAttribute alloc] init];
// Monetization Platform Name
attribute.adNetworkPlatform = impressionData.ad_network
// Displayed Ad Type (Please send values based on adType field description in the doc)
attribute.adType = 1;
// Monetization Platform Ad Unit ID
attribute.adNetworkPlacementID = impressionData.placement;
// Currency USD
attribute.currency = @"USD";
// ironsource SDK ecpm (Unit: USD Dollar)
attribute.ecpm = impressionData.revenue*1000;
// Mediation Platform Name (ironsource SDK set as "ironsource")
attribute.mediationPlatform = @"ironsource";
// Whether ad is rendered successfully
attribute.rendered = YES;
[[SolarEngineSDK sharedInstance] trackAdImpressionWithAttributes:attribute];
}
@end
Max Guide: https://developers.applovin.com/en/ios/overview/advanced-settings/
Sample Code
// Callback from MAX when ad revenue is detected.
- (void)didPayRevenueForAd:(MAAd *)ad
{
SEAdImpressionEventAttribute *attribute = [[SEAdImpressionEventAttribute alloc] init];
// Monetization Platform Name
attribute.adNetworkPlatform = ad.networkName;
// Monetization Platform App ID
attribute.adNetworkAppID = "";
// Displayed Ad Type
attribute.adType = ad.format; // Please refer to adType field description in the doc to convert MAAdFormat into corresponding values.)
// Monetization Platform Ad Placement ID
attribute.adNetworkPlacementID = ad.networkPlacement;
// Currency USD
attribute.currency = @"USD";
// MAX SDK ecpm (Unit: USD Dollar)
attribute.ecpm = ad.revenue*1000;
// Mediation Platform Name (max SDK set as "max")
attribute.mediationPlatform = @"max";
// Whether ad is rendered successfully
attribute.rendered = YES;
[[SolarEngineSDK sharedInstance] trackAdImpressionWithAttributes:attribute];
}
TopOn Guide: https://docs.toponad.com/#/en-us/android/android_doc/android_sdk_callback_access
Sample Code
// The ad source info returned in the "extra" parameter from TopOn SDK callback.
- (void)didFinishLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary*)extra {
//Different ads have different keys, e.g. Bannner uses kATBannerDelegateExtraNetworkIDKey.
int network_firm_id = [extra[kATBannerDelegateExtraNetworkIDKey] intValue];
NSString* network_placement_id = extra[kATADDelegateExtraNetworkPlacementIDKey];
NSString* adunit_format = extra[kATADDelegateExtraFormatKey];
//Different ads have different keys, e.g. Bannner uses kATBannerDelegateExtraAdSourceIDKey.
NSString* adsource_id = extra[kATBannerDelegateExtraAdSourceIDKey];
//Different ads have different keys, e.g. Bannner uses kATBannerDelegateExtraPrice.
double adsource_price = [extra[kATBannerDelegateExtraPrice] doubleValue];
NSString* precision = extra[kATADDelegateExtraPrecisionKey];
NSString* currency = extra[kATADDelegateExtraCurrencyKey];
SEAdImpressionEventAttribute *attribute = [[SEAdImpressionEventAttribute alloc] init];
// Monetization Platform Name
// https://docs.toponad.com/#/zh-cn/ios/ios_doc/ios_sdk_callback_access?id=network_firm_id
attribute.adNetworkPlatform = // network_firm_id (Please refer to Network Firm Id Table. e.g. 6=Mintegral)
// Displayed Ad Type (Please refer to adType field description in the doc and define the adunit_format for various ad types.)
attribute.adType = ;
// Monetization Platform Ad Placement ID
attribute.adNetworkPlacementID = network_placement_id;
// Currency (USD)
attribute.currency = currency;
// SDK ecpm (Unit: Dollar)
attribute.ecpm = adsource_price;
// Mediation Platform Name (topon SDK set as "topon")
attribute.mediationPlatform = @"topon";
// Whether ad is rendered successfully
attribute.rendered = YES;
[[SolarEngineSDK sharedInstance] trackAdImpressionWithAttributes:attribute];
}
Example of displaying ABUBannerAd advertisements:
- (void)bannerAdDidBecomeVisible:(ABUBannerAd *_Nonnull)bannerAd bannerView:(UIView *)bannerView {
ABURitInfo *info = [bannerAd getShowEcpmInfo];
SEAdImpressionEventAttribute *attribute = [[SEAdImpressionEventAttribute alloc] init];
// Monetization platform name
attribute.adNetworkPlatform = info.adnName;
// App ID on monetization platform. If not obtained, send ""
attribute.adNetworkAppID = @"App ID";
// Displayed ad type
attribute.adType = SolarEngineAdTypeBanner;
// Ad placement ID
attribute.adNetworkPlacementID = [bannerAd getAdNetworkRitId];
// Currency for displaying revenue, following ISO 4217 currency codes. Please confirm with GroMore about the currency (CNY/USD)。
attribute.currency = @"USD";
// GroMore SDK eCPM (Mini Unit: cent),SolarEngine SDK eCPM (Unit: Dollar)
attribute.ecpm = [info.ecpm doubleValue]/100;
// Mediation platform identifier, GroMore SDK is set as "gromore"
attribute.mediationPlatform = @"gromore";
// Whether the ad is rendered successfully
attribute.rendered = YES;
attribute.customProperties = @{
@"Key1": @"Value1",
@"Key2": @"Value2"
};
[[SolarEngineSDK sharedInstance] trackAdImpressionWithAttributes:attribute];
}
Note:
1. The "currency" variable in SEAdImpressionEventAttribute is not provided by the GroMore SDK. Developers can pass "CNY" as a value for this variable.
2. The "mediaPlatform" variable in SEAdImpressionEventAttribute should be set to "gromore" when using the GroMore SDK and passed to the SolarEngine SDK.
3. In the GroMore SDK, the unit for eCPM is in cents, while in the SolarEngine SDK, the unit for eCPM is in yuan. Therefore, it is necessary to convert between the two units.