Я уже много лет использую AdMob для показа рекламы в своих приложениях. В какой-то момент мне пришлось добавить новый диалог согласия GDPR, чтобы его можно было использовать в соответствии с новыми правилами ЕС, и Admob SDK автоматически использовал его результаты.
https://developers. google.com/admob/android/privacy
Это сработало нормально, поскольку я использовал SDK от Google, а Google уже владеет Admob для использования этого SDK.
Проблема
Недавно я добавил поддержку посредничества, чтобы включить различные источники рекламы, чтобы между ними была конкуренция:
https://developers.google.com/admob /android/choose-networks
К сожалению, в отличие от Admob, очень немногие источники рекламы автоматически извлекают выгоду из того, что выбрал пользователь. На самом деле я нашел лишь очень немногие, которые это делают: AppLovin и, возможно, также Mintegral (требуется дополнительный код перед инициализацией, но это все).
Для большинства источников рекламы это говорит, что нужно передавать в SDK данные о том, принял ли пользователь или нет, в коде.
Не только это, но в дополнение к правилам GDPR, есть новые для Сами США:
https://developers.google.com/admob/and ... ab-support
Дело в том, что я не могу найти, какое значение я для них нужно установить не GDPR для различных рекламных сетей, а также не новое правило США.
Даже Applovin (и, возможно, Mintegral тоже) не проверяет США часть SDK.
Что я нашел
Раньше, просто для того, чтобы аналитика могла увидеть ситуацию, я использовал следующее: Например, я создал это:
Код: Выделить всё
@WorkerThread
fun canShowPersonalizedAds(context: Context): Boolean {
val prefs = PreferenceUtil.getDefaultSharedPreferences(context)
//https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#in-app-details
//https://support.google.com/admob/answer/9760862?hl=en&ref_topic=9756841
val purposeConsent = prefs.getString("IABTCF_PurposeConsents", "") ?: ""
val vendorConsent = prefs.getString("IABTCF_VendorConsents", "") ?: ""
val vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests", "") ?: ""
val purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests", "") ?: ""
val googleId = 755
val hasGoogleVendorConsent = hasAttribute(vendorConsent, index = googleId)
val hasGoogleVendorLI = hasAttribute(vendorLI, index = googleId)
return hasConsentFor(listOf(1, 3, 4), purposeConsent, hasGoogleVendorConsent)
&& hasConsentOrLegitimateInterestFor(listOf(2, 7, 9, 10), purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI)
}
// Check if a binary string has a "1" at position "index" (1-based)
private fun hasAttribute(input: String, index: Int): Boolean {
return input.length >= index && input[index - 1] == '1'
}
// Check if consent is given for a list of purposes
private fun hasConsentFor(purposes: List, purposeConsent: String, hasVendorConsent: Boolean): Boolean {
return purposes.all { p -> hasAttribute(purposeConsent, p) } && hasVendorConsent
}
// Check if a vendor either has consent or legitimate interest for a list of purposes
private fun hasConsentOrLegitimateInterestFor(purposes: List, purposeConsent: String, purposeLI: String, hasVendorConsent: Boolean, hasVendorLI: Boolean): Boolean {
return purposes.all { p ->
(hasVendorLI && hasAttribute(purposeLI, p)) ||
(hasVendorConsent && hasAttribute(purposeConsent, p))
}
}
Код: Выделить всё
/**
* Checks the stored IABTCF configuration and returns one of the values defined in [AdConfiguration],
* based on the necessary minimum consent/interest defined here: https://support.google.com/admob/answer/9760862
*/
fun detectAdConfiguration(context: Context): AdConfiguration {
// default string for "no consent", used in cases where no configuration has previously been stored
val defaultPurposeString = "0000000000"
// IABTCF strings are stored in SharedPreferences
val sharedPrefs = PreferenceUtil.getDefaultSharedPreferences(context)
// https://developers.google.com/admob/android/privacy/ad-serving-modes
//limited ads: nothing for 1, consent/legitimate: 2,7,9,10
//non personalized ads: Consent: 1 , consent/legitimate: 2,7,9,10
//personalized: consent: 1,3,4 consent/legitimate: 2,7,9,10
//
// relevant strings are those for purpose consent or legitimate interest, as well as vendors
val tcConsentString = sharedPrefs
.getString("IABTCF_PurposeConsents", defaultPurposeString) ?: defaultPurposeString
val tcInterestString = sharedPrefs
.getString("IABTCF_PurposeLegitimateInterests", defaultPurposeString)
?: defaultPurposeString
// Log.d("AppLog", "detectAdConfiguration tcConsentString:$tcConsentString tcInterestString:$tcInterestString tcVendorString:$tcVendorString ")
// in any case we need at least legitimate interest for purposes N = 2, 7, 9 and 10,
// stored in positions N-1 of either purpose string:
val sufficientInterest =
(tcConsentString.getOrNull(1) == '1' || tcInterestString.getOrNull(1) == '1') &&
(tcConsentString.getOrNull(6) == '1' || tcInterestString.getOrNull(6) == '1') &&
(tcConsentString.getOrNull(8) == '1' || tcInterestString.getOrNull(8) == '1') &&
(tcConsentString.getOrNull(9) == '1' || tcInterestString.getOrNull(9) == '1')
if (!sufficientInterest) {
return AdConfiguration.None
}
val tcVendorString = sharedPrefs.getString("IABTCF_VendorConsents", "0") ?: "0"
// Log.d("AppLog", "tcVendorString:$tcVendorString")
// TODO vendor configuration is variable, so needs to be defined by the individual developer
// - run app and make sure that a valid configuration is stored
// - have the app log the value of [tcVendorString], then copy that value to the following line
// - repeat if ad configuration changes, perhaps make this value available via remote configuration instead
val goodVendorConfiguration = context.getString(R.string.ad_consent_expected_good_vendor_configuration)
// if the stored string is shorter than what is necessary, at least some vendors will not be
// configured properly.
if (tcVendorString.length < goodVendorConfiguration.length) {
return AdConfiguration.Unclear
}
// we need consent for the following purposes N, stored in positions N-1 of the consent string:
// 1, 3 and 4 to show all ads
// 1 to show non-personalized ads
// no consent to show limited ads
val maxAdDisplayConfiguration = when {
tcConsentString.getOrNull(0) != '1' -> AdConfiguration.Limited
tcConsentString.getOrNull(2) == '1' && tcConsentString.getOrNull(3) == '1' -> AdConfiguration.All
else -> AdConfiguration.NonPersonalized
}
// build a regex that must match all '1' but not the '0' characters in goodVendorConfiguration,
// and allows this configuration to be shorter than the string it is compared with
val vendorRegex = Regex(goodVendorConfiguration.replace("0", ".").plus(".*"))
//if the regex matches, at least some ads should be served; if not, vendor string is unclear
return if (vendorRegex.matches(tcVendorString)) {
maxAdDisplayConfiguration
} else {
return AdConfiguration.Unclear
}
}
Я также пытался обратиться за помощью к Admob и рекламным компаниям, но они просто перекладывают ответственность за это на других. сторона, а я посередине...
Позже я попытался проверить, что происходит в SharedPreferences (используя RegisterOnSharedPreferenceChangeListener). Похоже, что когда ключ IABTCF_gdprApplies указывает на целое число 1, это означает, что на него распространяются правила GDPR.
Что касается правил США, я вижу, что "
Код: Выделить всё
IABGPP_GppSIDКлючи
https://developers.google.com/admob/and ... ab-support #read-consent-choices
Но я не понимаю, как прочитать подробную информацию о них. Я вижу, что если я выберу «Не продавать и не передавать мои данные», я добавляю эти к настройкам SharedPreferences по умолчанию:
Код: Выделить всё
7
DBABL~BVQVAAAAAg
Однако, похоже, в этом есть ошибка, потому что, когда я поменяйте еще раз выбор в диалоге, вроде ничего не меняется...
Вопросы
- Дано любой источник рекламы X из списка поддерживаемых источников рекламы Admob, можно ли использовать один из функции, которые я упомянул выше для GDPR?
- Что мне делать с правилами США, так как я даже не нашел, где можно выбрать сохраняется пользователем? То, что я узнал о странном файле SharedPreferences, кажется ненадежным...
- Если я решу быть строгим, повлияет ли это на все страны в мире или только на тех, на кого распространяются эти правила?
Подробнее здесь: https://stackoverflow.com/questions/793 ... om-googles