在应用中接收归因数据
安装 AI Agent 工具
在你的 AI 编程工具中完成整个 Adapty SDK 集成。 了解更多
claude plugin marketplace add adaptyteam/adapty-sdk-integration-skill
claude plugin install adapty-sdk-integration@adapty
gh skill install adaptyteam/adapty-sdk-integration-skill
gemini skills install https://github.com/adaptyteam/adapty-sdk-integration-skill
git clone https://github.com/adaptyteam/adapty-sdk-integration-skill.git
cp -r adapty-sdk-integration-skill/skills/adapty-sdk-integration ~/.agents/skills/
可安装到任何支持技能的 AI 工具。之后更新请运行 npx skills update。
npx skills add adaptyteam/adapty-sdk-integration-skill
安装后,在你的项目中运行该技能:
/adapty-sdk-integration
当 Adapty 将安装匹配到某个推广活动时,它会在 onInstallationDetailsSuccess 回调中将归因数据返回给你的应用。利用这些数据,可以根据带来安装的渠道或活动来个性化用户体验。
归因数据以嵌套的 attribution 对象形式包含在 payload 字段中,包含以下字段:
| 字段 | 描述 |
|---|---|
channel | 获客渠道(例如 facebook、tiktok、google、organic) |
campaign_id | 广告系列标识符 |
campaign_name | 广告系列名称 |
adset_id | 广告组标识符 |
adset_name | 广告组名称 |
ad_id | 广告/素材标识符 |
ad_name | 广告/素材名称 |
所有字段均为可选项。对于自然流量安装或无法确定归因来源的情况,payload 字段中不包含 attribution 对象。
如需在应用中读取归因数据:
Adapty.delegate = self
nonisolated func onInstallationDetailsSuccess(_ details: AdaptyInstallationDetails) {
guard
let payloadDict = details.payload?.dictionary,
let attribution = payloadDict["attribution"] as? [String: Any]
else { return }
let channel = attribution["channel"] as? String
let campaignName = attribution["campaign_name"] as? String
let adName = attribution["ad_name"] as? String
print("Channel: \(channel ?? "organic")")
} Adapty.setOnInstallationDetailsListener(object : OnInstallationDetailsListener {
override fun onInstallationDetailsSuccess(details: AdaptyInstallationDetails) {
val payloadStr = details.payload ?: return
runCatching {
val payload = JSONObject(payloadStr)
val attribution = payload.optJSONObject("attribution") ?: return
val channel = attribution.optString("channel")
val campaignName = attribution.optString("campaign_name")
val adName = attribution.optString("ad_name")
println("Channel: $channel")
}.onFailure(Throwable::printStackTrace)
}
}) adapty.addEventListener('onInstallationDetailsSuccess', details => {
try {
if (!details.payload) return;
const payload = JSON.parse(details.payload);
const attribution = payload.attribution;
if (!attribution) return;
const channel = attribution.channel;
const campaignName = attribution.campaign_name;
const adName = attribution.ad_name;
console.log('Channel:', channel ?? 'organic');
} catch (error) {
console.error('Error parsing payload:', error);
}
}); Adapty().onUpdateInstallationDetailsSuccessStream.listen((details) {
final payloadStr = details.payload;
if (payloadStr == null) return;
final payload = json.decode(payloadStr) as Map<String, dynamic>;
final attribution = payload['attribution'] as Map<String, dynamic>?;
if (attribution == null) return;
final channel = attribution['channel'] as String?;
final campaignName = attribution['campaign_name'] as String?;
final adName = attribution['ad_name'] as String?;
print('Channel: ${channel ?? 'organic'}');
});