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 iOS SDK by following the integration guide: https://docs.cloudx.io/en/ios/integration
Please ensure you have the latest Tenjin iOS SDK installed (>= 1.17.0), which adds CloudX support via the TenjinSDK+CloudXILRD category. - Pass the revenue data to Tenjin from the CloudX revenueListener (or CloudXAdRevenueListener) callback, using the following sample code.
Objective-C #
Objective-C
#import <TenjinSDK/TenjinSDK.h>
#import <TenjinSDK/TenjinSDK+CloudXILRD.h>
/**
Invoked when CloudX records an impression and reports revenue for the ad **/
- (void)didPayRevenueForAd:(CloudXAd *)cloudXAd {
NSLog(@"%s", __PRETTY_FUNCTION__);
// Create JSON object for Tenjin
NSDictionary *impressionDict = @{
@"format": cloudXAd.adFormat ?: @"",
@"ad_unit_id": cloudXAd.adUnitId ?: @"",
@"network_name": cloudXAd.networkName ?: @"",
@"network_placement": cloudXAd.networkPlacement ?: @"",
@"placement": cloudXAd.placement ?: @"",
@"revenue": @(cloudXAd.revenue),
@"currency": @"USD"
};
// Convert to JSON string
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:impressionDict
options:0
error:&error];
if (jsonData && !error) {
NSString *jsonString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
// Send to Tenjin
[TenjinSDK cloudXImpressionFromJSON:jsonString];
NSLog(@"Sent CloudX impression to Tenjin: %@", jsonString);
} else {
NSLog(@"Error creating JSON: %@", error.localizedDescription);
}
}Swift #
Swift
import TenjinSDK
// Conform to CloudX's revenue listener protocol on your ad delegate
extension MyAdDelegate: CloudXAdRevenueListener {
func onAdRevenuePaid(_ cloudXAd: CloudXAd) {
let impressionDict: [String: Any] = [
"ad_format": cloudXAd.adFormat ?? "",
"ad_unit_id": cloudXAd.adUnitId ?? "",
"network_name": cloudXAd.networkName ?? "",
"network_placement": cloudXAd.networkPlacement ?? "",
"placement": cloudXAd.placement ?? "",
"revenue": cloudXAd.revenue,
"currency": "USD"
]
guard
let jsonData = try? JSONSerialization.data(withJSONObject: impressionDict, options: []),
let jsonString = String(data: jsonData, encoding: .utf8)
else {
print("Error creating CloudX impression JSON")
return
}
// Send to Tenjin
TenjinSDK.cloudXImpression(fromJSON: jsonString)
print("Sent CloudX impression to Tenjin: \(jsonString)")
}
}Attach the listener to each ad object (banner, MREC, interstitial, rewarded) before loading the ad, for example:
bannerAd.revenueListener = self
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 |
reference: https://docs.cloudx.io/en/ios/integration