diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250.java index a5c146962..e602b13df 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250.java @@ -85,7 +85,7 @@ public void failure(@NonNull PbFindSizeError error) { protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50.java index fe0927f5b..a0914e550 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50.java @@ -85,7 +85,7 @@ public void failure(@NonNull PbFindSizeError error) { protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayInterstitial.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayInterstitial.java index cb66ff468..3f977e099 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayInterstitial.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiDisplayInterstitial.java @@ -59,7 +59,7 @@ protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatBanner.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatBanner.java index f45e3f479..18a4f5a14 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatBanner.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatBanner.java @@ -98,7 +98,7 @@ public void failure(@NonNull PbFindSizeError error) { protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitial.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitial.java index 43e61a5c2..52a63a878 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitial.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitial.java @@ -72,7 +72,7 @@ protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeInApp.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeInApp.java index 2c8332c06..a45ba5176 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeInApp.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeInApp.java @@ -188,7 +188,7 @@ protected void onDestroy() { adView.destroy(); } if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } if (unifiedNativeAd != null) { unifiedNativeAd.destroy(); diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeStyles.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeStyles.java index 566ffba46..6c6276335 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeStyles.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiNativeStyles.java @@ -94,7 +94,7 @@ private void configureNativeAdUnit(NativeAdUnit adUnit) { protected void onDestroy() { super.onDestroy(); if (nativeAdUnit != null) { - nativeAdUnit.stopAutoRefresh(); + nativeAdUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoBanner.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoBanner.java index 9ab1798d2..7baaa1f91 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoBanner.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoBanner.java @@ -88,7 +88,7 @@ protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInStream.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInStream.java index ebb4f2b26..9b8ff3d19 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInStream.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInStream.java @@ -100,7 +100,7 @@ protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } if (adsLoader != null) { adsLoader.setPlayer(null); diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInterstitial.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInterstitial.java index c7064e6f3..0e0bdcfb5 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInterstitial.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoInterstitial.java @@ -71,7 +71,7 @@ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoRewarded.java b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoRewarded.java index ce2814afe..7b1601415 100644 --- a/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoRewarded.java +++ b/Example/PrebidDemoJava/src/main/java/org/prebid/mobile/javademo/activities/ads/gam/original/GamOriginalApiVideoRewarded.java @@ -66,7 +66,7 @@ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { protected void onDestroy() { super.onDestroy(); if (adUnit != null) { - adUnit.stopAutoRefresh(); + adUnit.destroy(); } } } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250Activity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250Activity.kt index 971b45987..5ad1ebff6 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250Activity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner300x250Activity.kt @@ -76,7 +76,7 @@ class GamOriginalApiDisplayBanner300x250Activity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } private fun createGAMListener(adView: AdManagerAdView): AdListener { diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50Activity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50Activity.kt index e1f03d5d1..13fb96996 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50Activity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBanner320x50Activity.kt @@ -31,7 +31,7 @@ class GamOriginalApiDisplayBanner320x50Activity : BaseAdActivity() { companion object { const val AD_UNIT_ID = "/21808260008/prebid_demo_app_original_api_banner" - const val CONFIG_ID = "prebid-demo-banner-320-50" + const val CONFIG_ID = "prebid-ita-banner-320-50" const val WIDTH = 320 const val HEIGHT = 50 } @@ -71,6 +71,9 @@ class GamOriginalApiDisplayBanner320x50Activity : BaseAdActivity() { parameters.api = listOf(Signals.Api.MRAID_3, Signals.Api.OMID_1) adUnit?.bannerParameters = parameters + // Optional: the activation of the native impression tracker + adUnit?.activatePrebidImpressionTracker(adView) + adUnit?.setAutoRefreshInterval(refreshTimeSeconds) adUnit?.fetchDemand(request) { adView.loadAd(request) @@ -80,7 +83,7 @@ class GamOriginalApiDisplayBanner320x50Activity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBannerMultiSizeActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBannerMultiSizeActivity.kt index 5583f4832..7c0fbf10a 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBannerMultiSizeActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayBannerMultiSizeActivity.kt @@ -83,7 +83,7 @@ class GamOriginalApiDisplayBannerMultiSizeActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayInterstitialActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayInterstitialActivity.kt index c5374e451..8f3ebec5b 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayInterstitialActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiDisplayInterstitialActivity.kt @@ -32,7 +32,7 @@ class GamOriginalApiDisplayInterstitialActivity : BaseAdActivity() { const val CONFIG_ID = "prebid-demo-display-interstitial-320-480" } - private var adUnit: AdUnit? = null + private var adUnit: InterstitialAdUnit? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -45,6 +45,9 @@ class GamOriginalApiDisplayInterstitialActivity : BaseAdActivity() { // 1. Create InterstitialAdUnit adUnit = InterstitialAdUnit(CONFIG_ID, 80, 60) + // Activate additional impression tracker (for burl) + adUnit?.activatePrebidImpressionTracker(true) + // 2. Make a bid request to Prebid Server val request = AdManagerAdRequest.Builder().build() adUnit?.fetchDemand(request) { @@ -78,6 +81,6 @@ class GamOriginalApiDisplayInterstitialActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiInStreamActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiInStreamActivity.kt index ddc8c95e8..c104d5366 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiInStreamActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiInStreamActivity.kt @@ -136,7 +136,7 @@ class GamOriginalApiInStreamActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() adsLoader?.setPlayer(null) adsLoader?.release() player?.release() diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatBannerActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatBannerActivity.kt index 9443a9da6..7fe378280 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatBannerActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatBannerActivity.kt @@ -87,7 +87,7 @@ class GamOriginalApiMultiformatBannerActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } private fun createGAMListener(adView: AdManagerAdView): AdListener { diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitialActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitialActivity.kt index 265327de9..fa4f66898 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitialActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiMultiformatInterstitialActivity.kt @@ -91,6 +91,6 @@ class GamOriginalApiMultiformatInterstitialActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeInAppActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeInAppActivity.kt index 607981d8a..89656fdef 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeInAppActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeInAppActivity.kt @@ -212,7 +212,7 @@ class GamOriginalApiNativeInAppActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() adView?.destroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() unifiedNativeAd?.destroy() } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeStylesActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeStylesActivity.kt index ce5bede0b..765c6c36f 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeStylesActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiNativeStylesActivity.kt @@ -93,7 +93,7 @@ class GamOriginalApiNativeStylesActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - nativeAdUnit?.stopAutoRefresh() + nativeAdUnit?.destroy() } } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoInterstitialActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoInterstitialActivity.kt index b20a9bdd1..59d4a3800 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoInterstitialActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoInterstitialActivity.kt @@ -88,7 +88,7 @@ class GamOriginalApiVideoInterstitialActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } } diff --git a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoRewardedActivity.kt b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoRewardedActivity.kt index af01ad518..28248be3b 100644 --- a/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoRewardedActivity.kt +++ b/Example/PrebidDemoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/activities/ads/gam/original/GamOriginalApiVideoRewardedActivity.kt @@ -74,7 +74,7 @@ class GamOriginalApiVideoRewardedActivity : BaseAdActivity() { override fun onDestroy() { super.onDestroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } } diff --git a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalBannerFragment.kt b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalBannerFragment.kt index ad5fd724d..9106bccc3 100644 --- a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalBannerFragment.kt +++ b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalBannerFragment.kt @@ -125,7 +125,7 @@ open class GamOriginalBannerFragment : AdFragment() { override fun onDestroyView() { super.onDestroyView() adView?.destroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() } private class Events(parentView: View) : BaseEvents(parentView) { diff --git a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamFragment.kt b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamFragment.kt index d6a94ef98..09a90229c 100644 --- a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamFragment.kt +++ b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamFragment.kt @@ -101,7 +101,7 @@ class GamOriginalInstreamFragment : AdFragment() { override fun onDestroyView() { super.onDestroyView() - adUnit?.stopAutoRefresh() + adUnit?.destroy() adsLoader?.setPlayer(null) adsLoader?.release() player?.release() diff --git a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamNewApiFragment.kt b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamNewApiFragment.kt index a6a99406e..1fdc43527 100644 --- a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamNewApiFragment.kt +++ b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalInstreamNewApiFragment.kt @@ -101,7 +101,7 @@ class GamOriginalInstreamNewApiFragment : AdFragment() { override fun onDestroyView() { super.onDestroyView() - adUnit?.stopAutoRefresh() + adUnit?.destroy() adsLoader?.setPlayer(null) adsLoader?.release() player?.release() diff --git a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeBannerFragment.kt b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeBannerFragment.kt index dbe135ea0..06234b3eb 100644 --- a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeBannerFragment.kt +++ b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeBannerFragment.kt @@ -144,7 +144,7 @@ class GamOriginalNativeBannerFragment : AdFragment() { override fun onDestroy() { super.onDestroy() - nativeAdUnit?.stopAutoRefresh() + nativeAdUnit?.destroy() } private class Events(parentView: View) : BaseEvents(parentView) { diff --git a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeInAppFragment.kt b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeInAppFragment.kt index 0123888f2..f099f5aeb 100644 --- a/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeInAppFragment.kt +++ b/Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/plugplay/bidding/gam/original/GamOriginalNativeInAppFragment.kt @@ -222,7 +222,7 @@ class GamOriginalNativeInAppFragment : PpmNativeFragment() { override fun onDestroy() { super.onDestroy() adView?.destroy() - adUnit?.stopAutoRefresh() + adUnit?.destroy() unifiedNativeAd?.destroy() } } \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java index fae031209..19f619fa5 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java @@ -19,11 +19,15 @@ import static org.prebid.mobile.PrebidMobile.AUTO_REFRESH_DELAY_MAX; import static org.prebid.mobile.PrebidMobile.AUTO_REFRESH_DELAY_MIN; +import android.app.Activity; +import android.app.Application; import android.content.Context; import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.os.Bundle; import android.text.TextUtils; +import android.view.View; import androidx.annotation.IntRange; import androidx.annotation.NonNull; @@ -43,6 +47,7 @@ import org.prebid.mobile.rendering.sdk.PrebidContextHolder; import org.prebid.mobile.tasksmanager.TasksManager; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@ -56,6 +61,8 @@ */ public abstract class AdUnit { + private static final String TAG = "AdUnit"; + protected AdUnitConfiguration configuration = new AdUnitConfiguration(); @Nullable @@ -65,7 +72,11 @@ public abstract class AdUnit { @Nullable protected BidResponse bidResponse; + protected final VisibilityMonitor visibilityMonitor = new VisibilityMonitor(); + protected WeakReference adViewReference = new WeakReference<>(null); + protected boolean allowNullableAdObject = false; + protected boolean activatePrebidImpressionTracker = false; public AdUnit(@NotNull String configId) { configuration.setConfigId(configId); @@ -123,6 +134,7 @@ public void destroy() { if (bidLoader != null) { bidLoader.destroy(); } + visibilityMonitor.stopTracking(); } /** @@ -147,6 +159,8 @@ public void fetchDemand(@NonNull final OnCompleteListener2 listener) { * @param listener callback when operation is completed (success or fail) */ public void fetchDemand(Object adObject, @NonNull OnCompleteListener listener) { + visibilityMonitor.stopTracking(); + if (TextUtils.isEmpty(PrebidMobile.getPrebidServerAccountId())) { LogUtil.error("Empty account id."); listener.onComplete(ResultCode.INVALID_ACCOUNT_ID); @@ -233,6 +247,15 @@ public void fetchDemand(OnFetchDemandResult listener) { }); } + /** + * Applies the native visibility tracker for tracking `burl` url. + * + * @param adView the ad view object (f.e. {@code AdManagerAdView}) + */ + public void activatePrebidImpressionTracker(View adView) { + adViewReference = new WeakReference<>(adView); + } + // MARK: - adunit context data aka inventory data (imp[].ext.data) /** @@ -449,6 +472,8 @@ public void onFetchCompleted(BidResponse response) { HashMap keywords = response.getTargeting(); Util.apply(keywords, adObject); originalListener.onComplete(ResultCode.SUCCESS); + + registerVisibilityTrackerIfNeeded(bidResponse); } @Override @@ -494,5 +519,45 @@ public AdUnitConfiguration getConfiguration() { return configuration; } + private void registerVisibilityTrackerIfNeeded(BidResponse response) { + visibilityMonitor.stopTracking(); + + if (response == null || response.getWinningBid() == null || response.getWinningBid().getBurl() == null) { + return; + } + if (response.isVideo()) { + LogUtil.debug(TAG, "VisibilityTracker ignored due to the video ad"); + return; + } + + String burl = response.getWinningBid().getBurl(); + + String cacheId = response.getTargeting().get("hb_cache_id"); + if (cacheId == null) { + LogUtil.warning(TAG, "Can't register visibility tracker. There is no hb_cache_id keyword."); + return; + } + + boolean isBannerTracker = !(this instanceof InterstitialAdUnit); + if (isBannerTracker) { + bannerVisibilityTracker(burl, cacheId); + } else if (activatePrebidImpressionTracker) { + interstitialVisibilityTracker(burl, cacheId); + } + } + + private void bannerVisibilityTracker(String burl, String cacheId) { + View adViewContainer = adViewReference != null ? adViewReference.get() : null; + if (adViewContainer == null) { + return; + } + + visibilityMonitor.trackView(adViewContainer, burl, cacheId); + } + + private void interstitialVisibilityTracker(String burl, String cacheId) { + visibilityMonitor.trackInterstitial(burl, cacheId); + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java index 64b7e6102..4532d792d 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java @@ -79,4 +79,8 @@ public void setOrtbConfig(@Nullable String ortbConfig) { configuration.setOrtbConfig(ortbConfig); } + public void activatePrebidImpressionTracker(boolean activate) { + this.activatePrebidImpressionTracker = activate; + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VisibilityActivityListener.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VisibilityActivityListener.java new file mode 100644 index 000000000..137ba4d6d --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VisibilityActivityListener.java @@ -0,0 +1,46 @@ +package org.prebid.mobile; + +import android.app.Activity; +import android.app.Application; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class VisibilityActivityListener implements Application.ActivityLifecycleCallbacks { + + private final VisibilityMonitor monitor; + private final String burl; + private final String cacheId; + + public VisibilityActivityListener(VisibilityMonitor monitor, String burl, String cacheId) { + this.monitor = monitor; + this.burl = burl; + this.cacheId = cacheId; + } + + @Override + public void onActivityResumed(@NonNull Activity activity) { + View rootView = activity.getWindow().getDecorView(); + monitor.trackView(rootView, burl, cacheId); + } + + @Override + public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {} + + @Override + public void onActivityStarted(@NonNull Activity activity) {} + + @Override + public void onActivityPaused(@NonNull Activity activity) {} + + @Override + public void onActivityStopped(@NonNull Activity activity) {} + + @Override + public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {} + + @Override + public void onActivityDestroyed(@NonNull Activity activity) {} +} diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VisibilityMonitor.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VisibilityMonitor.java new file mode 100644 index 000000000..75862e6dc --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VisibilityMonitor.java @@ -0,0 +1,199 @@ +package org.prebid.mobile; + +import android.app.Application; +import android.content.Context; +import android.os.CountDownTimer; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebView; + +import androidx.annotation.Nullable; + +import org.jetbrains.annotations.NotNull; +import org.prebid.mobile.addendum.AdViewUtils; +import org.prebid.mobile.rendering.models.CreativeVisibilityTracker; +import org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption; +import org.prebid.mobile.rendering.models.ntv.NativeEventTracker; +import org.prebid.mobile.rendering.networking.tracking.ServerConnection; +import org.prebid.mobile.rendering.sdk.PrebidContextHolder; + +import java.lang.ref.WeakReference; + +public class VisibilityMonitor { + + private boolean stopAfterFirstFinding = false; + + private final VisibilityTimer visibilityTimer = new VisibilityTimer(); + + @Nullable + private VisibilityActivityListener activityListener; + + public void trackView(@NotNull View adViewContainer, @NotNull String burl, @NotNull String cacheId) { + stopTracking(); + + visibilityTimer.start(adViewContainer, burl, cacheId, stopAfterFirstFinding); + } + + public void trackInterstitial(String burl, String cacheId) { + stopTracking(); + + stopAfterFirstFinding = true; + activityListener = new VisibilityActivityListener(this, burl, cacheId); + getApplication().registerActivityLifecycleCallbacks(activityListener); + } + + public void stopTracking() { + visibilityTimer.destroy(); + + if (activityListener != null) { + getApplication().unregisterActivityLifecycleCallbacks(activityListener); + } + } + + private Application getApplication() { + Context context = PrebidContextHolder.getContext(); + return (Application) context; + } + + private static class VisibilityTimer extends CountDownTimer { + + private static final int LONGEVITY = Integer.MAX_VALUE; + private static final int INTERVAL = 500; + private static final String TAG = "VisibilityTimer"; + + private int lastWebViewHash; + private boolean stopAfterFirstFinding; + private String burl; + private String responseCacheId; + + private WeakReference containerViewReference; + @Nullable + private CreativeVisibilityTracker visibilityTracker; + + public VisibilityTimer() { + super(LONGEVITY, INTERVAL); + } + + public void start(View containerView, String burl, String cacheId, boolean stopAfterFirstFinding) { + this.burl = burl; + this.responseCacheId = cacheId; + this.containerViewReference = new WeakReference<>(containerView); + this.stopAfterFirstFinding = stopAfterFirstFinding; + + LogUtil.debug(TAG, "Start of monitoring..."); + start(); + } + + @Override + public void onTick(long millisUntilFinished) { + View containerView = containerViewReference.get(); + if (containerView == null) { + LogUtil.debug(TAG, "Cancelled due to ad view is null"); + destroy(); + return; + } + + WebView webView = findIn(containerView); + if (webView == null) { + return; + } + + if (lastWebViewHash == webView.hashCode()) { + return; + } + lastWebViewHash = webView.hashCode(); + + if (stopAfterFirstFinding) { + LogUtil.debug(TAG, "Interstitial WebView found. Stopping..."); + destroy(); + } + + AdViewUtils.findCacheId( + webView, + attachVisibilityTrackerTask(new WeakReference<>(webView), this, responseCacheId, lastWebViewHash) + ); + } + + private void attachVisibilityTracker(WebView webView) { + if (visibilityTracker != null) { + visibilityTracker.stopVisibilityCheck(); + } + + visibilityTracker = new CreativeVisibilityTracker(webView, new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION)); + visibilityTracker.setVisibilityTrackerListener(result -> { + boolean visible = result.isVisible(); + if (visible) { + LogUtil.debug(TAG, "View is visible. Firing event: " + burl); + ServerConnection.fireAndForget(burl); + visibilityTracker.stopVisibilityCheck(); + } + }); + visibilityTracker.startVisibilityCheck(PrebidContextHolder.getContext()); + } + + @Override + public void onFinish() { + } + + public void destroy() { + if (visibilityTracker != null) { + LogUtil.debug(TAG, "Destroying"); + visibilityTracker.stopVisibilityCheck(); + visibilityTracker = null; + } + cancel(); + } + + public static WebView findIn(View root) { + if (root instanceof WebView) { + return (WebView) root; + } + + if (root instanceof ViewGroup) { + return findRecursively((ViewGroup) root); + } + + return null; + } + + private static WebView findRecursively(ViewGroup root) { + for (int i = 0; i < root.getChildCount(); i++) { + View child = root.getChildAt(i); + if (child instanceof WebView) { + return (WebView) child; + } + + if (child instanceof ViewGroup) { + WebView result = findRecursively((ViewGroup) child); + if (result != null) { + return result; + } + } + } + return null; + } + + private static AdViewUtils.CacheIdResult attachVisibilityTrackerTask(WeakReference webViewReference, VisibilityTimer visibilityTimer, String responseCacheId, int lastWebViewHash) { + return cacheId -> { + if (cacheId == null || cacheId.isEmpty()) { + return; + } + + if (!cacheId.equals(responseCacheId)) { + LogUtil.warning(TAG, "Different cache ids"); + return; + } + + WebView webView = webViewReference.get(); + if (webView == null) { + return; + } + + visibilityTimer.attachVisibilityTracker(webView); + LogUtil.debug(TAG, "Registering the new WebView: " + lastWebViewHash); + }; + } + } + +} diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/addendum/AdViewUtils.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/addendum/AdViewUtils.java index 4d6c677b0..298e950ad 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/addendum/AdViewUtils.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/addendum/AdViewUtils.java @@ -23,9 +23,11 @@ import android.view.ViewGroup; import android.webkit.ValueCallback; import android.webkit.WebView; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Size; + import org.prebid.mobile.CacheManager; import org.prebid.mobile.LogUtil; import org.prebid.mobile.PrebidNativeAd; @@ -33,22 +35,35 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; public final class AdViewUtils { + /** + * Escaped double quotes. + */ + private static final String EDQ = "\\\\\""; + private static final String INNER_HTML_SCRIPT = "document.body.innerHTML"; private static final String SIZE_VALUE_REGEX_EXPRESSION = "[0-9]+x[0-9]+"; private static final String SIZE_OBJECT_REGEX_EXPRESSION = "hb_size\\W+" + SIZE_VALUE_REGEX_EXPRESSION; //"hb_size\\W+[0-9]+x[0-9]+" + private static final String CACHE_ID_REGEX = EDQ + "hb_cache_id" + EDQ + ":\\[" + EDQ + "(.*?)" + EDQ + "\\]"; + + private static final String GAM_VIEW_CLASS = "com.google.android.gms.ads.doubleclick.PublisherAdView"; private static final String GAM_VIEW_CLASS_2 = "com.google.android.gms.ads.admanager.AdManagerAdView"; private static final String GAM_CUSTOM_TEMPLATE_AD_CLASS = "com.google.android.gms.ads.formats.NativeCustomTemplateAd"; private static final String GAM_CUSTOM_TEMPLATE_AD_CLASS_2 = "com.google.android.gms.ads.nativead.NativeCustomFormatAd"; - private AdViewUtils() { } + private AdViewUtils() { + } public static void findPrebidCreativeSize(@Nullable View adView, final PbFindSizeListener handler) { if (adView == null) { @@ -75,6 +90,7 @@ static void triggerSuccess(WebView webView, Pair adSize, PbFin fixZoomIn(webView, width, height); } + //a fix of strange bug on Android with image scaling up //case: should be called after PublisherAdView.setAdSizes() static void fixZoomIn(final WebView webView, final int expectedWidth, final int expectedHeight) { @@ -356,6 +372,29 @@ static String matchAndCheck(String regex, String text) { return firstResult; } + public static void findCacheId(WebView webView, CacheIdResult onResult) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + onResult.run(null); + return; + } + + webView.evaluateJavascript(INNER_HTML_SCRIPT, value -> { + String result = findCacheId(value); + onResult.run(result); + }); + } + + @Nullable + static String findCacheId(String html) { + Pattern pattern = Pattern.compile(CACHE_ID_REGEX); + Matcher matcher = pattern.matcher(html); + + if (!matcher.find() || matcher.groupCount() == 0) { + return null; + } + return matcher.group(1); + } + @Nullable static Pair stringToSize(String size) { String[] sizeArr = size.split("x"); @@ -469,12 +508,17 @@ static Object callMethodOnObject(Object object, String methodName, Object... par return null; } + public interface CacheIdResult { + void run(String cacheId); + } + } //It is not possible to use Enum because we should have a possibility to pass additional information final class PbFindSizeErrorFactory { - private PbFindSizeErrorFactory() { } + private PbFindSizeErrorFactory() { + } //common errors static final int UNSPECIFIED_CODE = 201;