ILRD
With Impression Level revenue data (ILRD), you can track and collect ad data.
|
Parent class |
Method |
|
InterstitialAdDelegate |
|
|
NativeAdDelegate |
|
|
RewardedAdDelegate |
|
|
BannerAdViewDelegate |
|
Each of these methods has the ImpressionData parameter with a single method, rawData. This method returns a JSON string with ILRD (see the table below).
Note
The didTrackImpressionWithData method only fires after an ad impression is counted.
-
Logger as a pure function:
struct NetworkData: Decodable { let name: String let ad_unit_id: String } struct ImpressionDataModel: Decodable { let ad_unit_id: String let adType: String let currency: String let revenue: String let revenueUSD: String let precision: String let network: NetworkData } func logImpression(_ impressionData: ImpressionData?, tag: String = "Ad") { guard let raw = impressionData?.rawData else { print("[\(tag)] Impression: no data") return } guard let jsonData = raw.data(using: .utf8) else { print("[\(tag)] Impression: invalid encoding") return } do { let parsed = try JSONDecoder().decode(ImpressionDataModel.self, from: jsonData) print(""" [\(tag) Impression] ├─ adUnitId: \(parsed.ad_unit_id) ├─ adType: \(parsed.adType) ├─ currency: \(parsed.currency) ├─ revenue: \(parsed.revenue) ├─ revenueUSD: \(parsed.revenueUSD) ├─ precision: \(parsed.precision) ├─ networkName: \(parsed.network.name) └─ networkAdUnitId: \(parsed.network.ad_unit_id) """) } catch { print("[\(tag)] Impression parse error: \(error.localizedDescription)") print("[\(tag)] Raw: \(raw)") } } -
Callbacks for different ad code formats that support the built-in Logger:
// MARK: - Interstitial func interstitialAd(_ ad: InterstitialAd, didTrackImpressionWith impressionData: ImpressionData?) { logImpression(impressionData, tag: "Interstitial") } // MARK: - Rewarded func rewardedAd(_ ad: RewardedAd, didTrackImpressionWith impressionData: ImpressionData?) { logImpression(impressionData, tag: "Rewarded") } // MARK: - Native func nativeAd(_ ad: NativeAd, didTrackImpressionWith impressionData: ImpressionData?) { logImpression(impressionData, tag: "Native") } // MARK: - AppOpen func appOpenAd(_ ad: AppOpenAd, didTrackImpressionWith impressionData: ImpressionData?) { logImpression(impressionData, tag: "AppOpen") } // MARK: - Banner func adView(_ adView: AdView, didTrackImpression impressionData: ImpressionData?) { logImpression(impressionData, tag: "Banner") }
Available data
You can parse rawData to obtain the following information:
|
Key |
Type |
Description |
|
|
string |
A unique ad unit ID. |
|
|
string |
The type of an ad:
|
|
|
string |
The currency that an ad network uses. |
|
|
string |
Revenue from an impression in the ad network currency. The currency specified in the |
|
|
string |
Revenue from an impression, converted to USD. |
|
|
string |
The accuracy of the
|
|
|
string |
The name of the ad network that served the impression. |
|
|
string |
A unique ad unit ID in the network that served the ad. |