Firebase Integration
1. Prerequisites
- Ensure that both the TradPlus SDK and Firebase SDK are correctly integrated into your project.
- Initialize the SDKs and integrate at least one type of advertisement.
- The TradPlus SDK supports real-time retrieval of ad revenue. Developers can log the Google Analytics
ad_impressionevent by listening to the impression callback to obtain the eCPM value of the currently displayed ad.
2. Code Implementation
Version Information:
| Version | Description |
|---|---|
| V9.5.0.1+ | Optimized; can be called directly without synchronously setting setAdListener |
| V8.8.0.1+ | Provides a global impression callback API. Synchronous execution requires calling setAdListener of the corresponding ad type to receive GlobalImpressionListener monitoring. |
| V8.8.0.1 and below | Get ad revenue through the ad type's onAdImpression |
Implementation Example:
TradPlusSdk.setGlobalImpressionListener(new GlobalImpressionManager.GlobalImpressionListener() {
@Override
public void onImpressionSuccess(TPAdInfo tpAdInfo) {
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
if (tpAdInfo != null) {
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.AD_PLATFORM, "TradPlus");
bundle.putString(FirebaseAnalytics.Param.AD_SOURCE, tpAdInfo.adSourceName);
bundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD");
bundle.putDouble(FirebaseAnalytics.Param.VALUE, tpAdInfo.ecpm / 1000.0);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, bundle);
}
}
});
3. Additional Information
When integrating both Firebase and Google AdMob, you may encounter the following error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/ads/rewarded/RewardedAd
This issue arises due to conflicts between the Firebase and Google AdMob SDKs.
Solution: Use the Firebase Ads SDK version that matches the Google AdMob version, and comment out the original play-services-ads dependency.
// Example version; ensure the Firebase version matches the one recommended by TradPlus
// implementation 'com.google.android.gms:play-services-ads:22.0.0'
implementation 'com.google.firebase:firebase-ads:22.0.0'