حِزم تطوير البرامج (SDK) الخاصة بحلول إدارة الموافقة من Google

اطّلِع على أدلة المطوّرين من Google لحِزم تطوير البرامج (SDK):

  • تطبيقات AdMob (لنظامَي التشغيل Android وiOS)
  • تطبيقات "مدير إعلانات Google" (Android iOS)

راجِع الأدلة في بداية هذا المستند لمعرفة متطلبات حزمة تطوير البرامج (SDK) العامة وكيفية تنفيذها. إذا فعّلت ميزة "وضع الموافقة" في صفحة "الخصوصية والمراسلة"، قد تحتاج أيضًا إلى تنفيذ الوظائف الإضافية التي تتم مناقشتها هنا.

بعد تنفيذ حزمة تطوير البرامج (SDK) ذات الصلة، فعِّل "وضع الموافقة من Google" في "الخصوصية والمراسلة"، وقرّر تنفيذ وضع الموافقة الأساسي، اتّبِع التعليمات التالية.

لتنفيذ الوضع الأساسي:

  1. أوقِف مؤقتًا جمع البيانات في "إحصاءات Google" (Android وiOS).
  2. عندما تكون مستعدًا لإلغاء حظر وظائف "إحصاءات Google"، أعِد تفعيل عملية جمع البيانات في "إحصاءات Google" (Android وiOS).

بالنسبة إلى الخطوة 2، يمكنك استشارة خبير قانوني لتحديد معايير إعادة تفعيل وظائف "إحصاءات Google".

على سبيل المثال، يمكنك إعادة تفعيل وظائف "إحصاءات Google" بعد أن يحدد المستخدِم خيار الموافقة من خلال إعادة تفعيل وظائف "إحصاءات Google" في loadAndShowConsentFormIfRequired callback (مرجع واجهة برمجة التطبيقات: Android، iOS).

بدلاً من ذلك، لتحديد ما إذا كان يجب إعادة تفعيل جمع البيانات في "إحصاءات Google" استنادًا إلى خيارات وضع الموافقة للمستخدِم، يمكنك قراءة مفتاح UMP_consentModeValues التخزين على الجهاز. القيمة هي سلسلة من أربعة أرقام.

  • يشير الرقم الأول إلى قيمة الغرض من ad_storage
  • يشير الرقم الثاني إلى قيمة الغرض من ad_user_data.
  • يشير الرقم الثالث إلى قيمة الغرض من ad_personalization.
  • يشير الرقم الرابع إلى قيمة الغرض من analytics_storage

يوضّح الجدول التالي القيم المحتملة لكل رقم:

القيمة المعنى
0 لا تتوفّر أي قيمة حتى الآن.
1 GRANTED المستخدِم هذا الغرض.
2 DENIED المستخدِم هذا الغرض.
3 لا ينطبق "وضع الموافقة" على هذا المستخدم.
4 لم يتم ضبط "وضع الموافقة" لهذا الغرض.

يحلّل المثال التالي UMP_consentModeValues، ويفعّل "إحصاءات Google" إذا كانت جميع الأغراض هي GRANTED أو لا تنطبق، ويوقف جمع البيانات في "إحصاءات Google" بخلاف ذلك:

Java

// 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;
}

Kotlin

// 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
}

Swift

// 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
}

Objective-C

// 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 في الحالات التالية:

  • تم تعديل معلومات الموافقة
  • يتم جمع الموافقة.