حِزم تطوير البرامج (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 (مرجع واجهة برمجة التطبيقات: Android, iOS).

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

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

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

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

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

جافا

// 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 عند:

  • يتم تعديل معلومات الموافقة
  • تم الحصول على الموافقة.