Impression Level Data - cleveradssolutions/CAS-iOS GitHub Wiki

⚡ Before you start
Make sure you have correctly Initialize CAS.


CleverAdsSolutions enables you to access detailed information for each impression through the impressions callback APIs. The information includes, for example, which demand source served the ad, the expected or exact revenue associated with it. In addition, it contains granular details to allow you to analyze and, ultimately, optimize user acquisition strategies.

Ad Impression

CASImpression (id<CASStatusHandler> for Objective-C) is an interface for getting detailed information about the current ad impression, such as revenue and ad creative details.

Each ad format has a callback to receive an AdImpression about the current impression.
The code below demonstrates how to handle impression events for Interstitial ad and Banner ad:

Swift
class AnyViewController: UIViewController, CASPaidCallback, CASBannerDelegate {
    @IBOutlet var bannerView: CASBannerView
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Set CASBannerDelegate to CASBannerView
        bannerView.adDelegate = self
    }

    func presentInterstitial() {
        // Present Interstitial ads with CASPaidCallback parameter 
        let manager: CASMediationManager = AppDelegate.getMediationManager()
        manager.presentInterstitial(fromRootViewController: self, callback: self)
    }
    
    func presentRewarded() {
        // Present Rewarded ads with CASPaidCallback parameter 
        let manager: CASMediationManager = AppDelegate.getMediationManager()
        manager.presentRewarded(fromRootViewController: self, callback: self)
    }

    // MARK: CASPaidCallback implementation
    
    func didPayRevenue(for ad: CASImpression) {
        // Get ad details using ad parameter
        let impression: CASImpression = ad
    }

    // MARK: CASBannerDelegate implementation
    
    func bannerAdView(_ adView: CASBannerView, willPresent impression: CASImpression) {
        // Get ad details using impression parameter
    }
}
Objective-C
@interface AnyViewController : UIViewController<CASPaidCallback, CASBannerDelegate>
@property (strong, nonatomic) IBOutlet CASBannerView *bannerView;
@end

@implementation AnyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Set CASBannerDelegate to CASBannerView
    [self.bannerView setAdDelegate:self];
}

- (IBAction)presentInterstitial:(id)sender {
    // Present Interstitial ads with CASPaidCallback parameter 
    CASMediationManager* manager = [AppDelegate getMediationManager];
    [manager presentInterstitialFromRootViewController:self callback:self];
}

- (IBAction)presentRewarded:(id)sender {  
    // Present Rewarded ads with CASPaidCallback parameter
    CASMediationManager* manager = [AppDelegate getMediationManager];
    [manager presentRewardedAdFromRootViewController:self callback:self];
}

#pragma mark CASPaidCallback implementation

- (void)didPayRevenueFor:(id<CASStatusHandler>)ad{
    // Get ad details using ad parameter
}

#pragma mark CASBannerDelegate implementation

- (void)bannerAdView:(CASBannerView *)adView willPresent:(id<CASStatusHandler>)impression {
    // Get ad details using impression parameter
}

@end

Ad revenue

Use the cpm property to get a revenue estimate for the current impression.
The value of the cpm property is Cost Per Mille estimated impressions. To earn per impression revenue, follow these steps:

let cpm: Double = impression.cpm

You can also check the precision estimate for the cpm value, as shown in the following example:

let precision: CASPriceAccuracy = impression.priceAccuracy
if (precision == CASPriceAccuracy.floor) {
    // The value is minimum eCPM, obtained from the ad network waterfall configuration.
} else if (precision == CASPriceAccuracy.bid) {
    // The value is exact and committed per 1000 impressions
} else{
    // The value is not disclosed by the demand source. cpm will return 0. 
}

Ad creative

You can also retrieve information about the current ad (such as its mediated network and creative ID), and you will be able to report creative issues for that ad to our Ad review team.

let placementType: CASType = impression.adType
let creativeId: String? = impression.creativeIdentifier
let networkName: String = impression.network
let networkSDKVersion: String = impression.versionInfo
let casUnitId: String = impression.identifier

Warning

impression.creativeIdentifier may return nil.

A list of all supported networks can be found in AdNetwork class. For example:

if (networkName == CASNetwork.vungle) {
    // Impression from Vungle network.
}

User ad summary

CAS count the number of ad impressions and the total revenue of all formats at the time of a new impression.

let totalImpressions: Int = impression.impressionDepth
let totalRevenue: Double = impression.lifetimeRevenue

Note

Progress is saved between sessions until the user clears your app's data.

Automatic collect ad revenue

The CleverAdsSolution SDK have feature to automatically logs the ad_impression event whenever your users see an ad impression. Optionally, the alternative event name can be CAS_Impression.

⭐ Contact support for details of enabling automatic logs the events to Google Analytics from your CAS application.

Custom collect ad revenue

The following code shows an implementation example for log AD_IMPRESSION event to Google Analytics.

if impression.priceAccuracy == .undisclosed { return }
        
let revenue: Double = impression.cpm / 1000.0

Analytics.logEvent(
   AnalyticsEventAdImpression,
   parameters: [
       AnalyticsParameterAdPlatform: "CAS",
       AnalyticsParameterAdSource: impression.network,
       AnalyticsParameterAdFormat: impression.adType.description,
       AnalyticsParameterAdUnitName: impression.identifier,
       AnalyticsParameterValue: revenue,
       // All CAS revenue is sent in USD 
       AnalyticsParameterCurrency: "USD",
   ])
⚠️ **GitHub.com Fallback** ⚠️