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 Unity SDK by following the integration guide: https://docs.cloudx.io/en/unity/integration
Please ensure you have the latest Tenjin Unity SDK installed (which includes the CloudXImpressionFromJSON() method). - Pass the revenue data to Tenjin from the CloudX revenue callback, using the following sample code.
C# #
C#
using System.Globalization;
using UnityEngine;
using CloudX; // CloudX Unity SDK namespace
[System.Serializable]
public class TenjinCloudXImpressionData
{
public string format;
public string ad_unit_id;
public string network_name;
public string network_placement;
public string placement;
public double revenue;
public string currency;
}
// Subscribe to the CloudX revenue event for each ad type (banner, MREC,
// interstitial, rewarded). Example: CloudXAdsCallbacks.Banner.OnAdRevenuePaid += OnCloudXRevenuePaid;
private void OnCloudXRevenuePaid(CloudXAd cloudXAd)
{
double parsedRevenue = 0.0;
CultureInfo invCulture = CultureInfo.InvariantCulture;
// Parse revenue with culture-invariant formatting
double.TryParse(
string.Format(invCulture, "{0}", cloudXAd.Revenue),
NumberStyles.Any,
invCulture,
out parsedRevenue
);
// Create impression data object for serialization
var impressionDataObject = new TenjinCloudXImpressionData
{
ad_format = cloudXAd.AdFormat.ToString() ?? "",
ad_unit_id = cloudXAd.AdUnitId ?? "",
network_name = cloudXAd.NetworkName ?? "",
network_placement = cloudXAd.NetworkPlacement ?? "",
placement = cloudXAd.Placement ?? "",
revenue = parsedRevenue,
currency = "USD"
};
// Convert to JSON string using JsonUtility
string jsonString = JsonUtility.ToJson(impressionDataObject);
// Send to Tenjin
Tenjin.getInstance("<YOUR-TENJIN-SDK-KEY>").CloudXImpressionFromJSON(jsonString);
Debug.Log("Sent CloudX impression to Tenjin: " + jsonString);
}Here is an example impression level revenue data entry from CloudX:
| 参数 | 必需? | 例子 |
| format | 否 | Banner, Mrec, Interstitial, Rewarded |
| ad_unit_id | 否 | abc-123-banner |
| network_name | 否 | meta |
| network_placement | 否 | 1234567890_9876543210 |
| placement | 否 | home_screen |
| revenue | 是 | 0.0123 |
| currency | 否 | USD |