> For the complete documentation index, see [llms.txt](https://aatkit.gitbook.io/ios-integration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aatkit.gitbook.io/ios-integration/advanced/advanced-delegates/statistics-delegate.md).

# Statistics Delegate

### Statistics Delegate

[AATStatisticsDelegate](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatstatisticsdelegate) enables publishers to listen to all the placement-related statistics events. This might be useful e.g. to establish user-related analytics.&#x20;

### Set Statistics Delegate for Placement

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

{% tabs %}
{% tab title="Swift" %}

```swift
placement.statisticsDelegate = self
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
self.placement.statisticsDelegate = self;
```

{% endtab %}
{% endtabs %}

### Complete Code Example

{% hint style="info" %}
The below example can be applied to all types of placements.
{% endhint %}

{% tabs %}
{% tab title="Swift" %}

```swift

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
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec

@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
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aatkit.gitbook.io/ios-integration/advanced/advanced-delegates/statistics-delegate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
