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คีย์พื้นที่เก็บข้อมูลในเครื่อง ค่านี้เป็นสตริง 4 หลัก

  • ตัวเลขแรกระบุค่าวัตถุประสงค์ ad_storage
  • ตัวเลขที่ 2 ระบุค่าวัตถุประสงค์ ad_user_data
  • ตัวเลขที่ 3 ระบุค่า ad_personalization purpose
  • ตัวเลขที่ 4 ระบุค่าวัตถุประสงค์ 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 ในกรณีต่อไปนี้

  • ข้อมูลความยินยอมได้รับการอัปเดต
  • รวบรวมความยินยอม