> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudx.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 集成

> CloudX Android SDK 的 AppsFlyer 广告收入连接器。无需发布方编写胶水代码即可将 CloudX 广告收入转发至 AppsFlyer。

连接器（Connector）用于在 CloudX SDK 与其他产品之间传递数据。AppsFlyer 连接器会将 CloudX 广告收入转发至您的移动归因合作伙伴（MMP），使广告收入与您在 AppsFlyer 中的其他数据一并呈现。只需添加依赖，收入上报即自动生效——CloudX SDK 会在初始化时发现该连接器，并将其加入与 `CloudX.addAdRevenueListener()` 相同的全局广告收入监听器列表。

## 安装

<CodeGroup>
  ```kotlin Kotlin DSL theme={null}
  dependencies {
      implementation("io.cloudx:connector-appsflyer:6.15.0.0")
  }
  ```

  ```groovy Groovy theme={null}
  dependencies {
      implementation 'io.cloudx:connector-appsflyer:6.15.0.0'
  }
  ```
</CodeGroup>

无需任何代码改动。连接器不会初始化 AppsFlyer，它使用您现有的 AppsFlyer 配置和 dev key。

## 要求

* CloudX Android SDK `4.3.0` 或更高版本。
* 您的应用已使用自己的 dev key 集成并初始化 AppsFlyer SDK。连接器仅在编译期依赖 AppsFlyer SDK，因此您的应用需自行声明 `com.appsflyer:af-android-sdk`，运行时使用的是您的版本。
* 受支持的 AppsFlyer SDK 版本：`6.15.0` 至 `7.0.0`（不含 `7.0.0`）。

## 上报内容

连接器会为每次 CloudX 竞得的展示调用一次 AppsFlyer 的 `logAdRevenue`，覆盖所有 CloudX 广告格式——banner、MREC、interstitial、rewarded、native 和 app open。每次调用会携带竞得的广告网络、该次展示的 CloudX 收入估算（USD）以及 CloudX 广告单元、格式和广告位。

<Warning>
  如果您的应用已在 CloudX 广告收入回调中调用 `AppsFlyerLib.logAdRevenue`，请在添加本连接器时移除该代码，否则每次展示都会向 AppsFlyer 重复上报两次。
</Warning>

## 兼容性

| 连接器版本      | AppsFlyer SDK                           | 最低 CloudX SDK |
| ---------- | --------------------------------------- | ------------- |
| `6.15.0.0` | AppsFlyer Android SDK `[6.15.0, 7.0.0)` | `4.3.0`       |

## 自行上报收入

如果您希望自行控制上报调用，可以不使用连接器，直接订阅 CloudX 广告收入：

```kotlin theme={null}
CloudX.addAdRevenueListener { ad ->
    // 使用您自己的字段映射转发至 AppsFlyer 或任何其他目标。
}
```

`CloudX.addAdRevenueListener()` 是稳定的公开接口。请只选择连接器或自行监听其中一种方式，不要同时使用。
