AATKit iOS Integration
Release Notes
  • Start
    • Setup
      • Minimum iOS Version
      • Cocoapods
      • Swift Package Manager
      • AATKit Reporting
      • App Transport Security (ATS)
      • SKAdNetwork
    • Initialization
    • Consent
      • General Handling
      • Managed Consent
        • Google CMP
        • Sourcepoint CMP
        • SFBX (AppConsent) CMP
      • Vendor Consent
      • Simple Consent
    • Plugins documentation
    • Additional Information
  • Formats
    • Introduction
    • Banner
      • Auto Load Banner
      • Multi-Size Auto Load Banner
      • Banner Cache
      • Infeed Banner
      • Asynchronous Infeed Banner
      • Sticky Banner
      • Multi-Size Banner
    • Fullscreen (Interstitial)
    • AppOpen (Google)
    • Rewarded Video
      • Server-Side Verification (SSV)
    • Native Ad
      • Basic Integration
      • Asynchronous Basic Integration
      • Network Specifics
        • Native Ads: Google
        • Native Ads: Applovin
  • Ad Networks
    • Customize Ad Networks
    • Privacy Requirements
    • Google Mobile Ads SDK
    • AppNexus Custom Interstitial Auto Dismiss Delay
    • FeedAd Banner Options
    • AmazonHB
  • Advanced
    • Targeting
      • Key-Value Targeting
      • User Targeting
      • Content Targeting URL
    • Frequency Capping
    • Advanced Delegates
      • Reports Delegate
      • Impression Delegate (ILRD)
      • Statistics Delegate
    • AATKit's Size
    • Ad Space and Fill Rate
    • Shake Debug
    • Publisher Provided ID
    • Child-directed Support
    • Disabling Ad Networks
    • Geo Tracking
    • Ad Quality
    • Creatives History
  • Other
    • AdMob Custom Events
    • Datonomy
    • Reference
      • Classes
        • AATConfiguration
        • AATRuntimeConfiguration
        • AATManagedConsent
        • AATVendorConsent
        • AATSimpleConsent
        • AATAdInfo
        • AATBannerConfiguration
        • AATBannerRequest
        • AATBannerCacheConfiguration
        • AATBannerAlign
        • AATPlacementHistoryInfo
        • AATReward
        • AATRewardedAdSSVInfo
        • AATNativeAdRating
        • AATImpression
        • AATPriceInfo
        • AATAdNetworksOptions
          • AATAppNexusOptions
          • AATFeedAdOptions
          • AATAdMobOptions
          • AATDFPOptions
          • AATDatonomyOptions
        • AATDebugInfo
        • AATDebugScreenConfiguration
        • AATUserTargeting
        • AATCollapsibleBannerOptions
      • Protocols
        • AATDelegate
        • AATManagedConsentDelegate
        • AATVendorConsentDelegate
        • AATPlacement
        • AATStickyBannerPlacement
        • AATStickyBannerPlacementDelegate
        • AATMultiSizeBannerPlacement
        • AATMultiSizeBannerPlacementDelegate
        • AATInfeedBannerPlacement
        • AATInfeedBannerPlacementDelegate
        • AATAsyncInfeedBannerPlacement
        • AATBannerRequestDelegate
        • AATBannerCache
        • AATBannerCacheDelegate
        • AATBannerCacheStatusDelegate
        • AATAutoLoadBannerPlacement
        • AATAutoLoadBannerPlacementDelegate
        • AATAutoLoadMultiSizeBannerPlacement
        • AATAutoLoadMultiSizeBannerPlacementDelegate
        • AATFullscreenPlacement
        • AATFullscreenPlacementDelegate
        • AATAppOpenAdPlacement
        • AATAppOpenPlacementDelegate
        • AATRewardedVideoPlacement
        • AATRewardedVideoPlacementDelegate
        • AATNativeAdPlacement
        • AATNativePlacementDelegate
        • AATAsyncNativeAdPlacement
        • AATNativeAdData
        • AATReportsDelegate
        • AATImpressionDelegate
        • AATStatisticsDelegate
      • Enumerations
        • AATAdNetwork
        • AATGender
        • AATLogLevel
        • AATManagedConsentState
        • NonIABConsent
        • AATBannerPlacementSize
        • AATBannerSize
        • HorizontalAlign
        • VerticalAlign
        • AATMediationType
        • AATImpressionPricePrecisionType
  • Samples
Powered by GitBook
On this page
  • Statistics Delegate
  • Set Statistics Delegate for Placement
  • Complete Code Example
  1. Advanced
  2. Advanced Delegates

Statistics Delegate

Listen to placements' statistics events

Last updated 5 months ago

Statistics Delegate

enables publishers to listen to all the placement-related statistics events. This might be useful e.g. to establish user-related analytics.

Set Statistics Delegate for Placement

Use the following code to set the statistics delegate for a specific placement:

placement.statisticsDelegate = self
self.placement.statisticsDelegate = self;

Complete Code Example

The below example can be applied to all types of placements.


class ViewController: UIViewController {
    // Create the placement
    lazy var placement = AATSDK.createStickyBannerPlacement(name: "<PLACEMENT_NAME>", size: .banner320x50)
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // [IMPORTANT] Notify AATKit about the currently active view controller
        AATSDK.controllerViewDidAppear(controller: self)
        
