# Piano Analytics

The Piano Analytics dispatcher automatically dispatches events to the [Piano SDK](https://developers.atinternet-solutions.com/piano-analytics/data-collection/sdks/ios-swift), including AT tags when they are available.

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

```
https://github.com/BatchLabs/Batch-iOS-piano-dispatcher.git
```

{% endtab %}

{% tab title="CocoaPods" %}
{% code title="Podfile" %}

```
pod 'BatchPianoDispatcher'
```

{% endcode %}
{% endtab %}

{% tab title="Carthage" %}
{% code title="Cartfile" %}

```
github "BatchLabs/Batch-iOS-piano-dispatcher"
```

{% endcode %}
{% endtab %}
{% endtabs %}

By default the dispatcher will handle UTM tracking and will send events only as Piano [On-site Ads events](https://developers.atinternet-solutions.com/piano-analytics/data-collection/how-to-send-events/standard-events#onsite-ads).

Register the dispatcher and update the configuration as following:

```swift
@import BatchPianoDispatcher

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    let pianoDispatcher = BatchPianoDispatcher.instance
    
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // PA Configuration
        pa.setConfiguration(ConfigurationBuilder()
            .withCollectDomain("logsx.xiti.com")
            .withSite(123456789)
            .build()
        )
        // Uncomment if you want to enable custom event sending (default: false)
        //pianoDispatcher.enableCustomEvents = true

        // Uncomment if you want to disable On-Site Ads event sending (default: true)
        //pianoDispatcher.enableOnSiteAdsEvents = false

        // Uncomment if you want to disable UTM tracking (default: true)
        //pianoDispatcher.enableUTMTracking = false
        
        BatchEventDispatcher.add(pianoDispatcher)
        
        [...]

        BatchSDK.start(withAPIKey: "YOUR_API_KEY")
        return true
    }
}
```

{% hint style="info" %}
If you enable custom events, you also need to define them in your Piano Data Model. If so, please refer to the [custom event/property list](https://github.com/BatchLabs/Batch-iOS-piano-dispatcher/blob/master/Sources/BatchPianoDispatcher/BatchPianoDispatcher.swift#L27).
{% endhint %}
