use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.
the class HTMLCreative method startViewabilityTracker.
@Override
public void startViewabilityTracker() {
VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
mCreativeVisibilityTracker = new CreativeVisibilityTracker(getCreativeView().getWebView(), visibilityTrackerOption, ((PrebidWebViewBase) getCreativeView()).getWebView().isMRAID());
mCreativeVisibilityTracker.setVisibilityTrackerListener(this::onVisibilityEvent);
mCreativeVisibilityTracker.startVisibilityCheck(mContextReference.get());
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.
the class AdMobBannerMediationUtils method canPerformRefresh.
@Override
public boolean canPerformRefresh() {
AdView view = adView.get();
if (view == null) {
LogUtil.e(TAG, "AdView is null, it can be destroyed as WeakReference");
return false;
}
final VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
final VisibilityChecker checker = new VisibilityChecker(visibilityTrackerOption);
boolean isVisible = checker.isVisibleForRefresh(view);
if (isVisible) {
Log.d(TAG, "Visibility checker result: " + true);
} else {
Log.e(TAG, "Can't perform refresh. Ad view is not visible.");
}
return isVisible;
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.
the class MoPubBannerMediationUtils method canPerformRefresh.
@Override
public boolean canPerformRefresh() {
MoPubView adView = adViewReference.get();
if (isAdViewNull(adView)) {
return false;
}
final VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
final VisibilityChecker checker = new VisibilityChecker(visibilityTrackerOption);
boolean isVisible = checker.isVisibleForRefresh(adView);
if (isVisible) {
Log.d(TAG, "Visibility checker result: " + true);
} else {
Log.e(TAG, "Can't perform refresh. Ad view is not visible.");
}
return isVisible;
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.
the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse.
// VisibilityRunnable Tests
@Test
public void visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse() throws Exception {
ViewExposure viewExposure = new ViewExposure(100, new Rect(0, 0, 100, 100), null);
when(mSpyVisibilityChecker.isVisible(any(View.class))).thenReturn(true);
when(mSpyVisibilityChecker.checkViewExposure(any(View.class))).thenReturn(viewExposure);
when(mSpyVisibilityChecker.hasBeenVisible()).thenReturn(true);
when(mSpyVisibilityChecker.hasRequiredTimeElapsed()).thenReturn(true);
mCreativeVisibilityTracker.mVisibilityRunnable.run();
VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
verify(mMockVisibilityTrackerListener).onVisibilityChanged(result);
final VisibilityTrackerOption visibilityTrackerOption = mSpyVisibilityChecker.getVisibilityTrackerOption();
assertTrue(visibilityTrackerOption.isImpressionTracked());
assertFalse((Boolean) getFieldValue("mIsVisibilityScheduled"));
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.
the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo.
@Test
public void visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo() {
mockView();
VisibilityTrackerOption trackerOptionImpression = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
VisibilityTrackerOption trackerOptionMrc50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC50);
VisibilityTrackerOption trackerOptionMrc100 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC100);
VisibilityTrackerOption trackerOptionViewableVideo50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_VIDEO50);
final ViewExposure viewExposure = new ViewExposure(1.0f, new Rect(), new ArrayList<>());
Set<VisibilityTrackerOption> visibilityTrackerOptionSet = new HashSet<>();
visibilityTrackerOptionSet.add(trackerOptionImpression);
visibilityTrackerOptionSet.add(trackerOptionMrc50);
visibilityTrackerOptionSet.add(trackerOptionMrc100);
visibilityTrackerOptionSet.add(trackerOptionViewableVideo50);
CreativeVisibilityTracker creativeVisibilityTracker = new CreativeVisibilityTracker(mMockView, visibilityTrackerOptionSet);
creativeVisibilityTracker.setVisibilityTrackerListener(mMockVisibilityTrackerListener);
mockVisibilityChecker(creativeVisibilityTracker, viewExposure, visibilityTrackerOptionSet);
creativeVisibilityTracker.mVisibilityRunnable.run();
// 0 sec visibility duration
assertTrue(trackerOptionImpression.isImpressionTracked());
ShadowSystemClock.advanceBy(Duration.ofMillis(1000));
// 1 sec visibility duration
assertTrue(trackerOptionMrc50.isImpressionTracked());
assertTrue(trackerOptionMrc100.isImpressionTracked());
// 2 sec visibility duration
assertFalse(trackerOptionViewableVideo50.isImpressionTracked());
VisibilityTrackerResult impressionResult = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
VisibilityTrackerResult mrc50Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC50, viewExposure, true, true);
VisibilityTrackerResult mrc100Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC100, viewExposure, true, true);
VisibilityTrackerResult videoResult = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_VIDEO50, viewExposure, true, true);
verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(impressionResult));
verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc50Result));
verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc100Result));
verify(mMockVisibilityTrackerListener, times(0)).onVisibilityChanged(eq(videoResult));
}
Aggregations