了解广告收入归因
广告收入归因可帮助您将广告收入与将用户引入应用程序的特定广告活动联系起来。通过在一个地方显示广告活动成本、应用内收入和广告收入,您可以清楚地了解广告效果如何。该功能还能让您将广告收入数据发送回广告网络,以提高广告效果。
要点
- 作用:广告收入归属将移动应用广告收入与为应用带来用户的营销活动联系起来。这样,您就可以看到您从每个营销活动中获得了多少收入,以及这些收入对您的整体广告投资回报率有何影响。
- 数据来源:这些数据通常来自您的中介平台,可以是用户级别的数据,也可以是印象级别的数据。Singular 支持通过不同方式获取这些归因数据。
- 更多信息:更多详情,请查看有关 Singular 广告收入归因的常见问题和故障排除文章。
重要说明:
- 货币代码:使用三个字母的 ISO 4217 货币代码(例如,"USD "表示美元,"EUR "表示欧元,"INR "表示印度卢比)。许多调解平台都使用 "USD",因此,如果您使用 "USD",请确保您的代码与之匹配。如果使用其他货币,请相应更新验证码。
- 数据准确性:在发送给 Singular 之前,请务必检查收入和货币数据是否正确。不正确的数据事后无法修复,因此确保数据准确至关重要。
实施广告收入归因
- 更新 SDK:确保拥有最新版本的 Singular SDK。
- 添加代码片段:根据您的调解平台,将正确的代码片段添加到您的 Singular SDK 设置中。
遵循这些步骤将帮助您正确设置广告收入归因,并充分利用广告数据。
合作伙伴说明
- 此功能需要在您的 AdMob 账户中启用。
请参阅AdMob 支持。
-
加载广告格式(如 "App Open"、"Banner"、"Interstitial"、"Native "或 "Rewarded")时,将paidEventHandler设置为回调函数,在广告产生收入时触发。Google 移动广告 SDK 会跟踪印象事件,并根据广告产生的收入调用该处理程序。
为此,请修改广告格式的"加载"函数,使其包含paidEventHandler。在该回调函数中,您可以管理广告收入数据、验证数据并使用Singular.adRevenue函数将其发送给Singular。
例如,当 "奖励广告 "加载成功时,paidEventHandler 将收到广告收入信息(adValue)。在该函数中,处理收入数据并将其发送给 Singular。
更多详情,请查阅AdMob 文档。
重要:AdMob SDK 报告收入的方式因平台而异。例如,0.005 美元的广告收入在 Unity 和 Android 平台上将以 5000 的形式返回,但在 iOS 平台上将以 0.005 的形式返回。对于 iOS,请直接向 Singular SDK 发送 0.005。在其他平台上,将adValue从微米转换成美元后再发送到Singular。
选择 SDK 实现的代码库:
如何运行
- 实施 Google AdMob 移动广告 SDK(iOS):请参阅《入门指南》。
- 整合 AdMob:从 AdMob 加载广告并设置setOnPaidEventListener来处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在向 Singular 发送数据之前,确保货币不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import Singular
private let adUnitID = "AD_UNIT_ID"
var rewardedAd: GADRewardedAd?
func loadRewardedAd() {
let request = GADRequest()
GADRewardedAd.load(withAdUnitID: adUnitID, request: request) { [weak self] ad, error in
guard let self = self else { return }
if let error = error {
print("Rewarded ad failed to load with error: \(error.localizedDescription)")
return
}
self.rewardedAd = ad
self.rewardedAd?.paidEventHandler = { adValue in
// Ensure valid revenue data
let revenue = adValue.value
let currency = adValue.currencyCode
// Validate the revenue and currency before sending to Singular
guard revenue > 0, let currency = currency, !currency.isEmpty else {
print("Invalid ad revenue data: revenue = \(revenue), currency = \(String(describing: currency))")
return
}
let data = SingularAdData(
adPlatform: "Admob",
currency: currency,
revenue: revenue
)
// Send Ad Revenue data to Singular
Singular.adRevenue(data: data)
// Log the data for debugging
print("Ad Revenue reported to Singular: \(data)")
}
}
}
如何运行
- 实施 Google AdMob 移动广告 SDK(iOS):请参阅《入门指南》。
- 整合 AdMob:从 AdMob 加载广告并设置paidEventHandler来处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在向 Singular 发送数据之前,确保货币不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
#import <Singular/Singular.h>
static NSString *const adUnitID = @"AD_UNIT_ID";
// Initialize and load the rewarded ad
@interface YourClassName () <GADRewardedAdDelegate>
@property(nonatomic, strong) GADRewardedAd *rewardedAd;
@end
@implementation YourClassName
- (void)loadRewardedAd {
GADRequest *request = [[GADRequest alloc] init];
[GADRewardedAd loadWithAdUnitID:adUnitID
request:request
completionHandler:^(GADRewardedAd *ad, NSError *error) {
if (error) {
NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
return;
}
self.rewardedAd = ad;
self.rewardedAd.fullScreenContentDelegate = self;
self.rewardedAd.paidEventHandler = ^(GADAdValue *adValue) {
// Ensure valid revenue data
NSDecimalNumber *revenue = adValue.value;
NSString *currency = adValue.currencyCode;
if (revenue.doubleValue > 0 && currency.length > 0) {
SingularAdData *data = [[SingularAdData alloc] initWithAdPlatfrom:@"Admob"
currency:currency
revenue:revenue.doubleValue];
// Send Ad Revenue data to Singular
[Singular adRevenue:data];
// Log the data for debugging
NSLog(@"Ad Revenue reported to Singular: %@", data);
} else {
NSLog(@"Invalid ad revenue data: revenue = %@, currency = %@", revenue, currency);
}
};
}];
}
@end
如何运行
- 执行 Google AdMob 移动广告 SDK(安卓):请参阅《入门指南》。
- 整合 AdMob:从 AdMob 加载广告,并设置setOnPaidEventListener来处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在向 Singular 发送数据之前,确保货币不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.Singular
import com.singular.sdk.SingularAdData
private const val AD_UNIT_ID = "AD_UNIT_ID"
class AdManager(private val context: Context) {
private var rewardedAd: RewardedAd? = null
fun loadRewardedAd() {
val adRequest = AdRequest.Builder().build()
RewardedAd.load(context, AD_UNIT_ID, adRequest, object : RewardedAdLoadCallback() {
override fun onAdLoaded(ad: RewardedAd) {
rewardedAd = ad
rewardedAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() {
Log.d("AdManager", "Rewarded ad displayed.")
}
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
Log.d("AdManager", "Rewarded ad failed to show with error: ${adError.message}")
}
override fun onAdDismissedFullScreenContent() {
Log.d("AdManager", "Rewarded ad dismissed.")
}
}
rewardedAd?.setOnPaidEventListener { adValue: AdValue ->
// Ensure valid revenue data
val revenue = adValue.valueMicros / 1_000_000.0
val currency = adValue.currencyCode
if (revenue > 0 && !currency.isNullOrEmpty()) {
val data = SingularAdData(
"Admob",
currency,
revenue
)
// Send Ad Revenue data to Singular
Singular.adRevenue(data)
// Log the data for debugging
Log.d("AdManager", "Ad Revenue reported to Singular: $data")
} else {
Log.d("AdManager", "Invalid ad revenue data: revenue = $revenue, currency = $currency")
}
}
}
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
Log.d("AdManager", "Rewarded ad failed to load with error: ${loadAdError.message}")
}
})
}
}
如何运行
- 执行 Google AdMob 移动广告 SDK(安卓):请参阅《入门指南》。
- 整合 AdMob:从 AdMob 加载广告,并设置setOnPaidEventListener来处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在向 Singular 发送数据之前,确保货币不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.Singular;
import com.singular.sdk.SingularAdData;
// Define constants for better maintainability
private static final String AD_UNIT_ID = "AD_UNIT_ID";
public class AdManager {
private RewardedAd rewardedAd;
private Context context;
public AdManager(Context context) {
this.context = context;
}
public void loadRewardedAd() {
AdRequest adRequest = new AdRequest.Builder().build();
RewardedAd.load(context, AD_UNIT_ID, adRequest, new RewardedAdLoadCallback() {
@Override
public void onAdLoaded(RewardedAd ad) {
rewardedAd = ad;
rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdShowedFullScreenContent() {
Log.d("AdManager", "Rewarded ad displayed.");
}
@Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
Log.d("AdManager", "Rewarded ad failed to show with error: " + adError.getMessage());
}
@Override
public void onAdDismissedFullScreenContent() {
Log.d("AdManager", "Rewarded ad dismissed.");
}
});
rewardedAd.setOnPaidEventListener(new OnPaidEventListener() {
@Override
public void onPaidEvent(AdValue adValue) {
double revenue = adValue.getValueMicros() / 1_000_000.0;
String currency = adValue.getCurrencyCode();
// Validate the revenue value
if (revenue <= 0 || currency == null || currency.isEmpty()) {
Log.d("AdManager", "Invalid ad revenue data: revenue = " + revenue + ", currency = " + currency);
return;
}
SingularAdData data = new SingularAdData(
"Admob",
currency,
revenue
);
// Send Ad Revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging
Log.d("AdManager", "Ad Revenue reported to Singular: " + data);
}
});
}
@Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
Log.d("AdManager", "Rewarded ad failed to load with error: " + loadAdError.getMessage());
}
});
}
}
如何运行
- 实施 Google AdMob 移动广告 SDK (Flutter):请参阅《入门指南》。
- 整合 AdMob:从 AdMob 加载广告并设置onPaidEvent回调以处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在向 Singular 发送数据之前,确保货币不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import 'package:singular_flutter_sdk/singular_flutter_sdk.dart';
const String adUnitId = 'YOUR_AD_UNIT_ID';
class AdManager {
RewardedAd? _rewardedAd;
void loadRewardedAd() {
RewardedAd.load(
adUnitId: adUnitId,
request: AdRequest(),
rewardedAdLoadCallback: RewardedAdLoadCallback(
onAdLoaded: (RewardedAd ad) {
_rewardedAd = ad;
_rewardedAd?.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: () {
print('Rewarded ad displayed.');
},
onAdFailedToShowFullScreenContent: (AdError adError) {
print('Rewarded ad failed to show with error: ${adError.message}');
},
onAdDismissedFullScreenContent: () {
print('Rewarded ad dismissed.');
_rewardedAd = null; // Clear the ad when it is dismissed
},
);
_rewardedAd?.onPaidEvent = (AdValue adValue) {
double revenue = adValue.valueMicros / 1_000_000.0; // Convert from micros to dollars
String? currency = adValue.currencyCode;
// Validate the revenue and currency before sending to Singular
if (revenue > 0 && currency != null && currency.isNotEmpty) {
final data = {
'adPlatform': 'Admob',
'currency': currency,
'revenue': revenue,
};
// Send Ad Revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging
print('Ad Revenue reported to Singular: $data');
} else {
print('Invalid ad revenue data: revenue = $revenue, currency = $currency');
}
};
},
onAdFailedToLoad: (LoadAdError loadAdError) {
print('Rewarded ad failed to load with error: ${loadAdError.message}');
},
),
);
}
}
如何运行
- Cordova 不受谷歌官方支持,需要使用第三方 Cordova 插件。AdMob Plus Cordova是cordova-plugin-admob-free的后续版本,它提供了更简洁的应用程序接口,并使用现代工具构建。Singular 不支持该插件。 请参阅《入门指南》。
- AdMob 初始化:使用广告单元 ID 为广告格式创建一个实例。确保将 "ca-app-pub-xxx/yyy "替换为实际广告单元 ID。
- 事件处理:触发付费事件回调:该事件提供收入和货币代码。验证这些值并将收入从微元转换为美元。将这些数据发送到 Singular。处理 "加载"、"显示"、"驳回 "和 "错误 "生命周期事件,必要时记录日志。
- 数据验证:在将数据发送到 Singular 之前,确保收入大于零且货币代码存在。
- Singular 集成:使用 SingularAdData 对象准备数据,并调用 adRevenue 将数据发送到 Singular。
document.addEventListener('deviceready', async () => {
const admob = window.cordova.plugins.AdMobPlus;
// Initialize RewardedAd
const rewarded = admob.RewardedAd.create({
adUnitId: 'ca-app-pub-xxx/yyy', // Replace with your ad unit ID
// Optional configurations
isTesting: true, // Set to false when going live
});
// Handle the 'paid' event to get revenue details
rewarded.on('paid', (event) => {
const { value, currencyCode } = event;
// Validate the revenue and currency data
if (value > 0 && currencyCode) {
const revenueAmount = value / 1_000_000.0; // Convert from micros to dollars
// Prepare data for Singular
const adData = new cordova.plugins.SingularCordovaSdk.SingularAdData(
'Admob', // Mediation platform
currencyCode, // Currency code
revenueAmount // Revenue amount
);
// Send Ad Revenue data to Singular
cordova.plugins.SingularCordovaSdk.adRevenue(adData);
// Log the data for debugging
console.log('Ad Revenue reported to Singular:', {
adPlatform: 'Admob',
currency: currencyCode,
revenue: revenueAmount
});
} else {
console.error('Invalid ad revenue data:', { value, currencyCode });
}
});
// Handle ad load and show events
rewarded.on('load', async () => {
console.log('Rewarded ad loaded.');
// Load the next ad as soon as the current one is dismissed
await rewarded.load();
});
rewarded.on('show', () => {
console.log('Rewarded ad shown.');
});
rewarded.on('dismiss', async () => {
console.log('Rewarded ad dismissed.');
// Load a new ad for future use
await rewarded.load();
});
rewarded.on('error', (error) => {
console.error('Error with rewarded ad:', error);
});
// Load and show the rewarded ad
await rewarded.load();
await rewarded.show();
}, false);
如何运行
- 实施 React Native Google Mobile Ads 包:请参阅《入门指南》。
- AdMob 集成:从 AdMob 加载广告并设置onAdEvent来处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在向 Singular 发送数据之前,确保货币不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import { Singular } from 'singular-react-native';
const adUnitID = 'AD_UNIT_ID';
const loadRewardedAd = () => {
// Create a RewardedAd instance with the provided adUnitID
const rewardedAd = RewardedAd.createForAdRequest(adUnitID);
// Set up event listener for ad events
rewardedAd.onAdEvent((type, error, data) => {
if (type === AdEventType.LOADED) {
console.log('Rewarded ad loaded');
} else if (type === AdEventType.ERROR) {
console.error('Rewarded ad failed to load', error);
} else if (type === AdEventType.PAID_EVENT) {
// Extract value and currencyCode from event data
const { value, currencyCode } = data;
// Validate the revenue and currency before sending to Singular
if (value > 0 && currencyCode) {
const revenue = value / 1_000_000.0; // Convert from micros to dollars
const adRevenueData = {
'Admob',
currency: currencyCode,
revenue,
};
// Send Ad Revenue data to Singular
Singular.adRevenue(adRevenueData);
// Log the data for debugging
console.log('Ad Revenue reported to Singular:', adRevenueData);
} else {
console.error('Invalid ad revenue data:', { value, currencyCode });
}
}
});
// Load the rewarded ad
rewardedAd.load();
};
useEffect(() => {
// Load the rewarded ad when the component mounts
loadRewardedAd();
}, []);
如何运行
- 实施 Google AdMob Mobile Ads SDK (Unity):请参阅《入门指南》。
- 按照谷歌 AdMob 文档(请点击此处)中的记录,监听获得奖励的广告事件。
- AdMob 集成:从 AdMob 加载广告,并在广告产生收益时设置OnAdPaid回调。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在向 Singular 发送数据之前,确保货币不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
using Singular;
private void RegisterEventHandlers(RewardedAd ad)
{
// Raised when the ad is estimated to have earned money.
ad.OnAdPaid += (AdValue adValue) =>
{
// Validate and ensure revenue data is within an expected range
float revenue = adValue.Value / 1_000_000f; // Convert micros to dollars
string currency = adValue.CurrencyCode;
// Check if revenue is positive and currency is valid
if (revenue > 0 && !string.IsNullOrEmpty(currency))
{
// Construct and send the Singular AdMon Event
SingularAdData data = new SingularAdData(
"Admob",
currency,
revenue
);
SingularSDK.AdRevenue(data);
// Log the revenue data for debugging purposes
Debug.Log($"Ad Revenue reported to Singular: {data}");
}
else
{
Debug.LogError($"Invalid ad revenue data: revenue = {revenue}, currency = {currency}");
}
};
}
合作伙伴注意事项
- 使用 Applovin 印象级用户收入 API 共享印象级广告收入数据。
为您的 SDK 实施选择代码库:
工作原理:
- 使用 AppLovin 印象级用户收入 API(iOS):请参阅入门指南。
- AppLovin 集成:从 AppLovin MAX 加载奖励广告,并使用didReceive函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import Singular
func didReceive(_ message: ALCMessage) {
if "max_revenue_events" == message.topic {
// Safely unwrap values from the message data
guard
let revenueValue = message.data["revenue"] as? Double,
revenueValue > 0
else {
print("Failed to parse valid revenue value from message data or revenue is not greater than 0")
return
}
let data = SingularAdData(
adPlatform: "AppLovin",
currency: "USD", // Update this if a different currency is needed
revenue: revenueValue
)
// Send the revenue data to Singular
Singular.adRevenue(data)
}
}
工作原理
- 使用 AppLovin 印象级用户收入 API(iOS):请参阅《入门指南》。
- AppLovin 集成:从 AppLovin MAX 加载奖励广告,并使用didReceive函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
#import <Singular/Singular.h>
- (void)didReceive:(ALCMessage *)message {
if ([@"max_revenue_events" isEqualToString:message.topic]) {
NSDictionary *data = message.data;
NSNumber *revenueNumber = data[@"revenue"];
double revenueValue = [revenueNumber doubleValue];
if (revenueValue > 0) {
SingularAdData *adData = [[SingularAdData alloc] initWithAdPlatfrom:@"AppLovin"
currency:@"USD"
revenue:revenueValue];
// Send the revenue data to Singular
[Singular adRevenue:adData];
} else {
NSLog(@"Failed to parse valid revenue value from message data or revenue is not greater than 0");
}
}
}
工作原理
- 使用 AppLovin 印象级用户收入 API(安卓):请参见入门指南。
- AppLovin集成:从 AppLovin MAX 加载奖励广告,并使用onMessageReceived函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.*
override fun onMessageReceived(message: AppLovinCommunicatorMessage) {
// In the case that you are subscribed to multiple topics, check for the desired one
if ("max_revenue_events" == message.topic) {
val adData: Bundle? = message.messageData
// Safely access and validate revenue value
val revenueValue = adData?.getDouble("revenue", 0.0) ?: 0.0
if (revenueValue > 0) {
val data = SingularAdData(
adPlatform = "AppLovin",
currency = "USD",
revenue = revenueValue
)
Singular.adRevenue(data)
} else {
Log.e("AppLovinRevenue", "Failed to parse valid revenue value from message data or revenue is not greater than 0")
}
}
}
工作原理
- 使用 AppLovin 印象级用户收入 API(安卓):请参见入门指南。
- AppLovin集成:从 AppLovin MAX 加载奖励广告,并使用onMessageReceived函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.*;
@Override
public void onMessageReceived(AppLovinCommunicatorMessage message) {
// In the case that you are subscribed to multiple topics, check for the desired one
if ("max_revenue_events".equals(message.getTopic())) {
Bundle adData = message.getMessageData();
// Safely access and validate revenue value
double revenueValue = (adData != null) ? adData.getDouble("revenue", 0.0) : 0.0;
if (revenueValue > 0) {
SingularAdData data = new SingularAdData(
"AppLovin",
"USD",
revenueValue
);
Singular.adRevenue(data);
} else {
Log.e("AppLovinRevenue", "Failed to parse valid revenue value from message data or revenue is not greater than 0");
}
}
}
工作原理
- 使用 AppLovin 印象级用户收入 API (Flutter):请参阅《入门指南》。
- AppLovin 集成:为onAdRevenuePaidCallback设置广告监听器,并将广告数据传递给handleAdRevenuePaid函数,以处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,请打印日志信息进行调试,不要向 Singular 发送数据。
import 'package:singular_flutter_sdk/singular.Flutter';
@override
void initState() {
super.initState();
// Set up ad listeners
AppLovinMAX.setInterstitialListener(InterstitialListener(
onAdRevenuePaidCallback: (ad) {
_handleAdRevenuePaid(ad);
},
));
AppLovinMAX.setRewardedAdListener(RewardedAdListener(
onAdRevenuePaidCallback: (ad) {
_handleAdRevenuePaid(ad);
},
));
AppLovinMAX.setBannerListener(AdViewAdListener(
onAdRevenuePaidCallback: (ad) {
_handleAdRevenuePaid(ad);
},
));
AppLovinMAX.setMRecListener(AdViewAdListener(
onAdRevenuePaidCallback: (ad) {
_handleAdRevenuePaid(ad);
},
));
}
void _handleAdRevenuePaid(Ad ad) {
final double revenueValue = ad.revenue ?? 0.0;
final String currency = ad.currency ?? 'USD'; // Default to 'USD' if currency is not available
if (revenue > 0) {
final SingularAdData adData = SingularAdData(
adPlatform: "AppLovin",
currency: currency,
revenue: revenueValue,
);
Singular.adRevenue(adData);
_logger.i('Sent ad revenue to Singular: $revenueValue $currency');
} else {
_logger.e('Failed to parse valid revenue value from ad revenue data or revenue is not greater than 0');
}
}
不支持:
AppLovin 的 Cordova SDK 本身不支持通过 adInfo 对象获取广告收入信息。与安卓和iOS的原生SDK相比,Cordova SDK的高级功能通常比较有限。
对于高级广告收入跟踪,您可能需要直接与原生 AppLovin SDK 集成,或者使用自定义插件在 Cordova 和原生 SDK 之间搭建功能桥梁。如果您需要广告收入数据,请考虑联系 AppLovin 支持部门了解最新信息,或寻找其他方法获取这些数据。
工作原理
- 使用 AppLovin 印象级用户收入 API(React Native):请参阅《入门指南》。
- AppLovin 集成:从 AppLovin MAX 加载奖励广告,并在所有广告生命周期回调中检索收入金额。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import Singular from 'singular-react-native';
// Function to handle ad revenue
const handleAdRevenue = (adInfo) => {
const revenue = adInfo.revenue;
if (revenue > 0) {
const adData = {
adPlatform: "AppLovin",
currency: "USD", // AppLovin typically reports revenue in USD
revenue: revenue,
};
// Send ad revenue data to Singular
Singular.adRevenue(adData);
} else {
console.error("Failed to parse valid revenue value from ad info or revenue is not greater than 0");
}
};
// Set up listeners for various ad types
InterstitialAd.addAdRevenuePaidListener(handleAdRevenue);
RewardedAd.addAdRevenuePaidListener(handleAdRevenue);
BannerAd.addAdRevenuePaidListener(handleAdRevenue);
MRecAd.addAdRevenuePaidListener(handleAdRevenue);
AppOpenAd.addAdRevenuePaidListener(handleAdRevenue);
工作原理
- 使用 AppLovin 印象级用户收入 API(Unity):请参见入门指南。
- AppLovin集成:从 AppLovin MAX 加载奖励广告,并在所有广告生命周期回调中检索收入金额。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,请打印日志信息进行调试,不要将数据发送到 Singular。
using Singular;
public class AdRevenueHandler : MonoBehaviour
{
void Start()
{
// Attach callbacks based on the ad format(s) you are using
MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
}
private void OnAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
double revenue = adInfo.Revenue;
if (revenue > 0)
{
// Create a SingularAdData object with relevant information
SingularAdData adData = new SingularAdData(
"Applovin",
"USD",
revenue);
// Send ad revenue data to Singular
SingularSDK.AdRevenue(adData);
}
else
{
Debug.LogError("Failed to parse valid revenue value from ad info or revenue is not greater than 0");
}
}
void OnDestroy()
{
// Detach callbacks to prevent memory leaks
MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
MaxSdkCallbacks.Banner.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent -= OnAdRevenuePaidEvent;
}
}
合作伙伴说明
- Impression Level Revenue (ILR) SDK API 使用 ironSource SDK 为 ironSource Ads 和其他中介网络提供印象级别数据。在[developers.is.com] 上阅读更多内容
- 确保打开 IronSource 中的 ARM SDK 回传标志
为您的 SDK 实施选择代码库:
工作原理:
- 使用 ironSource SDK 获取印象级用户收入(iOS):请参阅《入门指南》。
- Ironsource集成:从 Ironsource 加载奖励广告,并使用impressionDataDidSucceed函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import Singular
class IronSourceRewardedAdViewController: UIViewController {
func impressionDataDidSucceed(impressionData: ISImpressionData?) {
logCallback(#function)
// Ensure impressionData is not nil
guard let impressionData = impressionData else {
print("No impression data available.")
return
}
// Ensure revenue value is valid
let revenue = impressionData.revenue
guard revenue > 0 else {
print("Invalid revenue value: \(revenue)")
return
}
// Create SingularAdData object with appropriate values
let data = SingularAdData(
adPlatform: "IronSource",
currency: "USD",
revenue: revenue
)
// Send the Ad Revenue data to Singular
Singular.adRevenue(data)
// Log the data for debugging
print("Ad Revenue reported to Singular: AdPlatform: \(data.adPlatform), Currency: \(data.currency), Revenue: \(data.revenue)")
}
private func logCallback(_ functionName: String) {
// Implement logging if needed
print("Function called: \(functionName)")
}
}
工作原理
- 使用 ironSource SDK 获取印象级用户收入(iOS):请参阅《入门指南》。
- Ironsource集成:从 Ironsource 加载奖励广告,并使用impressionDataDidSucceed函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
#import <Singular/Singular.h>
@implementation IronSourceRewardedAdViewController
- (void)impressionDataDidSucceed:(ISImpressionData *)impressionData {
[self logCallback:NSStringFromSelector(_cmd)];
// Ensure impressionData is not nil
if (!impressionData) {
NSLog(@"No impression data available.");
return;
}
// Ensure revenue value is valid
double revenue = impressionData.revenue;
if (revenue <= 0) {
NSLog(@"Invalid revenue value: %f", revenue);
return;
}
// Create SingularAdData object with appropriate values
SingularAdData *data = [[SingularAdData alloc] initWithAdPlatfrom:@"IronSource"
currency:@"USD"
revenue:revenue];
// Send the Ad Revenue data to Singular
[Singular adRevenue:data];
// Log the data for debugging
NSLog(@"Ad Revenue reported to Singular: AdPlatform: %@, Currency: %@, Revenue: %f",
data.adPlatform, data.currency, data.revenue);
}
- (void)logCallback:(NSString *)functionName {
// Implement logging if needed
NSLog(@"Function called: %@", functionName);
}
@end
工作原理
- 使用 ironSource SDK 获取印象级用户收入(Android):请参阅《入门指南》。
- Ironsource集成:从 Ironsource 加载奖励广告,并使用onImpressionDataSuccess函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.Singular
// Method called when impression data is successfully received
fun onImpressionDataSuccess(impressionData: ISImpressionData?) {
// Ensure impressionData is not null
if (impressionData == null) {
Log.d("IronSource", "No impression data available.")
return
}
// Ensure revenue value is valid
val revenue = impressionData.revenue.toDouble()
if (revenue <= 0) {
Log.w("IronSource", "Invalid revenue value: $revenue")
return
}
// Create SingularAdData object with required fields
val data = SingularAdData(
adPlatform = "IronSource",
currency = "USD",
revenue = revenue
)
// Send the Ad Revenue data to Singular
Singular.adRevenue(data)
// Log the data for debugging
Log.i("IronSource", "Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}")
}
工作原理
- 使用 ironSource SDK 获取印象级用户收入(Android):请参阅《入门指南》。
- Ironsource集成:从 Ironsource 加载奖励广告,并使用onImpressionDataSuccess函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.Singular;
import com.singular.sdk.SingularAdData;
public class IronSourceAdManager {
// Method called when impression data is successfully received
public void onImpressionDataSuccess(ISImpressionData impressionData) {
// Ensure impressionData is not null
if (impressionData == null) {
Log.d("IronSource", "No impression data available.");
return;
}
// Ensure revenue value is valid
double revenue = impressionData.getRevenue().doubleValue();
if (revenue <= 0) {
Log.w("IronSource", "Invalid revenue value: " + revenue);
return;
}
// Create SingularAdData object with required fields
SingularAdData data = new SingularAdData(
"IronSource", // adPlatform
"USD", // currency
revenue // revenue
);
// Send the Ad Revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging
Log.i("IronSource", "Ad Revenue reported to Singular: AdPlatform: " + data.getAdPlatform() +
", Currency: " + data.getCurrency() +
", Revenue: " + data.getRevenue());
}
}
如何运行
- 使用 ironSource Flutter 插件获取印象级用户收入:请参阅《入门指南》。
- Ironsource集成:从 Ironsource 加载奖励广告,并使用onImpressionDataSuccess函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,请打印日志信息进行调试,不要向 Singular 发送数据。
import 'package:singular_flutter_sdk/singular.Flutter';
// Method called when impression data is successfully received
void onImpressionDataSuccess(ISImpressionData? impressionData) {
// Ensure impressionData is not null
if (impressionData == null) {
print("No impression data available.");
return;
}
// Ensure revenue value is valid
final revenue = impressionData.revenue.toDouble();
if (revenue <= 0) {
print("Invalid revenue value: $revenue");
return;
}
// Create SingularAdData object with required fields
final data = SingularAdData(
adPlatform: "IronSource",
currency: "USD",
revenue: revenue,
);
// Send the Ad Revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging
if (kDebugMode) {
print("Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}");
}
}
不支持:
ironSource 本身不支持在 Cordova 框架上获取广告收入。
对于高级广告收入跟踪,您可能需要直接与原生的 ironSource SDK 集成,或使用自定义插件在 Cordova 和原生 SDK 之间搭建功能桥梁。如果您需要广告收入数据,请考虑联系 ironSource 支持部门以获取最新信息,或研究其他获取数据的方法。
工作原理
- 使用 ironSource React Native 插件获取印象级用户收入:请参阅《入门指南》。
- Ironsource集成:从 Ironsource 加载奖励广告,并使用onImpressionDataSuccess监听器处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import { Singular } from 'singular-react-native';
const { IronSourceModule } = NativeModules;
const ironSourceEventEmitter = new NativeEventEmitter(IronSourceModule);
const AD_PLATFORM = 'IronSource';
const CURRENCY = 'USD'; // Assuming USD, adjust if necessary
ironSourceEventEmitter.addListener('onImpressionDataSuccess', (impressionData) => {
if (!impressionData) {
console.log('No impression data available.');
return;
}
const revenue = impressionData.revenue;
// Validate the revenue to ensure it is within the expected range
if (revenue <= 0) {
console.warn(`Invalid revenue value: ${revenue}`);
return;
}
// Create SingularAdData object with valid values
const data = {
adPlatform: AD_PLATFORM,
currency: CURRENCY,
revenue: revenue,
};
// Send the revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging purposes
console.log(`Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}`);
});
工作原理
- 使用 ironSource Unity 插件获取印象级用户收入:请参阅《入门指南》。
- Ironsource集成:从 Ironsource 加载奖励广告,并使用ImpressionDataReadyEvent函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币准确无误,而不是零或空值。
- 记录无效数据:如果数据未通过验证,请打印日志信息进行调试,不要将数据发送到 Singular。
using Singular;
public class IronSourceRewardedAdViewController : MonoBehaviour
{
void Start()
{
// Ensure the listener is added before initializing the SDK
IronSourceEvents.onImpressionDataReadyEvent += ImpressionDataReadyEvent;
// Initialize the IronSource SDK here if not already done
// IronSource.Agent.init("YOUR_IRONSOURCE_APP_KEY");
}
private void ImpressionDataReadyEvent(IronSourceImpressionData impressionData)
{
if (impressionData != null)
{
// Ensure revenue value is valid
double? revenue = impressionData.revenue;
if (revenue.HasValue && revenue.Value > 0)
{
// Create SingularAdData object with appropriate values
SingularAdData adData = new SingularAdData(
"IronSource",
"USD",
revenue.Value
);
// Send the Ad Revenue data to Singular
SingularSDK.AdRevenue(adData);
// Log the data for debugging
Debug.Log($"Ad Revenue reported to Singular: AdPlatform: {adData.AdPlatform}, Currency: {adData.Currency}, Revenue: {adData.Revenue}");
}
else
{
Debug.LogError($"Invalid revenue value: {revenue}");
}
}
else
{
Debug.LogError("Impression data is null.");
}
}
void OnDestroy()
{
// Detach the callback to prevent memory leaks
IronSourceEvents.onImpressionDataReadyEvent -= ImpressionDataReadyEvent;
}
}
合作伙伴注意事项
- 设置impressionDelegate
- 在TradPlusAdImpression回调中添加 Singular
为您的 SDK 实现选择代码库:
如何工作:
- TradPlus 集成:从TradPlus加载奖励广告并使用tradPlusAdImpression函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。adInfo字典包含一个具有有效 NSNumber 值的"ecpm"键。它将此值转换为双倍值并进行缩放(ecpm 通常以毫安单位表示,因此除以 1000.0 将其转换为美元)。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币是准确的,而不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import Singular
// Set up the delegate
TradPlus.sharedInstance().impressionDelegate = self
// Delegate method for handling ad impressions
func tradPlusAdImpression(_ adInfo: [String: Any]) {
let currency = "USD" // Assuming USD, adjust if necessary
// Ensure adInfo contains the necessary key and its value is valid
if let ecpmValue = adInfo["ecpm"] as? NSNumber {
let revenue = ecpmValue.doubleValue / 1000.0
// Validate the revenue value
guard revenue > 0 else {
print("Ad Revenue value out of expected range: \(revenue)")
return
}
// Create SingularAdData object with required fields
let data = SingularAdData(
adPlatform: "TradPlus",
currency: currency,
revenue: revenue
)
// Send the Ad Revenue data to Singular
Singular.adRevenue(data)
print("Ad Revenue reported to Singular: \(data)")
} else {
// Log the issue for debugging
print("No eCPM data available in adInfo")
}
}
如何运行
- TradPlus 集成:从TradPlus加载奖励广告,并使用tradPlusAdImpression函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。adInfo字典包含一个具有有效 NSNumber 值的"ecpm"键。它将此值转换为双倍值并进行缩放(ecpm 通常以毫安单位表示,因此除以 1000.0 将其转换为美元)。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币是准确的,而不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
#import <Singular/Singular.h>
// Set up the delegate
TradPlus.sharedInstance.impressionDelegate = self;
// Delegate method for handling ad impressions
- (void)tradPlusAdImpression:(NSDictionary<NSString *, id> *)adInfo {
NSString *currency = @"USD"; // Assuming USD, adjust if necessary
// Ensure adInfo contains the necessary key and its value is valid
NSNumber *ecpmValue = adInfo[@"ecpm"];
if (ecpmValue) {
double revenue = [ecpmValue doubleValue] / 1000.0;
// Validate the revenue value
if (revenue <= 0) {
NSLog(@"Ad Revenue value out of expected range: %f", revenue);
return;
}
// Create SingularAdData object with required fields
SingularAdData *data = [[SingularAdData alloc] initWithAdPlatfrom:@"TradPlus"
currency:currency
revenue:revenue];
// Send the Ad Revenue data to Singular
[Singular adRevenue:data];
NSLog(@"Ad Revenue reported to Singular: AdPlatform: %@, Currency: %@, Revenue: %f", data.adPlatform, data.currency, data.revenue);
} else {
// Log the issue for debugging
NSLog(@"No eCPM data available in adInfo");
}
}
如何运行
- TradPlus 集成:从 TradPlus 加载奖励广告,并使用onImpressionSuccess函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。adInfo字典包含一个具有有效 NSNumber 值的"ecpm"键。它将此值转换为双倍值并进行缩放(ecpm 通常以毫安单位表示,因此除以 1000.0 将其转换为美元)。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币是准确的,而不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.Singular
import com.singular.sdk.SingularAdData
// Set the global impression listener for TradPlus
TradPlusSdk.setGlobalImpressionListener(
object : GlobalImpressionManager.GlobalImpressionListener {
override fun onImpressionSuccess(tpAdInfo: TPAdInfo?) {
// Ensure tpAdInfo is not null
if (tpAdInfo == null) {
println("AdInfo is null")
return
}
// Calculate revenue (assuming ecpm is a valid field)
val revenue = tpAdInfo.ecpm.toDouble() / 1000
// Validate the revenue value
if (revenue <= 0) {
println("Ad Revenue value out of expected range: $revenue")
return
}
// Create SingularAdData object with required fields
val data = SingularAdData(
adPlatform = "TradPlus",
currency = "USD", // Assuming USD, adjust if necessary
revenue = revenue
)
// Send the Ad Revenue data to Singular
Singular.adRevenue(data)
// Log for debugging
println("Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}")
}
}
)
如何运行
- TradPlus 集成:从 TradPlus 加载奖励广告,并使用onImpressionSuccess函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。adInfo字典包含一个具有有效 NSNumber 值的"ecpm"键。它将此值转换为双倍值并进行缩放(ecpm 通常以毫安单位表示,因此除以 1000.0 将其转换为美元)。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币是准确的,而不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import com.singular.sdk.Singular;
import com.singular.sdk.SingularAdData;
public class AdImpressionListener implements GlobalImpressionManager.GlobalImpressionListener {
private static final String TAG = "AdImpressionListener";
@Override
public void onImpressionSuccess(TPAdInfo tpAdInfo) {
// Ensure tpAdInfo is not null
if (tpAdInfo == null) {
Log.e(TAG, "AdInfo is null");
return;
}
// Ensure eCPM is valid and not null
if (tpAdInfo.getEcpm() == null) {
Log.e(TAG, "eCPM value is null");
return;
}
// Calculate revenue (assuming ecpm is in micros)
double revenue = tpAdInfo.getEcpm().doubleValue() / 1000;
// Validate the revenue value
if (revenue <= 0) {
Log.e(TAG, "Ad Revenue value out of expected range: " + revenue);
return;
}
// Create SingularAdData object with required fields
SingularAdData data = new SingularAdData(
"TradPlus",
"USD",
revenue
);
// Send the Ad Revenue data to Singular
Singular.adRevenue(data);
// Log for debugging
Log.d(TAG, "Ad Revenue reported to Singular: AdPlatform: " + data.getAdPlatform() +
", Currency: " + data.getCurrency() + ", Revenue: " + data.getRevenue());
}
}
如何运行
- TradPlus 集成:从 TradPlus 加载奖励广告,并使用setGlobalImpressionListener处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。adInfo字典包含一个具有有效 NSNumber 值的"ecpm"键。它将此值转换为双倍值并进行缩放(ecpm 通常以毫安单位表示,因此除以 1000.0 将其转换为美元)。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币是准确的,而不是零或空。
- 记录无效数据:如果数据未通过验证,请打印日志信息进行调试,不要将数据发送到 Singular。
import 'package:singular_flutter_sdk/singular.dart';
void setupTradPlusImpressionListener() {
// Set up the global impression listener
TradPlusSdk.setGlobalImpressionListener((tpAdInfo) {
if (tpAdInfo == null) {
print("AdInfo is null");
return;
}
// Ensure eCPM is not null
if (tpAdInfo.ecpm == null) {
print("eCPM value is null");
return;
}
// Calculate revenue (assuming ecpm is in micros)
double revenue = tpAdInfo.ecpm / 1000.0;
// Validate the revenue value
if (revenue <= 0) {
print("Ad Revenue value out of expected range: $revenue");
return;
}
// Create SingularAdData object
final data = SingularAdData(
adPlatform: "TradPlus", // Ad platform name
currency: "USD", // Currency
revenue: revenue // Revenue
);
// Send the Ad Revenue data to Singular
Singular.adRevenue(data);
// Print log for debugging
print("Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}");
});
}
void main() {
// Initialize TradPlus SDK and other setup
setupTradPlusImpressionListener();
// Run your app
runApp(MyApp());
}
不支持:
TradPlus 本身不支持通过 adInfo 对象获取广告收入信息。与 Android 和 iOS 的原生 SDK 相比,Cordova SDK 的高级功能通常比较有限。
对于高级广告收入跟踪,您可能需要直接与原生 TradPlus SDK 集成,或者使用自定义插件来连接 Cordova 和原生 SDK 之间的功能。如果您需要广告收入数据,请考虑联系 AppLovin 支持部门了解最新信息,或寻找其他方法获取这些数据。
如何运行
- TradPlus 集成:从 TradPlus 加载奖励广告,并设置onImpressionSuccess监听器来处理广告收入事件。
- 收入验证:这样可以防止发送零或负的收入值。adInfo字典包含一个具有有效 NSNumber 值的"ecpm"键。它将此值转换为双倍值并进行缩放(ecpm 通常以毫安单位表示,因此除以 1000.0 将其转换为美元)。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币是准确的,而不是零或空。
- 记录无效数据:如果数据未通过验证,则打印日志信息进行调试,并不向 Singular 发送数据。
import { NativeModules, NativeEventEmitter } from 'react-native';
import { Singular } from 'singular-react-native';
const { TradPlusModule } = NativeModules;
const tradPlusEventEmitter = new NativeEventEmitter(TradPlusModule);
const AD_PLATFORM = 'TradPlus';
const CURRENCY = 'USD'; // Assuming USD, adjust if necessary
tradPlusEventEmitter.addListener('onImpressionSuccess', (tpAdInfo) => {
if (!tpAdInfo) {
console.log('AdInfo is null');
return;
}
const revenue = tpAdInfo.ecpm / 1000;
// Validate the revenue to ensure it is within the expected range
if (revenue <= 0) {
console.warn(`Ad Revenue value out of expected range: ${revenue}`);
return;
}
// Create the ad revenue data object
const data = {
adPlatform: AD_PLATFORM,
currency: CURRENCY,
revenue: revenue,
};
// Send the revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging purposes
console.log(`Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}`);
});
如何运行
- TradPlus 集成:从 TradPlus 加载奖励广告,并使用onImpressionSuccess函数处理广告收入事件。
- 收入验证:添加检查以确保收入大于 0,从而防止发送零或负收入值。adInfo字典包含一个具有有效 NSNumber 值的"ecpm"键。它将此值转换为双倍值并进行缩放(ecpm 通常以毫安单位表示,因此除以 1000.0 将其转换为美元)。
- 货币验证:在下面的示例中,货币被硬编码为 "美元"。在向 Singular 发送数据之前,请确保货币是准确的,而不是零或空。
- 记录无效数据:如果数据未能通过验证,请打印日志信息以便调试,同时不要向 Singular 发送数据。
using Singular;
public class AdImpressionListener : MonoBehaviour
{
private const string TAG = "AdImpressionListener";
void Start()
{
// Add Global Ad Impression Listener
TradplusAds.Instance().AddGlobalAdImpression(OnGlobalAdImpression);
}
void OnGlobalAdImpression(Dictionary<string, object> adInfo)
{
// Ensure adInfo is not null
if (adInfo == null)
{
Debug.LogError($"{TAG}: AdInfo is null");
return;
}
// Ensure eCPM is present and valid
if (!adInfo.ContainsKey("ecpm") || adInfo["ecpm"] == null)
{
Debug.LogError($"{TAG}: eCPM value is null or missing");
return;
}
// Parse the eCPM value
if (!double.TryParse(adInfo["ecpm"].ToString(), NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out double revenue))
{
Debug.LogError($"{TAG}: Failed to parse eCPM value");
return;
}
// Convert eCPM to revenue (assuming eCPM is in micros)
revenue = revenue / 1000;
// Validate the revenue value
if (revenue <= 0)
{
Debug.LogError($"{TAG}: Ad Revenue value out of expected range: " + revenue);
return;
}
// Create SingularAdData object with the necessary fields
SingularAdData data = new SingularAdData(
"TradPlus", // Ad platform name
"USD", // Currency
revenue // Revenue value
);
// Send the Ad Revenue data to Singular
SingularSDK.AdRevenue(data);
// Log the data for debugging purposes
Debug.Log($"{TAG}: Ad Revenue reported to Singular: AdPlatform: {data.AdPlatform}, Currency: {data.Currency}, Revenue: {data.Revenue}");
}
}
合作伙伴说明
- 通用集成:初始化一个 SingularAdData 对象并传递所需的数据。数据应包括字符串形式的广告平台、字符串形式的货币和双倍形式的收入。
- 收入报告:在将收入和货币数据发送给 Singular 之前,请检查这些数据是否正确。不正确的数据以后无法修复,因此确保数据准确至关重要。
- 提示:记录调试信息。
为您的 SDK 实施选择代码库:
import Singular
// Function to send Ad Revenue data to Singular
func reportAdRevenue(adPlatform: String, currency: String, revenue: Double) {
// Validate the revenue value
guard revenue > 0 else {
print("Invalid revenue value: \(revenue)")
return
}
// Create a SingularAdData object with the provided fields
let data = SingularAdData(
adPlatform: adPlatform,
currency: currency,
revenue: revenue
)
// Send the Ad Revenue data to Singular
Singular.adRevenue(data)
// Log the data for debugging
print("Ad Revenue reported to Singular: AdPlatform: \(data.adPlatform), Currency: \(data.currency), Revenue: \(data.revenue)")
}
#import <Singular/Singular.h>
// Function to send Ad Revenue data to Singular
- (void)reportAdRevenueWithPlatform:(NSString *)adPlatform currency:(NSString *)currency revenue:(double)revenue {
// Validate the revenue value
if (revenue <= 0) {
NSLog(@"Invalid revenue value: %f", revenue);
return;
}
// Create a SingularAdData object with the provided fields
SingularAdData *data = [[SingularAdData alloc] initWithAdPlatfrom:adPlatform currency:currency revenue:revenue];
// Send the Ad Revenue data to Singular
[Singular adRevenue:data];
// Log the data for debugging
NSLog(@"Ad Revenue reported to Singular: AdPlatform: %@, Currency: %@, Revenue: %f", data.adPlatform, data.currency, data.revenue);
}
import com.singular.sdk.Singular
import com.singular.sdk.SingularAdData
// Function to send Ad Revenue data to Singular
fun reportAdRevenue(adPlatform: String, currency: String, revenue: Double) {
// Validate the revenue value
if (revenue <= 0) {
println("Invalid revenue value: $revenue")
return
}
// Create a SingularAdData object with the provided fields
val data = SingularAdData(
adPlatform = adPlatform,
currency = currency,
revenue = revenue
)
// Send the Ad Revenue data to Singular
Singular.adRevenue(data)
// Log the data for debugging
println("Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}")
}
import com.singular.sdk.Singular;
import com.singular.sdk.SingularAdData;
// Function to send Ad Revenue data to Singular
public void reportAdRevenue(String adPlatform, String currency, double revenue) {
// Validate the revenue value
if (revenue <= 0) {
Log.w("AdRevenue", "Invalid revenue value: " + revenue);
return;
}
// Create a SingularAdData object with the provided fields
SingularAdData data = new SingularAdData(
adPlatform, // adPlatform
currency, // currency
revenue // revenue
);
// Send the Ad Revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging
Log.d("AdRevenue", "Ad Revenue reported to Singular: AdPlatform: " + data.getAdPlatform() + ", Currency: " + data.getCurrency() + ", Revenue: " + data.getRevenue());
}
import 'package:singular_flutter_sdk/singular.Flutter';
// Function to send Ad Revenue data to Singular
void reportAdRevenue({
required String adPlatform,
required String currency,
required double revenue,
}) {
// Validate the revenue value
if (revenue <= 0) {
print('Invalid revenue value: $revenue');
return;
}
// Create a SingularAdData object with the provided fields
final data = SingularAdData(
adPlatform: adPlatform,
currency: currency,
revenue: revenue,
);
// Send the Ad Revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging
print('Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}');
}
// Function to report Ad Revenue to Singular
function reportAdRevenue(mediationPlatform, currencyCode, revenueAmount) {
// Validate input values
if (!mediationPlatform || !currencyCode || typeof revenueAmount !== 'number' || revenueAmount <= 0) {
console.error("Invalid input for Ad Revenue reporting: ", {
mediationPlatform,
currencyCode,
revenueAmount
});
return;
}
try {
// Create a SingularAdData object
const adData = new cordova.plugins.SingularCordovaSdk.SingularAdData(
mediationPlatform,
currencyCode, // e.g., "USD"
revenueAmount
);
// Report Ad Revenue to Singular
cordova.plugins.SingularCordovaSdk.adRevenue(adData);
// Log success
console.log("Ad Revenue reported successfully: ", {
mediationPlatform: adData.mediationPlatform,
currencyCode: adData.currencyCode,
revenueAmount: adData.revenueAmount
});
} catch (error) {
// Log any errors that occur during the process
console.error("Failed to report Ad Revenue: ", error);
}
}
import { Singular } from 'singular-react-native';
const reportAdRevenue = (adPlatform, currency, revenue) => {
// Validate the revenue value
if (revenue <= 0) {
console.warn(`Invalid revenue value: ${revenue}`);
return;
}
// Create a SingularAdData object with the provided fields
const data = {
adPlatform: adPlatform,
currency: currency,
revenue: revenue,
};
// Send the Ad Revenue data to Singular
Singular.adRevenue(data);
// Log the data for debugging
console.log(`Ad Revenue reported to Singular: AdPlatform: ${data.adPlatform}, Currency: ${data.currency}, Revenue: ${data.revenue}`);
};
using Singular;
public class AdRevenueReporter : MonoBehaviour
{
// Function to report ad revenue to Singular
public void ReportAdRevenue(string adPlatform, float revenueInMicros, string currency)
{
// Convert revenue from micros to the standard unit (e.g., dollars)
float revenue = revenueInMicros / 1_000_000f;
// Validate the input: ensure revenue is positive and currency is not null or empty
if (revenue > 0 && !string.IsNullOrEmpty(currency))
{
// Create a SingularAdData object with the validated data
SingularAdData data = new SingularAdData(
adPlatform,
currency,
revenue
);
// Send the ad revenue data to Singular
SingularSDK.AdRevenue(data);
// Log the reported data for debugging
Debug.Log($"Ad Revenue reported to Singular: Platform = {adPlatform}, Currency = {currency}, Revenue = {revenue}");
}
else
{
// Log a warning if validation fails
Debug.LogWarning("Invalid ad revenue data: " +
$"Platform = {adPlatform}, Revenue = {revenue}, Currency = {currency}");
}
}
}