Zapoznaj się z Przewodnikami Google dla programistów dotyczącymi pakietów SDK:
Funkcje pakietu SDK trybu uzyskiwania zgody Google
Ogólne wymagania dotyczące pakietu SDK i jego implementacji znajdziesz w przewodnikach na początku tego dokumentu. Jeśli masz włączoną obsługę trybu uzyskiwania zgody w sekcji Prywatność i przesyłanie wiadomości, możesz też zaimplementować dodatkowe funkcje opisane w tym dokumencie.
Tryb uzyskiwania zgody: obsługa trybu podstawowego
Gdy zaimplementujesz odpowiedni pakiet SDK, włączysz tryb uzyskiwania zgody Google w sekcji Prywatność i przesyłanie wiadomości, oraz stwierdzisz, że chcesz zaimplementować podstawowy tryb uzyskiwania zgody, postępuj zgodnie z tymi instrukcjami.
Aby zaimplementować tryb podstawowy:
- Tymczasowo wyłącz zbieranie danych Analytics (Android, iOS).
- Gdy będziesz gotowy(-a) do odblokowania funkcji Google Analytics, ponownie włącz zbieranie danych Analytics (Android, iOS).
W przypadku kroku 2 skonsultuj się z prawnikiem, aby określić kryteria ponownego włączenia funkcji Analytics.
Możesz na przykład ponownie włączyć funkcje Google Analytics, gdy użytkownik wyrazi zgodę, ponownie włączając funkcje Google Analytics w wywołaniu zwrotnym loadAndShowConsentFormIfRequired (dokumentacja API: Android, iOS).
Możesz też odczytać klucz pamięci lokalnej UMP_consentModeValues, aby określić, czy ponownie włączyć zbieranie danych Analytics na podstawie wyborów użytkownika dotyczących trybu uzyskiwania zgody. Wartość to 4-cyfrowy ciąg znaków.
- Pierwsza cyfra wskazuje wartość celu ad_storage.
- Druga cyfra wskazuje wartość celu ad_user_data.
- Trzecia cyfra wskazuje wartość celu ad_personalization.
- Czwarta cyfra wskazuje wartość celu analytics_storage.
W tabeli poniżej opisano możliwe wartości każdej cyfry:
| Wartość | Znaczenie |
|---|---|
0 |
Wartość nie jest jeszcze dostępna. |
1 |
Użytkownik GRANTED na ten cel. |
2 |
Użytkownik DENIED ten cel. |
3 |
Tryb uzyskiwania zgody nie ma zastosowania do tego użytkownika. |
4 |
Tryb uzyskiwania zgody nie jest skonfigurowany dla tego celu. |
Poniższy przykład analizuje UMP_consentModeValues, włącza Google Analytics
jeśli wszystkie cele są GRANTED lub nie mają zastosowania, a w przeciwnym razie wyłącza zbieranie danych 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;
}
Wywołaj maybeReEnableAnalyticsCollection, gdy:
- informacje o zgodzie zostaną zaktualizowane,
- zgoda zostanie uzyskana.