برای SDK ها به راهنمای توسعه دهندگان گوگل مراجعه کنید:
عملکرد SDK حالت رضایت گوگل
برای الزامات کلی و پیادهسازی SDK، به راهنماهای ابتدای این سند مراجعه کنید. اگر پشتیبانی از حالت رضایت در بخش حریم خصوصی و پیامرسانی را فعال کردهاید، ممکن است بخواهید قابلیتهای اضافی پوشش داده شده در اینجا را نیز پیادهسازی کنید.
حالت رضایت: پشتیبانی از حالت پایه
پس از پیادهسازی SDK مربوطه، فعال کردن حالت رضایت گوگل در بخش حریم خصوصی و پیامرسانی و تصمیم به پیادهسازی حالت رضایت پایه ، این دستورالعملها را دنبال کنید.
برای پیادهسازی حالت پایه:
- غیرفعال کردن موقت مجموعه آنالیتیکس ( اندروید ، iOS ).
- وقتی آماده رفع انسداد عملکرد گوگل آنالیتیکس شدید، مجموعه آنالیتیکس ( اندروید ، iOS ) را دوباره فعال کنید.
برای مرحله ۲، با یک متخصص حقوقی مشورت کنید تا معیارهای شما برای فعالسازی مجدد قابلیت آنالیتیکس مشخص شود.
برای مثال، میتوانید پس از اینکه کاربر رضایت خود را اعلام کرد، با فعال کردن مجدد قابلیت گوگل آنالیتیکس در فراخوانی تابع loadAndShowConsentFormIfRequired (مرجع API: اندروید ، iOS )، قابلیت گوگل آنالیتیکس را دوباره فعال کنید.
روش دیگر، برای تعیین اینکه آیا بر اساس انتخابهای حالت رضایت کاربر، مجموعه Analytics دوباره فعال شود یا خیر، کلید ذخیرهسازی محلی UMP_consentModeValues را بخوانید. این مقدار یک رشته چهار رقمی است.
- رقم اول مقدار هدف ad_storage را نشان میدهد
- رقم دوم مقدار هدف ad_user_data را نشان میدهد.
- رقم سوم مقدار هدف ad_personalization را نشان میدهد.
- رقم چهارم مقدار هدف analytics_storage را نشان میدهد.
جدول زیر مقادیر ممکن برای هر رقم را شرح میدهد:
| ارزش | معنی |
|---|---|
0 | هنوز هیچ ارزشی در دسترس نیست. |
1 | کاربر این هدف را GRANTED . |
2 | کاربر این هدف را DENIED . |
3 | حالت رضایت برای این کاربر اعمال نمیشود. |
4 | حالت رضایت برای این منظور پیکربندی نشده است. |
مثال زیر UMP_consentModeValues را تجزیه میکند، در صورتی که همه اهداف GRANTED باشند یا اعمال نشوند، Google Analytics را فعال میکند و در غیر این صورت مجموعه Analytics را غیرفعال میکند:
جاوا
// Helper function that sets Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private void maybeReEnableAnalyticsCollection() {
String consentModeValues = sharedPreferences.getString("UMP_consentModeValues", null);
if (shouldReEnableAnalyticsCollection(consentModeValues)) {
firebaseAnalytics.setAnalyticsCollectionEnabled(true);
} else {
firebaseAnalytics.setAnalyticsCollectionEnabled(false);
}
}
// Helper function to determine whether Analytics collection should be enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private boolean shouldReEnableAnalyticsCollection(String consentModeValues) {
if (consentModeValues.isEmpty()) {
return false;
}
for (int i = 0; i < consentModeValues.length(); i++) {
char consentModeValue = consentModeValues.charAt(i);
switch (consentModeValue) {
case '0':
// Consent mode data not ready yet.
return false;
case 1:
// Consent mode is granted for this purpose.
break;
case '2':
// Consent is denied for this consent mode purpose.
return false;
case '3':
// Consent does not apply for this purpose at this time.
break;
case '4':
// Consent mode is not configured for this purpose.
break;
default:
// Unexpected value encountered.
return false;
}
}
// If all checks pass, re-enable Analytics collection.
return true;
}
کاتلین
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private fun maybeReEnableAnalyticsCollection() {
val consentModeValues = sharedPreferences.getString("UMP_consentModeValues", null)
if (shouldReEnableAnalyticsCollection(consentModeValues)) {
firebaseAnalytics.setAnalyticsCollectionEnabled(true)
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private fun shouldReEnableAnalyticsCollection(consentModeValues: String?): Boolean {
if (consentModeValues.isNullOrEmpty()) {
return false
}
for (consentModeValue in consentModeValues) {
when (consentModeValue) {
'0' -> {
// Consent mode data not ready yet.
return false
}
'1' -> {
// Consent mode is granted for this purpose.
}
'2' -> {
// Consent is denied for this consent mode purpose.
return false
}
'3' -> {
// Consent does not apply for this purpose at this time.
}
'4' -> {
// Consent mode is not configured for this purpose.
}
else -> {
// Unexpected value encountered.
return false
}
}
}
// If all checks pass, can re-enable Analytics collection.
return true
}
سویفت
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private func maybeReEnableAnalyticsCollection() {
let consentModeValues = userDefaults.string(forKey: "UMP_consentModeValues")
if shouldReEnableAnalyticsCollection(consentModeValues) {
Analytics.setAnalyticsCollectionEnabled(true)
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private func shouldReEnableAnalyticsCollection(_ consentModeValues: String?) -> Bool {
guard let consentModeValues = consentModeValues, !consentModeValues.isEmpty else {
return false
}
for consentModeValue in consentModeValues {
switch consentModeValue {
case "0":
// Consent mode data not ready yet.
return false
case "1":
// Consent mode is granted for this purpose.
break
case "2":
// Consent is denied for this consent mode purpose.
return false
case "3":
// Consent does not apply for this purpose at this time.
break
case "4":
// Consent mode is not configured for this purpose.
break
default:
// Unexpected value encountered.
return false
}
}
// If all checks pass, can re-enable Analytics collection.
return true
}
هدف-سی
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
- (void)maybeReEnableAnalyticsCollection {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *consentModeValues = [defaults stringForKey:@"UMP_consentModeValues"];
if ([self shouldReEnableAnalyticsCollection:consentModeValues]) {
[FIRAnalytics setAnalyticsCollectionEnabled:YES];
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
- (BOOL)shouldReEnableAnalyticsCollection:(NSString *)consentModeValues {
if (!consentModeValues || [consentModeValues length] == 0) {
return NO;
}
for (NSUInteger i = 0; i < [consentModeValues length]; i++) {
unichar consentModeValue = [consentModeValues characterAtIndex:i];
switch (consentModeValue) {
case '0':
// Consent mode data not ready yet.
return NO;
case '1':
// Consent mode is granted for this purpose.
break;
case '2':
// Consent is denied for this consent mode purpose.
return NO;
case '3':
// Consent does not apply for this purpose at this time.
break;
case '4':
// Consent mode is not configured for this purpose.
break;
default:
// Unexpected value encountered.
return NO;
}
}
// If all checks pass, can re-enable Analytics collection.
return YES;
}
تابع maybeReEnableAnalyticsCollection را زمانی فراخوانی کنید که:
- اطلاعات رضایتنامه بهروزرسانی میشود
- رضایت جمع آوری شده است.