Request: offer official API functions to check cached values about last ad-consent results

137 views
Skip to first unread message

Liran Barsisa

unread,
Dec 13, 2023, 6:45:16 PM12/13/23
to Google Mobile Ads SDK Developers
The `UserMessagingPlatform.getConsentInformation` can't return anything till `requestConsentInfoUpdate` is being called on it.
However, `requestConsentInfoUpdate` uses Activity which isn't always available (and can cause memory leaks), and it also takes much more time if we had it cached in just a file instead.

I've found some weird workaround to query SharedPreferences of the SDK, but this is illogical as there should be an official way to do it.

Please offer some official API to get the most recent consent-information that we have.
Also remove the need to use Activity for every important operation here. Not always we can initialize ads via an Activity.

Mobile Ads SDK Forum Advisor

unread,
Dec 13, 2023, 10:27:00 PM12/13/23
to lbl...@gmail.com, google-adm...@googlegroups.com

Hi Liran Barsisa, 

Thank you for contacting the Mobile Ads SDK Support team.

By reviewing your concern, I understand that you are facing issues with a situation where obtaining consent information in your Android app is causing some issues related to memory and performance. 

If you're facing problems with memory leaks and performance, you might consider the following approaches:

Use Application Context Instead of using the Activity context. The Application context doesn't have the same lifecycle as an Activity, so you won't run into issues like memory leaks related to holding references to activities.

UserMessagingPlatform.getConsentInformation(getApplicationContext());

For checking cache you need to implement the readFromCache(), isCacheExpired(), and handleConsentInformation() methods according to your caching strategy.

ConsentInformation cachedConsentInfo = readFromCache();

if (cachedConsentInfo != null && !isCacheExpired()) {

 // Use cached information

 handleConsentInformation(cachedConsentInfo);

} else {

 // Fetch new consent information

 requestConsentInfoUpdate();

}

Kindly share the below information to investigate further.

  • Mobile Ads SDK Version
  • App ID and Ad Unit ID
  • Sample project which replicates the issue.
  • Steps to replicate the issue

 

This message is in relation to case "ref:!00D1U01174p.!5004Q02r1ij4:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


Liran Barsisa

unread,
Dec 14, 2023, 4:18:57 AM12/14/23
to Google Mobile Ads SDK Developers
Hi, please don't mention names and emails. I have enough spam already.

You cannot use getApplicationContext except for UserMessagingPlatform.getConsentInformation , and even then it won't return you a cached result, and it's also documented as such:

None of the functions you've mentioned exist: readFromCache(), isCacheExpired(), and handleConsentInformation(). 
Also, as I've read, even if I cache the "canRequestAds" and "getPrivacyOptionsRequirementStatus" myself, it doesn't mean it's this way forever, because it seems there are expiration dates of about 13 months:
https://groups.google.com/g/google-admob-ads-sdk/c/KcW2D4kue_Q/m/KbSVWCLAAQAJ
It also mentions there that the SDK itself doesn't handle the expiration correctly, to remove expired cached results. 

This means that not only there is cache that we can't reach officially, but it's also not managed properly.

So please offer an official API to get what's already cached and fix the bugs mentioned on the website, or better:
1. For UserMessagingPlatform.getConsentInformation , always return the last cached result for "canRequestAds" and "getPrivacyOptionsRequirementStatus" , and when it's expired
2. For requestConsentInfoUpdate , offer to use Context instead of Activity, and automatically use the cached result if possible, to minimize the time it takes to load it.
3. Cache should handle expiration date too, automatically. If it's expired, should return values as if we never queried so far.

This isn't a bug but a request, so I don't understand why you need my information.

Jason Hoare

unread,
Dec 14, 2023, 5:21:29 PM12/14/23
to google-adm...@googlegroups.com
--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/1CM5e000000000000000000000000000000000000000000000S5N08700Luq9-3FsQiyEr3-G8n0Uuw%40sfdc.net.
Reply all
Reply to author
Forward
0 new messages