prebid / prebid-mobile-android

Prebid Mobile SDK for Android applications
Apache License 2.0
58 stars 82 forks source link

Prefetch the advertising info #696

Open YuriyVelichkoPI opened 9 months ago

YuriyVelichkoPI commented 9 months ago

Background

In the current implementation, the SDK requests the advertising info on each bid request. To avoid blocking, it is performed async in the background thread. However, the Prebid SDK in any case, is waiting until the OS returns the current advertising info. See the class AdIdManager of the SDK for the details.

This implementation has two major disadvantages:

To avoid runtime issues and get rid of delays in creating the bid request, the SDK should prefetch the advertising info so it's always available. The prefetching should take into consideration the Android policy to request the updated info each time it's needed and not cache it.

Proposal

Even though Android docs advise not to cache the ID, it's clear that this property won't be changed too often, especially during the single app session. So, if the SDK will fetch it on the initialization and refresh on each following bid request, it shouldn't violate privacy settings and other policies.

The general approach is displayed in the following diagram:

Prebid - Github Proposals

Step 1: The SDK on the initialization step runs the background task to fetch the advertising info and save it in memory. No saving to the persistent memory. Step 2: Once the SDK is initialized, publishers can run bid requests Step 3: Publisher calls the fetchDemand method, or any other, that leads to creating and sending the Bid Request. Step 4: Prebid SDK uses the prefetched advertising info to build the Bid Request Step 5: Prebid SDK updates the advertising info, starting the background task. The SDK doesn't wait for the result. Step 6: SDK makes the bid request with prefetched advertising info

Once the updating task is finished, the advertising info will be actualized and used in the subsequent bid request.

Note: the diagram and description don't contain, but assume that fetching the advertising info is performed according to the user consent and permission as it is happening now.

Objectives

Once the proposal is reviewed, finalized, and approved, the implementation will assume the following steps:

YuriyVelichkoPI commented 9 months ago

History note. The motivation for the proposed changes was raised in the discussion of this PR. This is not the first time we have experienced problems with the sequential retrieval of the advertising info while preparing the bid request.