ConsentManager.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using GoogleMobileAds.Ump.Api;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. namespace James.Base
  8. {
  9. public static class ConsentManager
  10. {
  11. public static bool CanRequestAds => ConsentInformation.CanRequestAds();
  12. public static bool CanShowPrivacyButton => ConsentInformation.PrivacyOptionsRequirementStatus ==
  13. PrivacyOptionsRequirementStatus.Required;
  14. // private static Button _privacyButton;
  15. // public static Button PrivacyButton
  16. // {
  17. // set
  18. // {
  19. // _privacyButton = value;
  20. // UpdatePrivacyButton();
  21. // }
  22. // }
  23. public static void GatherConsent(Action<string> onComplete)
  24. {
  25. // Debug.Log("Gathering consent.");
  26. var requestParameters = new ConsentRequestParameters
  27. {
  28. // False means users are not under age.
  29. TagForUnderAgeOfConsent = false,
  30. // ConsentDebugSettings = new ConsentDebugSettings
  31. // {
  32. // // For debugging consent settings by geography.
  33. // DebugGeography = DebugGeography.EEA,
  34. // // https://developers.google.com/admob/unity/test-ads
  35. // TestDeviceHashedIds = GoogleMobileAdsController.TestDeviceIds,
  36. // }
  37. };
  38. // The Google Mobile Ads SDK provides the User Messaging Platform (Google's
  39. // IAB Certified consent management platform) as one solution to capture
  40. // consent for users in GDPR impacted countries. This is an example and
  41. // you can choose another consent management platform to capture consent.
  42. ConsentInformation.Update(requestParameters, updateError =>
  43. {
  44. // Enable the change privacy settings button.
  45. UpdatePrivacyButton();
  46. if (updateError != null)
  47. {
  48. onComplete?.Invoke(updateError.Message);
  49. return;
  50. }
  51. // Determine the consent-related action to take based on the ConsentStatus.
  52. if (CanRequestAds)
  53. {
  54. // Consent has already been gathered or not required.
  55. // Return control back to the user.
  56. onComplete?.Invoke(null);
  57. return;
  58. }
  59. // Consent not obtained and is required.
  60. // Load the initial consent request form for the user.
  61. ConsentForm.LoadAndShowConsentFormIfRequired(showError =>
  62. {
  63. UpdatePrivacyButton();
  64. onComplete?.Invoke(showError?.Message);
  65. });
  66. });
  67. }
  68. /// <summary>
  69. /// Shows the privacy options form to the user.
  70. /// </summary>
  71. /// <remarks>
  72. /// Your app needs to allow the user to change their consent status at any time.
  73. /// Load another form and store it to allow the user to change their consent status
  74. /// </remarks>
  75. public static void ShowPrivacyOptionsForm(Action<string> onComplete)
  76. {
  77. // Debug.Log("Showing privacy options form.");
  78. ConsentForm.ShowPrivacyOptionsForm(showError =>
  79. {
  80. UpdatePrivacyButton();
  81. onComplete?.Invoke(showError?.Message);
  82. });
  83. }
  84. private static void UpdatePrivacyButton()
  85. {
  86. // if (_privacyButton != null)
  87. // {
  88. // _privacyButton.interactable =
  89. // ConsentInformation.PrivacyOptionsRequirementStatus ==
  90. // PrivacyOptionsRequirementStatus.Required;
  91. // }
  92. }
  93. }
  94. }