How do we handle expired ads??

206 views
Skip to first unread message

joe...@gmail.com

unread,
Sep 9, 2024, 5:44:58 PM9/9/24
to Google Mobile Ads SDK Developers
There's a blue 'Tip' section in the Admob Interstitial and Rewarded docs that state the following:

Tip: You can use ad load calls to build up a cache of preloaded ads before you intend to show them, so that ads can be shown with zero latency when needed. Since ads expire after an hour, you should clear this cache and reload with new ads every hour.

This seems quite important, however, there is no actual code samples that explain how to achieve this. The code samples provided by Google do not account for any cache-clearing or if the Ad is expired.

My questions:
- Is this something that's done 'behind the scenes' where you don't have to account for this in code?
- If it's something that needs to be implemented in code - where can we find code samples on how to achieve this?
- If you preload ads on launch - then the user closes the App (without firing any ads), returns 2 hours later and does something to trigger an ad - what happens?

Thank you.


Mobile Ads SDK Forum Advisor

unread,
Sep 10, 2024, 7:40:14 AM9/10/24
to joe...@gmail.com, google-adm...@googlegroups.com

Hi,

As per the Interstitial loading Ad document an Ad expires for every one hour. Kindly follow the below code snippet to check if the Ad is expired or not: 

func getTimeDifference(){
        let currentTime = Date()
        guard let adTime = adTime else{
            return
        }
        let difference =  currentTime.timeIntervalSince1970 - adTime.timeIntervalSince1970
        print(difference)
        if difference > 3600{
            print("your ad is expired")
            //Load ad here.
        }else {
            print("your ad is not expired")
        }
    }

As you have mentioned that you are going to the app after one hour then you can call this function applicationWillEnterForeground and viewWilAppear methods.

  • Is this something that's done 'behind the scenes' where you don't have to account for this in code?
    • This logic needs to be written by the user according to the requirement.
  • If it's something that needs to be implemented in code - where can we find code samples on how to achieve this?
    • As of now this is not implemented yet in sample projects because it depends on user requirements. 
  • If you preload ads on launch - then the user closes the App (without firing any ads), returns 2 hours later and does something to trigger an ad - what happens?
    • As we have already said that the Ad expires every hour even  if you return 2 hours later fresh Ad loads if you request to load an Ad.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vFy64:ref" (ADR-00267334)

Thanks,
 
Google Logo Mobile Ads SDK Team


joe...@gmail.com

unread,
Sep 10, 2024, 4:00:07 PM9/10/24
to Google Mobile Ads SDK Developers
Thank you for the update and code snippet.

I want to call the code to check if Ad is expired in applicationWillEnterForeground.
My logic will look something like this:
if (rewardedAd != nil && AdCheck.isAdExpired == true) {
//...
}

I want to check if the ad is NOT nil AND expired. I think checking both will prevent unnecessary ad requests.
If an ad is not nil, it still can be expired, correct? (meaning my logic is okay)

Or if you have any other suggestions, it would be appreciated!

Mobile Ads SDK Forum Advisor

unread,
Sep 10, 2024, 5:05:15 PM9/10/24
to joe...@gmail.com, google-adm...@googlegroups.com
Hi Joe,

Yes, It's a correct approach and you can use perviously mentioned time logic in AdCheck.isAdExpired.
Also it require to fire local notification from applicationWillEnterForeground to your ViewColtroller observer where your ad variable exists.

Kindly reach out to us if you've any other concern related to Mobile Ads SDK.

Thanks
Reply all
Reply to author
Forward
0 new messages