ILRD

With Impression Level revenue data (ILRD), you can track and collect ad data.

Parent class

Method

InterstitialAdDelegate

didTrackImpression

NativeAdDelegate

didTrackImpression

RewardedAdDelegate

didTrackImpression

BannerAdViewDelegate

bannerAdView(_:didTrackImpression:)

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.

  1. 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)")
        }
    }
    
  2. 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

ad_unit_id

string

A unique ad unit ID.

adType

string

The type of an ad:

  • Inline or sticky banner.

  • Interstitial ad.

  • Native ad.

  • Rewarded ad.

  • App open ad.

currency

string

The currency that an ad network uses.

revenue

string

Revenue from an impression in the ad network currency. The currency specified in the currency field is used.

revenueUSD

string

Revenue from an impression, converted to USD.

precision

string

The accuracy of the revenue value. Acceptable values:

  • publisher_defined: The value that takes into account the CPM floor from the mediation interface.

  • estimated: The value based on automatic strategies.

network.name

string

The name of the ad network that served the impression.

network.ad_unit_id

string

A unique ad unit ID in the network that served the ad.