The Tenjin SDK can listen to CloudX impression level revenue data and send revenue events to Tenjin. This integration will send revenue related data for each ad impression served from CloudX. Here are the steps to integrate:
- Install the CloudX Android SDK by following the integration guide: https://docs.cloudx.io/en/android/integration
Please ensure you have the latest Tenjin Android SDK installed (which includes the cloudXImpressionFromJSON() method). - Pass the revenue data to Tenjin from the CloudX CloudXAdRevenueListener callback, using the following sample code.
Kotlin
Kotlin
import com.tenjin.android.TenjinSDK
import io.cloudx.sdk.CloudXAd
import io.cloudx.sdk.CloudXAdRevenueListener
import org.json.JSONObject
class MainActivity : AppCompatActivity(), CloudXAdRevenueListener {
// Attach this listener to each ad (banner / MREC / interstitial / rewarded)
// before loading the ad, e.g.:
// bannerAd.revenueListener = this
override fun onAdRevenuePaid(cloudXAd: CloudXAd) {
// Create JSON object for Tenjin
val impressionData = JSONObject().apply {
put("ad_format", cloudXAd.adFormat?.toString() ?: "")
put("ad_unit_id", cloudXAd.adUnitId ?: "")
put("network_name", cloudXAd.networkName ?: "")
put("network_placement", cloudXAd.networkPlacement ?: "")
put("placement", cloudXAd.placement ?: "")
put("revenue", cloudXAd.revenue)
put("currency", "USD")
}
val jsonString = impressionData.toString()
// Send to Tenjin
TenjinSDK.getInstance(this, "<YOUR-TENJIN-SDK-KEY>")
.eventAdImpressionCloudX(jsonString)
Log.d("Tenjin", "Sent CloudX impression to Tenjin: $jsonString")
}
}Java #
JavaScript
import com.tenjin.android.TenjinSDK;
import io.cloudx.sdk.CloudXAd;
import io.cloudx.sdk.CloudXAdRevenueListener;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity implements CloudXAdRevenueListener {
// Attach this listener to each ad (banner / MREC / interstitial / rewarded)
// before loading the ad, e.g.:
// bannerAd.setRevenueListener(this);
@Override
public void onAdRevenuePaid(CloudXAd cloudXAd) {
try {
JSONObject impressionData = new JSONObject();
impressionData.put("format",
cloudXAd.getAdFormat() != null ? cloudXAd.getAdFormat().toString() : "");
impressionData.put("ad_unit_id",
cloudXAd.getAdUnitId() != null ? cloudXAd.getAdUnitId() : "");
impressionData.put("network_name",
cloudXAd.getNetworkName() != null ? cloudXAd.getNetworkName() : "");
impressionData.put("network_placement",
cloudXAd.getNetworkPlacement() != null ? cloudXAd.getNetworkPlacement() : "");
impressionData.put("placement",
cloudXAd.getPlacement() != null ? cloudXAd.getPlacement() : "");
impressionData.put("revenue", cloudXAd.getRevenue());
impressionData.put("currency", "USD");
String jsonString = impressionData.toString();
// Send to Tenjin
TenjinSDK.getInstance(this, "<YOUR-TENJIN-SDK-KEY>")
.cloudXImpressionFromJSON(jsonString);
Log.d("Tenjin", "Sent CloudX impression to Tenjin: " + jsonString);
} catch (JSONException e) {
Log.e("Tenjin", "Error creating CloudX impression JSON", e);
}
}
}Here is an example impression level revenue data entry from CloudX:
| Parameter | Required? | Example |
| format | No | “banner”, “mrec”, “interstitial”, “rewarded” |
| ad_unit_id | No | abc-123-banner |
| network_name | No | meta |
| network_placement | No | 1234567890_9876543210 |
| placement | No | home_screen |
| revenue | Yes | 0.0123 |
| currency | No | USD |