How to read consent choices in unity in C#

412 views
Skip to first unread message

Romain Bitard

unread,
Jan 11, 2024, 2:49:15 AM1/11/24
to Google Mobile Ads SDK Developers
it says how to read consent choices from android/ios. How can we do that from C# with unity ? Is there a bridge or some classes we can use ?

"

Consent is not represented by a single bit, but rather a set of purposes and vendors as defined in the IAB TCF specification. See Consent Policies: Personalized & Non-Personalized Ads for criteria for Google Ads personalization.

See how to read consent choices (Android | iOS) for information on reading consent choices programmatically. The IAB also provides a web tool where you can manually decode the TC String.

"


Mobile Ads SDK Forum Advisor

unread,
Jan 11, 2024, 3:51:14 AM1/11/24
to bitard...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting the Mobile Ads SDK Support team.

I will check with our team regarding your query and one of my team members will reach out to you once we have an update on this. Meanwhile, your patience is highly appreciated.

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

Thanks,
 
Google Logo Mobile Ads SDK Team


Mobile Ads SDK Forum Advisor

unread,
Jan 11, 2024, 7:59:40 PM1/11/24
to google-adm...@googlegroups.com, bitard...@gmail.com

Hi Romain,

You are correct that this is possible. `ApplicationPreferences` wraps around the apis used by Android and iOS.Here is some sample code to help you out.

 

  // Example value: "1111111111"
  string purposeConsents = ApplicationPreferences.GetString("IABTCF_PurposeConsents");
  // Purposes are zero-indexed. Index 0 contains information about Purpose 1.
  if (!string.IsNullOrEmpty(purposeConsents))
  {
    char purposeOneString = purposeConsents[0];
    boolean hasConsentForPurposeOne = purposeOneString == '1';
  }
 

 

Hope this helps,

Nick



ref:!00D1U01174p.!5004Q02rW1aI:ref

Romain Bitard

unread,
Jan 12, 2024, 8:50:22 AM1/12/24
to Mobile Ads SDK Forum Advisor, google-adm...@googlegroups.com
Hello, Thank you for your response. ApplicationPreferences only have setters not getters. In which version of unity admob sdk is it available ?
image.png


Romain Bitard

unread,
Jan 12, 2024, 3:41:17 PM1/12/24
to Google Mobile Ads SDK Developers
I tried to upgrade admob sdk but it seems to be located elsewhere, do you know what has to be done to get access to GetString method ?

Mobile Ads SDK Forum Advisor

unread,
Jan 16, 2024, 12:17:37 PM1/16/24
to bitard...@gmail.com, google-adm...@googlegroups.com
Hi Romain,


This change is available now on GitHub and will be distributed with the next release.

Romain Bitard

unread,
Jan 16, 2024, 12:23:58 PM1/16/24
to Mobile Ads SDK Forum Advisor, google-adm...@googlegroups.com
Thanks for the reply, that's what I saw too

Peter Gambell

unread,
Jan 16, 2024, 6:56:04 PM1/16/24
to Google Mobile Ads SDK Developers
Hi Mobile Ads SDK team,

Will the next release of the Google Mobile Ads Unity plugin be soon? I'm keen to update to get this change to the ApplicationPreferences.

Mobile Ads SDK Forum Advisor

unread,
Jan 16, 2024, 7:31:09 PM1/16/24
to peter....@gmail.com, google-adm...@googlegroups.com
Hi Peter,


I do not have an exact release date, but we are at work for our next release and hope to deliver it soon.

Thanks,

Nathan McKean

unread,
Jul 14, 2024, 9:32:53 PM7/14/24
to Google Mobile Ads SDK Developers
Can you confirm if ApplicationPreferences.GetString("IABTCF_PUrposeConsents"); is now supposed to be returning a value for Unity in C# because I keep getting a null response and would prefer to know if it is fruitless trying to fix my problem. (I am querying from the Unity Editor on a PC to test the implementation).

Mobile Ads SDK Forum Advisor

unread,
Jul 15, 2024, 1:43:37 PM7/15/24
to nathan...@gmail.com, google-adm...@googlegroups.com
Hi Nathan,

I can confirm this issue was fixed in version 9.0.0 of the Google mobile ads SDK for Unity.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rW1aI:ref" (ADR-00218729)

Thanks,
 
Google Logo
Nicholas Ventimiglia
Mobile Ads SDK Team


Peter Gambell

unread,
Jul 30, 2024, 9:04:53 AM7/30/24
to Google Mobile Ads SDK Developers
Are there any plans to add a default value parameter to the ApplicationPreferences.GetString and  ApplicationPreferences.GetInt methods so that we can tell if there is no value set for these keys?
Or adding another method that we can call to see if the key value exists? e.g. ApplicationPreferences.HasKey(string key) which returns a boolean

Mobile Ads SDK Forum Advisor

unread,
Jul 30, 2024, 2:07:11 PM7/30/24
to peter....@gmail.com, google-adm...@googlegroups.com
Hi Peter,

I will bring up the request to extend the API. As a work around, have you tried using `String.IsNullOrEmpty()` on the result?

Peter Gambell

unread,
Jul 30, 2024, 9:48:03 PM7/30/24
to Google Mobile Ads SDK Developers
I haven't tried that, but I suspect it will work for the GetString method's returned value. It's more the GetInt method that is an issue, as e.g. ApplicationPreferences.GetInt("IABTCF_gdprApplies") will return 0 if GDPR does not apply, but I think also returns 0 if the key isn't set.
Reply all
Reply to author
Forward
0 new messages