ดูคู่มือนักพัฒนาแอปของ Google สำหรับ SDK ได้ที่
ฟังก์ชันการทำงานของ SDK โหมดความยินยอมของ Google
โปรดดูคำแนะนำที่ส่วนต้นของเอกสารนี้เพื่อดูข้อกำหนดโดยรวมของ SDK และการใช้งาน หากเปิดใช้การรองรับโหมดความยินยอมของความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้แล้ว คุณอาจต้องใช้ฟังก์ชันเพิ่มเติมที่อธิบายไว้ ที่นี่ด้วย
โหมดความยินยอม: การรองรับโหมดพื้นฐาน
เมื่อติดตั้งใช้งาน SDK ที่เกี่ยวข้องแล้ว เปิดใช้โหมดความยินยอมของ Google ในความเป็นส่วนตัวและการแสดงข้อความ และพิจารณาแล้วว่าจะใช้โหมดความยินยอมพื้นฐาน ให้ทำตามวิธีการต่อไปนี้
วิธีใช้โหมดพื้นฐาน
- ปิดใช้การเก็บข้อมูล Analytics ชั่วคราว (Android, iOS)
- เมื่อพร้อมที่จะเลิกบล็อกฟังก์ชันการทํางานของ Google Analytics แล้ว ให้เปิดใช้การรวบรวมข้อมูล Analytics อีกครั้ง (Android, iOS)
สําหรับขั้นตอนที่ 2 โปรดปรึกษาผู้เชี่ยวชาญด้านกฎหมายเพื่อกําหนดเกณฑ์สําหรับ การเปิดใช้ฟังก์ชัน Analytics อีกครั้ง
เช่น คุณสามารถเปิดใช้ฟังก์ชัน Google Analytics อีกครั้งหลังจากที่ผู้ใช้เลือกให้ความยินยอมโดยการเปิดใช้ฟังก์ชัน Google Analytics อีกครั้งในการเรียกกลับของ loadAndShowConsentFormIfRequired (เอกสารอ้างอิง API: Android, iOS)
หรือหากต้องการพิจารณาว่าจะเปิดใช้การเก็บรวบรวมข้อมูล Analytics อีกครั้งหรือไม่ตามตัวเลือกโหมดความยินยอมของผู้ใช้ ให้อ่านคีย์UMP_consentModeValuesพื้นที่เก็บข้อมูลในเครื่อง ค่านี้เป็นสตริง 4 หลัก
- ตัวเลขแรกระบุค่าวัตถุประสงค์ของ ad_storage
- ตัวเลขที่ 2 แสดงค่าวัตถุประสงค์ของ ad_user_data
- ตัวเลขที่ 3 แสดงค่าวัตถุประสงค์ของ ad_personalization
- ตัวเลขหลักที่ 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 เมื่อ
- อัปเดตข้อมูลความยินยอม
- รวบรวมความยินยอม