【埋点】广告点击事件和广告收益上报事件中 position 属性上报不一致
This commit is contained in:
parent
090e819e84
commit
3745010e38
|
|
@ -37,6 +37,7 @@ object VidiConst {
|
|||
const val WATCH_AD_FOR_DAILY_SIGN_SINGLE = 8
|
||||
const val WATCH_AD_FOR_DAILY_SIGN_DOUBLE = 9
|
||||
const val WATCH_AD_FOR_DAILY_SIGN_COMPLEMENT = 10
|
||||
const val WATCH_AD_FOR_DAILY_EARN_GOLD_POPMENU = 11
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ object VidiStatisticHelper {
|
|||
return "RV_VideoStream"
|
||||
}
|
||||
|
||||
VidiConst.WATCH_AD_FOR_DAILY_EARN_GOLD -> {
|
||||
VidiConst.WATCH_AD_FOR_DAILY_EARN_GOLD_POPMENU -> {
|
||||
return "RV_Home_Menu"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity
|
|||
import com.ama.core.architecture.util.AndroidUtil
|
||||
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||
import com.gamedog.vididin.VidiConst
|
||||
import com.gamedog.vididin.VidiStatisticHelper
|
||||
import com.gamedog.vididin.VididinEvents
|
||||
import com.gamedog.vididin.beans.WatchAdNotifyBean
|
||||
import com.gamedog.vididin.main.interfaces.OnTabStyleListener
|
||||
|
|
@ -117,7 +118,7 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
|||
notifyEventType = VididinEvents.EVENT_AD_WATCHED_FOR_DAILY_WATCH_AD
|
||||
}
|
||||
|
||||
VidiConst.WATCH_AD_FOR_DAILY_EARN_GOLD -> {
|
||||
VidiConst.WATCH_AD_FOR_DAILY_EARN_GOLD_POPMENU, VidiConst.WATCH_AD_FOR_DAILY_EARN_GOLD -> {
|
||||
shouldNotifyOneAdWatched = true
|
||||
notifyEventType = VididinEvents.EVENT_AD_WATCHED_FOR_EARN_GOLD
|
||||
}
|
||||
|
|
@ -192,11 +193,12 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
|||
if (!mIsLoadSuccess) {
|
||||
handleLoadFailed()
|
||||
}
|
||||
}, 3000)
|
||||
}, 30000)
|
||||
|
||||
|
||||
try {
|
||||
when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity, { rewardedData ->
|
||||
when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity,
|
||||
VidiStatisticHelper.getShowFromStr(mWatchType), { rewardedData ->
|
||||
mRewardedDollarNum = rewardedData.rewardNum
|
||||
}, {
|
||||
notifyAdWatchFinish()
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
StatisticUtil.reportEvents(StatisticUtil.KEY_Chest_Claim_Click)
|
||||
},
|
||||
PopMenuView.MenuItem(R.mipmap.home_menu_2,R.mipmap.icon_gold_ss_new, 0) {
|
||||
WatchAdDialog(requireActivity(), VidiConst.WATCH_AD_FOR_DAILY_EARN_GOLD, WatchAdDialog.FROM_HOME_MENU,null).show()
|
||||
WatchAdDialog(requireActivity(), VidiConst.WATCH_AD_FOR_DAILY_EARN_GOLD_POPMENU, WatchAdDialog.FROM_HOME_MENU,null).show()
|
||||
},
|
||||
PopMenuView.MenuItem(R.mipmap.home_menu_3,0, 0) {
|
||||
Router.Game.startActivity(requireActivity())
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class RewardedAdController private constructor() {
|
|||
/**
|
||||
* 预加载广告
|
||||
*/
|
||||
suspend fun preloadAd(context: Context, adUnitId: String? = null): AdResult<Unit> {
|
||||
suspend fun preloadAd(context: Context, adUnitId: String? = null, positionStr: String): AdResult<Unit> {
|
||||
if(!GlobalAdSwitchInterceptor.isGlobalAdEnabled()){
|
||||
return AdResult.Failure(
|
||||
AdException(
|
||||
|
|
@ -126,7 +126,7 @@ class RewardedAdController private constructor() {
|
|||
))
|
||||
}
|
||||
val finalAdUnitId = adUnitId ?: BuildConfig.ADMOB_REWARDED_ID
|
||||
return loadAdToCache(context, finalAdUnitId)
|
||||
return loadAdToCache(context, finalAdUnitId, positionStr)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,6 +134,7 @@ class RewardedAdController private constructor() {
|
|||
*/
|
||||
suspend fun showAd(
|
||||
activity: Activity,
|
||||
positionStr: String,
|
||||
adUnitId: String? = null,
|
||||
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? = null,
|
||||
closeCallback: () -> Unit,
|
||||
|
|
@ -149,7 +150,7 @@ class RewardedAdController private constructor() {
|
|||
eventName = "ad_position",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to finalAdUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowTriggerCount
|
||||
)
|
||||
)
|
||||
|
|
@ -165,7 +166,7 @@ class RewardedAdController private constructor() {
|
|||
// eventName = "ad_show_fail",
|
||||
// params = mapOf(
|
||||
// "ad_unit_name" to finalAdUnitId,
|
||||
// "position" to PositionGet.get(),
|
||||
// "position" to positionStr,
|
||||
// "number" to totalShowFailCount,
|
||||
// "reason" to interceptResult.error.message
|
||||
// )
|
||||
|
|
@ -185,7 +186,7 @@ class RewardedAdController private constructor() {
|
|||
// 激励广告阻塞loading
|
||||
ADLoadingDialog.show(activity)
|
||||
AdLogger.d("Admob缓存为空,立即加载激励广告,广告位ID: %s", finalAdUnitId)
|
||||
loadAdToCache(activity, finalAdUnitId)
|
||||
loadAdToCache(activity, finalAdUnitId, positionStr)
|
||||
cachedAd = getCachedAd(finalAdUnitId)
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +196,7 @@ class RewardedAdController private constructor() {
|
|||
AdLogger.d("Admob使用缓存中的激励广告,广告位ID: %s", finalAdUnitId)
|
||||
|
||||
// 3. 显示广告
|
||||
val result = showAdInternal(activity, cachedAd.ad, finalAdUnitId, onRewardEarned, closeCallback)
|
||||
val result = showAdInternal(activity, positionStr,cachedAd.ad, finalAdUnitId, onRewardEarned, closeCallback)
|
||||
|
||||
result
|
||||
} else {
|
||||
|
|
@ -212,7 +213,7 @@ class RewardedAdController private constructor() {
|
|||
/**
|
||||
* 基础广告加载方法(可复用)
|
||||
*/
|
||||
private suspend fun loadAd(context: Context, adUnitId: String): RewardedAd? {
|
||||
private suspend fun loadAd(context: Context, adUnitId: String, positionStr: String): RewardedAd? {
|
||||
// 累积加载次数统计
|
||||
totalLoadCount++
|
||||
AdLogger.d("Admob激励广告累积加载次数: $totalLoadCount")
|
||||
|
|
@ -258,7 +259,7 @@ class RewardedAdController private constructor() {
|
|||
eventName = "ad_impression",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowCount,
|
||||
"ad_source" to (rewardedAd.responseInfo?.loadedAdapterResponseInfo?.adSourceName.orEmpty()),
|
||||
"value" to (currentAdValue?.let { it.valueMicros / 1_000_000.0 }
|
||||
|
|
@ -305,7 +306,7 @@ class RewardedAdController private constructor() {
|
|||
/**
|
||||
* 加载广告到缓存
|
||||
*/
|
||||
suspend fun loadAdToCache(context: Context, adUnitId: String): AdResult<Unit> {
|
||||
suspend fun loadAdToCache(context: Context, adUnitId: String, positionStr: String): AdResult<Unit> {
|
||||
return try {
|
||||
|
||||
// 检查缓存是否已满
|
||||
|
|
@ -316,7 +317,7 @@ class RewardedAdController private constructor() {
|
|||
}
|
||||
|
||||
// 加载广告
|
||||
val rewardedAd = loadAd(context, adUnitId)
|
||||
val rewardedAd = loadAd(context, adUnitId, positionStr)
|
||||
if (rewardedAd != null) {
|
||||
synchronized(adCachePool) {
|
||||
adCachePool.add(CachedRewardedAd(rewardedAd, adUnitId))
|
||||
|
|
@ -379,6 +380,7 @@ class RewardedAdController private constructor() {
|
|||
*/
|
||||
private suspend fun showAdInternal(
|
||||
activity: Activity,
|
||||
positionStr: String,
|
||||
rewardedAd: RewardedAd,
|
||||
adUnitId: String,
|
||||
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)?,
|
||||
|
|
@ -399,7 +401,7 @@ class RewardedAdController private constructor() {
|
|||
eventName = "ad_close",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalCloseCount,
|
||||
"ad_source" to (rewardedAd.responseInfo?.loadedAdapterResponseInfo?.adSourceName.orEmpty()),
|
||||
"value" to (currentAdValue?.let { it.valueMicros / 1_000_000.0 }
|
||||
|
|
@ -428,7 +430,7 @@ class RewardedAdController private constructor() {
|
|||
eventName = "ad_show_fail",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowFailCount,
|
||||
"ad_source" to (rewardedAd.responseInfo?.loadedAdapterResponseInfo?.adSourceName.orEmpty()),
|
||||
"reason" to adError.message
|
||||
|
|
@ -460,7 +462,7 @@ class RewardedAdController private constructor() {
|
|||
eventName = "ad_click",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalClickCount,
|
||||
"ad_source" to (rewardedAd.responseInfo?.loadedAdapterResponseInfo?.adSourceName.orEmpty()),
|
||||
"value" to (currentAdValue?.let { it.valueMicros / 1_000_000.0 }
|
||||
|
|
@ -500,7 +502,7 @@ class RewardedAdController private constructor() {
|
|||
eventName = "ad_reward_earned",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalRewardEarnedCount,
|
||||
"reward_type" to rewardItem.type,
|
||||
"reward_amount" to rewardItem.amount,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ object RewardedBiddingManager {
|
|||
|
||||
suspend fun bidding(
|
||||
context: Context,
|
||||
positionStr: String,
|
||||
admobAdUnitId: String = BuildConfig.ADMOB_REWARDED_ID,
|
||||
pangleAdUnitId: String = BuildConfig.PANGLE_REWARDED_ID,
|
||||
toponPlacementId: String = BuildConfig.TOPON_REWARDED_ID,
|
||||
|
|
@ -34,17 +35,18 @@ object RewardedBiddingManager {
|
|||
AdSourceController.AdSource.TOPON -> BiddingWinner.TOPON
|
||||
AdSourceController.AdSource.BIDDING -> {
|
||||
// 不会执行到这里,但为了完整性保留
|
||||
performBidding(context, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
performBidding(context, positionStr, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用竞价逻辑
|
||||
return performBidding(context, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
return performBidding(context, positionStr, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
}
|
||||
|
||||
private suspend fun performBidding(
|
||||
context: Context,
|
||||
positionStr: String,
|
||||
admobAdUnitId: String,
|
||||
pangleAdUnitId: String,
|
||||
toponPlacementId: String,
|
||||
|
|
@ -58,7 +60,7 @@ object RewardedBiddingManager {
|
|||
coroutineScope {
|
||||
val admobDeferred = async {
|
||||
runCatching {
|
||||
admobController.loadAdToCache(context, admobAdUnitId)
|
||||
admobController.loadAdToCache(context, admobAdUnitId, positionStr)
|
||||
}.getOrNull()
|
||||
}
|
||||
val pangleDeferred = async {
|
||||
|
|
@ -68,7 +70,7 @@ object RewardedBiddingManager {
|
|||
}
|
||||
val toponDeferred = async {
|
||||
runCatching {
|
||||
toponController.preloadAd(context, toponPlacementId)
|
||||
toponController.preloadAd(context, positionStr, toponPlacementId)
|
||||
}.getOrNull()
|
||||
}
|
||||
// 等待所有加载完成
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.iab.omid.library.bigosg.adsession.media.Position
|
||||
import com.remax.bill.BuildConfig
|
||||
import com.remax.bill.ads.AdResult
|
||||
import com.remax.bill.ads.AppOpenAdController
|
||||
|
|
@ -294,12 +295,13 @@ object AdShowExt {
|
|||
*/
|
||||
suspend fun showRewardedVideoAd(
|
||||
activity: Activity,
|
||||
positionStr: String,
|
||||
rewardCallback: ((CommonRewardedData) -> Unit)? = null,
|
||||
closeCallback: ()->Unit,
|
||||
readyCallback:() -> Unit,
|
||||
): AdResult<Unit> {
|
||||
AdLogger.d("激励视频广告竞价开始")
|
||||
val winner = RewardedBiddingManager.bidding(activity)
|
||||
val winner = RewardedBiddingManager.bidding(activity, positionStr)
|
||||
AdLogger.d("激励视频广告竞价结果: $winner")
|
||||
|
||||
|
||||
|
|
@ -308,7 +310,7 @@ object AdShowExt {
|
|||
BiddingWinner.ADMOB -> {
|
||||
AdLogger.d("使用 AdMob 展示激励视频广告")
|
||||
RewardedAdController.getInstance().showAd(
|
||||
activity,
|
||||
activity, positionStr,
|
||||
BuildConfig.ADMOB_REWARDED_ID,
|
||||
{ rewardItem, commonRewardedData ->
|
||||
rewardCallback?.invoke(commonRewardedData)
|
||||
|
|
@ -319,7 +321,7 @@ object AdShowExt {
|
|||
BiddingWinner.PANGLE -> {
|
||||
AdLogger.d("使用 Pangle 展示激励视频广告")
|
||||
PangleRewardedAdController.getInstance().showAd(
|
||||
activity,
|
||||
activity, positionStr,
|
||||
BuildConfig.PANGLE_REWARDED_ID,
|
||||
{ pagRewardItem, commonRewardedData ->
|
||||
rewardCallback?.invoke(commonRewardedData)
|
||||
|
|
@ -330,7 +332,7 @@ object AdShowExt {
|
|||
BiddingWinner.TOPON -> {
|
||||
AdLogger.d("使用 TopOn 展示激励视频广告")
|
||||
TopOnRewardedAdController.getInstance().showAd(
|
||||
activity,
|
||||
activity, positionStr,
|
||||
BuildConfig.TOPON_REWARDED_ID,
|
||||
{ _, _, revenueValue ->
|
||||
val rewardedData = CommonRewardedData(revenueValue.toDouble())
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ class PangleRewardedAdController private constructor() {
|
|||
|
||||
suspend fun showAd(
|
||||
activity: Activity,
|
||||
positionStr: String,
|
||||
adUnitId: String? = null,
|
||||
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null,
|
||||
closeCallback: () -> Unit, readyCallback:() -> Unit,
|
||||
|
|
@ -112,7 +113,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_position",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to finalAdUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowTriggerCount
|
||||
)
|
||||
)
|
||||
|
|
@ -124,7 +125,7 @@ class PangleRewardedAdController private constructor() {
|
|||
// eventName = "ad_show_fail",
|
||||
// params = mapOf(
|
||||
// "ad_unit_name" to finalAdUnitId,
|
||||
// "position" to PositionGet.get(),
|
||||
// "position" to positionStr,
|
||||
// "number" to totalShowFailCount,
|
||||
// "reason" to interceptResult.error.message
|
||||
// )
|
||||
|
|
@ -150,7 +151,7 @@ class PangleRewardedAdController private constructor() {
|
|||
currentRewardedAd = null
|
||||
currentAdUnitId = null
|
||||
readyCallback.invoke()
|
||||
showAdInternal(activity, ad, finalAdUnitId, onRewardEarned, closeCallback)
|
||||
showAdInternal(activity, positionStr,ad, finalAdUnitId, onRewardEarned, closeCallback)
|
||||
} else {
|
||||
ADLoadingDialog.hide()
|
||||
totalShowFailCount++
|
||||
|
|
@ -158,7 +159,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_show_fail",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to finalAdUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowFailCount,
|
||||
"reason" to "load_failed"
|
||||
)
|
||||
|
|
@ -172,7 +173,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_show_fail",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to finalAdUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowFailCount,
|
||||
"reason" to e.message.orEmpty()
|
||||
)
|
||||
|
|
@ -248,6 +249,7 @@ class PangleRewardedAdController private constructor() {
|
|||
|
||||
private suspend fun showAdInternal(
|
||||
activity: Activity,
|
||||
positionStr: String,
|
||||
rewardedAd: PAGRewardedAd,
|
||||
adUnitId: String,
|
||||
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)?,
|
||||
|
|
@ -282,7 +284,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_impression",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowCount,
|
||||
"ad_source" to (currentAdSource ?: "Pangle"),
|
||||
"value" to impressionValue,
|
||||
|
|
@ -320,7 +322,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_click",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalClickCount,
|
||||
"ad_source" to (currentAdSource ?: "Pangle"),
|
||||
"value" to (rewardedAd.pagRevenueInfo?.showEcpm?.revenue?.toDoubleOrNull() ?: 0.0),
|
||||
|
|
@ -334,6 +336,7 @@ class PangleRewardedAdController private constructor() {
|
|||
isShowing = false
|
||||
closeEvent(
|
||||
adUnitId = adUnitId,
|
||||
positionStr,
|
||||
adSource = currentAdSource,
|
||||
valueUsd = currentRevenueUsd,
|
||||
currencyCode = currentCurrency,
|
||||
|
|
@ -365,7 +368,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_reward_earned",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalRewardEarnedCount,
|
||||
"reward_name" to rewardItem.rewardName,
|
||||
"reward_amount" to rewardItem.rewardAmount,
|
||||
|
|
@ -401,7 +404,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_show_fail",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowFailCount,
|
||||
"reason" to model.errorMessage.orEmpty(),
|
||||
"ad_source" to (currentAdSource ?: "Pangle")
|
||||
|
|
@ -419,7 +422,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_show_fail",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowFailCount,
|
||||
"reason" to "rewarded_not_ready",
|
||||
"ad_source" to (currentAdSource ?: "Pangle")
|
||||
|
|
@ -439,7 +442,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_show_fail",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowFailCount,
|
||||
"reason" to e.message.orEmpty(),
|
||||
"ad_source" to (currentAdSource ?: "Pangle")
|
||||
|
|
@ -464,6 +467,7 @@ class PangleRewardedAdController private constructor() {
|
|||
|
||||
private fun closeEvent(
|
||||
adUnitId: String,
|
||||
positionStr: String,
|
||||
adSource: String? = "Pangle",
|
||||
valueUsd: Double? = null,
|
||||
currencyCode: String? = null,
|
||||
|
|
@ -474,7 +478,7 @@ class PangleRewardedAdController private constructor() {
|
|||
eventName = "ad_close",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to adUnitId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalCloseCount,
|
||||
"ad_source" to (adSource ?: "Pangle"),
|
||||
"value" to (valueUsd ?: 0.0),
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
/**
|
||||
* 预加载广告
|
||||
*/
|
||||
suspend fun preloadAd(context: Context, placementId: String? = null): AdResult<Unit> {
|
||||
suspend fun preloadAd(context: Context, positionStr: String, placementId: String? = null): AdResult<Unit> {
|
||||
if (!GlobalAdSwitchInterceptor.isGlobalAdEnabled()) {
|
||||
return AdResult.Failure(
|
||||
AdException(
|
||||
|
|
@ -117,7 +117,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
return AdResult.Success(Unit)
|
||||
}
|
||||
|
||||
return if (loadAd(context, finalPlacementId) != null) {
|
||||
return if (loadAd(context, positionStr, finalPlacementId) != null) {
|
||||
AdResult.Success(Unit)
|
||||
} else {
|
||||
AdResult.Failure(createAdException("广告加载失败"))
|
||||
|
|
@ -129,6 +129,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
*/
|
||||
suspend fun showAd(
|
||||
activity: Activity,
|
||||
positionStr: String,
|
||||
placementId: String? = null,
|
||||
onRewardEarned: ((String, Int, Double) -> Unit)? = null,
|
||||
closeCallback: ()->Unit, readyCallback:() -> Unit,
|
||||
|
|
@ -145,7 +146,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
eventName = "ad_position",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to finalPlacementId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowTriggerCount
|
||||
)
|
||||
)
|
||||
|
|
@ -159,7 +160,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
// eventName = "ad_show_fail",
|
||||
// params = mapOf(
|
||||
// "ad_unit_name" to finalPlacementId,
|
||||
// "position" to PositionGet.get(),
|
||||
// "position" to positionStr,
|
||||
// "number" to totalShowFailCount,
|
||||
// "reason" to interceptResult.error.message
|
||||
// )
|
||||
|
|
@ -176,7 +177,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
|
||||
if (entry == null) {
|
||||
ADLoadingDialog.show(activity)
|
||||
loadAd(activity, finalPlacementId)
|
||||
loadAd(activity, positionStr, finalPlacementId)
|
||||
entry = synchronized(adCache) {
|
||||
adCache[finalPlacementId]?.takeUnless { it.isExpired() }
|
||||
}
|
||||
|
|
@ -202,7 +203,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
/**
|
||||
* 加载广告
|
||||
*/
|
||||
private suspend fun loadAd(context: Context, placementId: String): TopOnRewardedAdEntry? {
|
||||
private suspend fun loadAd(context: Context, positionStr: String, placementId: String): TopOnRewardedAdEntry? {
|
||||
totalLoadCount++
|
||||
AdLogger.d("TopOn激励广告开始加载,广告位ID: %s,当前累计加载次数: %d", placementId, totalLoadCount)
|
||||
|
||||
|
|
@ -219,6 +220,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
val applicationContext = context.applicationContext
|
||||
val rewardedVideoAd = TURewardVideoAd(applicationContext, placementId)
|
||||
val listener = TopOnRewardedVideoListener(
|
||||
positionStr = positionStr,
|
||||
placementId = placementId,
|
||||
startLoadTime = System.currentTimeMillis(),
|
||||
rewardedVideoAd = rewardedVideoAd,
|
||||
|
|
@ -286,6 +288,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
* TopOn 激励视频广告监听器
|
||||
*/
|
||||
private inner class TopOnRewardedVideoListener(
|
||||
private val positionStr: String,
|
||||
private val placementId: String,
|
||||
private val startLoadTime: Long,
|
||||
private val rewardedVideoAd: TURewardVideoAd,
|
||||
|
|
@ -443,7 +446,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
eventName = "ad_show_fail",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to placementId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowFailCount,
|
||||
"ad_source" to (adInfo?.networkName ?: ""),
|
||||
"reason" to (adError.desc ?: adError.getFullErrorInfo())
|
||||
|
|
@ -467,7 +470,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
eventName = "ad_close",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to placementId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalCloseCount,
|
||||
"ad_source" to (adInfo.networkName ?: ""),
|
||||
"value" to (adInfo.publisherRevenue ?: 0.0),
|
||||
|
|
@ -484,7 +487,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
CoroutineScope(SupervisorJob() + Dispatchers.IO).launch {
|
||||
try {
|
||||
AdLogger.d("TopOn激励广告关闭,开始重新预缓存,广告位ID: %s", placementId)
|
||||
preloadAd(applicationContext, placementId)
|
||||
preloadAd(applicationContext, positionStr, placementId)
|
||||
} catch (e: Exception) {
|
||||
AdLogger.e("TopOn激励广告重新预缓存失败", e)
|
||||
}
|
||||
|
|
@ -507,7 +510,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
eventName = "ad_click",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to placementId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalClickCount,
|
||||
"ad_source" to (adInfo.networkName ?: ""),
|
||||
"value" to (adInfo.publisherRevenue ?: 0.0),
|
||||
|
|
@ -530,7 +533,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
eventName = "ad_reward_earned",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to placementId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalRewardEarnedCount,
|
||||
"reward_type" to rewardType,
|
||||
"reward_amount" to rewardAmount,
|
||||
|
|
@ -555,7 +558,7 @@ class TopOnRewardedAdController private constructor() {
|
|||
eventName = "ad_impression",
|
||||
params = mapOf(
|
||||
"ad_unit_name" to placementId,
|
||||
"position" to PositionGet.get(),
|
||||
"position" to positionStr,
|
||||
"number" to totalShowCount,
|
||||
"ad_source" to (adInfo.networkName ?: ""),
|
||||
"value" to (adInfo.publisherRevenue ?: 0.0),
|
||||
|
|
|
|||
Loading…
Reference in New Issue