        // Set placement delegate to listen to the callbacks
        placement.delegate = self
        // Set placement statistics delegate to listen to the statistics callbacks
        placement.statisticsDelegate = self
        
        // Get the banner view
        if let bannerAdView = placement.getPlacementView() {
            view.addSubview(bannerAdView)
            // Change the bannerAdView frame to your desired location on the screen
        }
        
        // reload the banner placement each 30 seconds.
        placement.startAutoReload()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // [IMPORTANT] Remove the currently active view controller
        AATSDK.controllerViewWillDisappear()
        // [IMPORTANT] Stop placement autoreload
        placement?.stopAutoReload()
    }
}

// MARK: - AATStickyBannerPlacementDelegate
extension ViewController: AATStickyBannerPlacementDelegate {
    func aatHaveAd(placement: AATPlacement) {
        // The placement has a new banner ad
    }

    func aatNoAd(placement: AATPlacement) {
        // No ad available
    }
    
    func aatAdCurrentlyDisplayed(placement: AATPlacement) {
        // Ad has been displayed on the screen
    }

    func aatResumeAfterAd(placement: AATPlacement) {
        // Back to the app after clicking on the ad
    }
}

// MARK: - AATStatisticsDelegate
extension ViewController: AATStatisticsDelegate {
    func AATKitCountedAdSpace(placement: AATPlacement?) {
        // An ad space counted
    }

    func AATKitCountedRequest(placement: AATPlacement?, for network: AATAdNetwork) {
        // A request counted
    }

    func AATKitCountedResponse(placement: AATPlacement?, for network: AATAdNetwork) {
        // A response counted
    }

    func AATKitCountedImpression(placement: AATPlacement?, for network: AATAdNetwork) {
        // An impression counted
    }

    func AATKitCountedVImpression(placement: AATPlacement?, for network: AATAdNetwork) {
        // A viewable impression counted
    }

    func AATKitCountedClick(placement: AATPlacement?, for network: AATAdNetwork) {
        // A click counted
    }

    func AATKitCountedDirectDealImpression(placement: AATPlacement?, for network: AATAdNetwork) {
        // A direct deal impression counted
    }

    func AATKitCountedMediationCycle(placement: AATPlacement?) {
        // A mediation cycle counted
    }
}

@interface ViewController () <AATStickyBannerPlacementDelegate, AATStatisticsDelegate>
@property id<AATStickyBannerPlacement> placement;
@end

@implementation ViewController
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    // [IMPORTANT] Notify AATKit about the currently active view controller
    [AATSDK controllerViewDidAppearWithController:self];
    
    // Create the placement
    self.placement = [AATSDK createStickyBannerPlacementWithName:@"<PLACEMENT_NAME>" size:AATBannerPlacementSizeBanner300x50];
    
    // Set placement delegate to listen to the callbacks
    self.placement.delegate = self;
    // Set placement statistics delegate to listen to the statistics callbacks
    self.placement.statisticsDelegate = self
    
    // Get the banner view
    UIView *bannerAdView = [self.placement getPlacementView];
    [self.view addSubview:bannerAdView];
    // Change the bannerAdView frame to your desired location on the screen
    
    //reload the banner placement each 30 seconds.
    [self.placement startAutoReload];
    // or set refresh time manually
    [self.placement startAutoReloadWithSeconds:30];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // [IMPORTANT] Remove the currently active view controller
    [AATSDK controllerViewWillDisappear];
    // [IMPORTANT] Stop placement autoreload
    [self.placement stopAutoReload];
}

#pragma mark - AATStickyBannerPlacementDelegate
- (void)aatHaveAdWithPlacement:(id<AATPlacement>)placement {
    // The placement has a new banner ad
}

- (void)aatNoAdWithPlacement:(id<AATPlacement>)placement {
    // No ad available
}

- (void)aatAdCurrentlyDisplayedWithPlacement:(id<AATPlacement>)placement {
    // Ad has been displayed on the screen
}

- (void)aatResumeAfterAdWithPlacement:(id<AATPlacement>)placement {
    // Back to the app after clicking on the ad
}

#pragma mark - AATStatisticsDelegate
- (void)AATKitCountedAdSpaceWithPlacement:(id <AATPlacement> _Nullable)placement {
    // An ad space counted
}

- (void)AATKitCountedClickWithPlacement:(id <AATPlacement> _Nullable)placement for:(enum AATAdNetwork)network {
    // A click counted
}

- (void)AATKitCountedDirectDealImpressionWithPlacement:(id <AATPlacement> _Nullable)placement for:(enum AATAdNetwork)network {
    // A direct deal impression counted
}

- (void)AATKitCountedImpressionWithPlacement:(id <AATPlacement> _Nullable)placement for:(enum AATAdNetwork)network {
    // An impression counted
}

- (void)AATKitCountedMediationCycleWithPlacement:(id <AATPlacement> _Nullable)placement {
    // A mediation cycle counted
}

- (void)AATKitCountedRequestWithPlacement:(id <AATPlacement> _Nullable)placement for:(enum AATAdNetwork)network {
    // A request counted
}

- (void)AATKitCountedResponseWithPlacement:(id <AATPlacement> _Nullable)placement for:(enum AATAdNetwork)network {
    // A response counted
}

- (void)AATKitCountedVImpressionWithPlacement:(id <AATPlacement> _Nullable)placement for:(enum AATAdNetwork)network {
    // A viewable impression counted
}
@end
AATStatisticsDelegate