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'}');
});