Tenjin SDK có thể thu thập dữ liệu doanh thu ở cấp độ hiển thị quảng cáo từ CloudX và gửi các sự kiện doanh thu đến Tenjin. Tích hợp này sẽ gửi dữ liệu liên quan đến doanh thu cho mỗi lần hiển thị quảng cáo được phân phối từ CloudX. Dưới đây là các bước để thực hiện tích hợp:
- Hãy cài đặt bộ công cụ phát triển phần mềm (SDK) CloudX Android bằng cách làm theo hướng dẫn tích hợp: https://docs.cloudx.io/en/android/integration
Vui lòng đảm bảo rằng bạn đã cài đặt phiên bản mới nhất của Tenjin Android SDK (bao gồm phương thức cloudXImpressionFromJSON()). - Chuyển dữ liệu doanh thu sang Tenjin từ hàm gọi lại CloudXAdRevenueListener của CloudX, bằng cách sử dụng đoạn mã mẫu sau đây.
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);
}
}
}Dưới đây là một ví dụ về việc nhập dữ liệu doanh thu theo mức độ hiển thị từ CloudX:
| Tham số | Có bắt buộc không? | Ví dụ |
| định dạng | Không | “banner”, “mrec”, “interstitial”, “rewarded” |
| ad_unit_id | Không | abc-123-banner |
| tên_mạng | Không | meta |
| vị trí_mạng | Không | 1234567890_9876543210 |
| vị trí | Không | màn hình chính |
| doanh thu | Có | 0.0123 |
| tiền tệ | Không | USD |