prebid / prebid-mobile-ios

Prebid Mobile SDK for iOS applications
Apache License 2.0
46 stars 85 forks source link

Stop ViewabilityTimer when ViewForTracking has become nil #949

Closed jsligh closed 6 months ago

jsligh commented 6 months ago

Closes #908

shinwan2 commented 6 months ago

Thank you so much for handling this @YuriyVelichkoPI and @jsligh.

If I may be so bold, below are my use cases and expectations described by unit tests for faster feedback loop. https://github.com/prebid/prebid-mobile-ios/compare/master...smartnews:prebid-mobile-ios:feature/optimize-view-tracking?expand=1

Let me know if I can be of more help.

YuriyVelichkoPI commented 6 months ago

@shinwan2, thank you for the clarification of the use case.

If I understood correctly, you want to display the same ad in the feed several times. Do you want to do it regardless of the impression event, Or if the ad is tracked the impression, you don't need to display it one more time in the feed?

To support your scenario, I believe you should use some additional container view as a point of viewability tracking and add this whole container to the different cells in the feed.

The pseudo-code solution:

 let nativeAd = NativeAd.create(cacheId: cacheId!)!
 let adContainer: UIView = createMyNativeAd(from: nativeAd)

 nativeAd.registerView(adContainer ...)

 cell.addSubview(adContainer)

// Later, after scrolling do the same, the native ad will still track the viewability of the adContainer but not the cell in the feed
cell.addSubview(adContainer)
YuriyVelichkoPI commented 6 months ago

In any casy after expecting the use case and the current codebase I think that we still need several additional enchancmets regarding the impression tracking of the native ads:

It will prevent

shinwan2 commented 6 months ago

@YuriyVelichkoPI

Do you want to do it regardless of the impression event

Yes, this one. The ad once assigned to a given slot (e.g. 4th slot on a feed) will always be shown on that same slot (using UITableViewCell).

I believe you should use some additional container view as a point of viewability tracking and add this whole container to the different cells in the feed.

I see, I believe it should be OK to clear the UIImageView.image (showing the ad image) to save memory when it's out of view?