Я использовал Admob для демонстрации рекламы в течение многих лет в моих приложениях. В какой -то момент мне пришлось добавить новый диалоговое окно согласия GDPR, чтобы его можно было использовать в соответствии с новыми правилами EU, и Admob SDK автоматически использует свои результаты. Sdk.
Проблема
Недавно я добавил поддержку посредничества, чтобы включить различные рекламные исходные данные, чтобы иметь некоторую конкуренцию между ними:
https://developers.google.com/admob/and ... etworks:/p> radmob/admob/Android/Choose-networks>
Для большинства рекламных источников говорится, что для передачи данных о том, принял ли пользователь или нет, в код SDK. (COPPA):
https://developers.google.com/admob/and ... ab-support
Я не могу найти то, что мне нужно, чтобы использовать для них, а не GDPR для различных AD-NetWorks, а также не правила New Us. (и, вероятно, тоже mintegral) не проверяет часть SDK. />[*]https://stackoverflow.com/a/68310602/878126
Например, я создал это:
Код: Выделить всё
@WorkerThread
fun isGDPR(context: Context): Boolean? {
val prefs = PreferenceUtil.getDefaultSharedPreferences(context)
val gdpr =
if (prefs.contains("IABTCF_gdprApplies"))
prefs.getInt("IABTCF_gdprApplies", 0)
else return null
return gdpr == 1
}
@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))
}
}
< /code>
, а также это: < /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
}
}
< /code>
Но я думаю, что я могу использовать их только для обнаружения для Admob (потому что «755»-это адвокат, как показано здесь, но есть и другие, и, возможно, у них есть другие правила) или просто принятие всех, а не специально для различных рекламных источников. Также это только для GDPR, а не из нас правил. Кажется, что когда iAbtcf_gdprapplies Что касается правил США, я вижу, что »
Код: Выделить всё
IABGPP_GppSIDhttps://developers.google.com/admob/and ... ent-moices , но я не понимаю, как я не понимаю, что я не понимаю, что я не понимаю, что я не понимаю, что я не понимаю, что я не понимаю. «Не продавайте и не делитесь моими данными», я добавляю их в SharedPreferences по умолчанию: < /p>
7
DBABL~BVQVAAAAAg
< /code>
Когда я решаю разрешить делиться, он меняет значение «iabgpp_hdr_gppstring» на «dbabl ~ bvqqaaaag», так что это разница в одной букве, от «v» (не делитесь) до «q» (разрешение на обмен). И это все, или, может быть, мне нужно вместо этого проверить один символ или бить.fun isDataShareAllowed(context: Context): Boolean {
val defaultSharedPreferences = PreferenceUtil.getDefaultSharedPreferences(context)
val gppString = defaultSharedPreferences.getString("IABGPP_HDR_GppString", null) ?: return true
// DBABL~BVQVAAAAAg - don't share
// DBABL~BVQqAAAAAg - allow share
return gppString == "DBABL~BVQqAAAAAg"
}
< /code>
Вопросы < /h2>
Учитывая какие-либо рекламные источники x из списка поддерживаемых рекламных источников Admob Medaition, можно ли использовать одну из функций, которые я упоминал выше для GDPR? Должен ли я просто изменить для них «755» на основе веб -сайта? Что я должен сделать для компаний, которые нет в списке на веб -сайте? < /P>
< /li>
Что мне делать с правилами США? Можно ли просто сравниться с одной из струн, как и я? Или я должен заставить его работать по -разному, например, проверка одной буквы или выполнение специальной бить?>
Подробнее здесь: https://stackoverflow.com/questions/793 ... ices-got-f
Мобильная версия