ערכות SDK של פתרונות לניהול הסכמה של Google

כדאי לעיין במדריכים למפתחים של Google בנושא ערכות ה-SDK:


מומלץ לעיין במדריכים שבתחילת המסמך הזה כדי לקבל מידע על הדרישות הכלליות של ה-SDK ועל ההטמעה שלו. אם הפעלתם את התמיכה בסטטוס הסכמה בכלי 'פרטיות והודעות', כדאי לכם להטמיע גם את הפונקציונליות הנוספת שמפורטת כאן.

אחרי שמטמיעים את ה-SDK הרלוונטי, מפעילים את סטטוס ההסכמה של Google בכלי 'פרטיות והודעות' ומחליטים להטמיע סטטוס הסכמה בסיסי, פועלים לפי ההוראות הבאות.

כדי להטמיע את המצב הבסיסי:

  1. השבתה זמנית של איסוף הנתונים ב-Analytics‏ (Android, ‏ iOS).
  2. כשמוכנים לבטל את החסימה של הפונקציונליות של Google Analytics, צריך להפעיל מחדש את איסוף הנתונים ב-Analytics ‏ (Android, ‏ iOS).

בשלב 2, כדאי להתייעץ עם מומחה משפטי כדי לקבוע את הקריטריונים להפעלה מחדש של הפונקציונליות של Analytics.

לדוגמה, אפשר להפעיל מחדש את הפונקציונליות של Google Analytics אחרי שהמשתמש בחר את ההסכמה שלו, על ידי הפעלה מחדש של הפונקציונליות של Google Analytics בקריאה החוזרת של loadAndShowConsentFormIfRequired (הפניה ל-API:‏ Android,‏ iOS).

לחלופין, כדי לקבוע אם להפעיל מחדש את איסוף הנתונים ב-Analytics על סמך הבחירות של המשתמש בסטטוס ההסכמה, אפשר לקרוא את המפתח UMP_consentModeValuesבזיכרון המקומי. הערך הוא מחרוזת בת 4 ספרות.

  • הספרה הראשונה מציינת את ערך היעד של ad_storage
  • הספרה השנייה מציינת את ערך המטרה של הפרמטר ad_user_data
  • הספרה השלישית מציינת את ערך המטרה של התאמה אישית של מודעות
  • הספרה הרביעית מציינת את ערך המטרה של analytics_storage

בטבלה הבאה מתוארים הערכים האפשריים של כל ספרה:

ערך משמעות
0 עדיין אין ערך זמין.
1 המשתמש GRANTED את המטרה הזו.
2 המשתמש DENIED את המטרה הזו.
3 סטטוס ההסכמה לא חל על המשתמש הזה.
4 סטטוס ההסכמה לא מוגדר למטרה הזו.

בדוגמה הבאה מתבצע ניתוח של UMP_consentModeValues, מופעל Google Analytics אם כל המטרות הן GRANTED או לא רלוונטיות, ומושבת איסוף הנתונים של Analytics במקרים אחרים:

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 כאשר:

  • פרטי ההסכמה מתעדכנים
  • הסכמה נאספת.