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

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


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

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

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

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

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

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

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

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

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

ערך משמעות
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 במקרים הבאים:

  • פרטי ההסכמה מתעדכנים
  • מתקבלת הסכמה.