Zapoznaj się z przewodnikiem dla deweloperów Google dotyczącym pakietów SDK:
Funkcje pakietu SDK trybu uzyskiwania zgody Google
Informacje o ogólnych wymaganiach i implementacji pakietu SDK znajdziesz w przewodnikach na początku tego dokumentu. Jeśli masz włączone obsługiwanie trybu zgody w narzędziu Prywatność i wyświetlanie wiadomości, możesz też zaimplementować dodatkowe funkcje opisane w tym artykule.
Tryb uzyskiwania zgody: obsługa trybu podstawowego
Po zaimplementowaniu odpowiedniego pakietu SDK, włączeniu trybu uzyskiwania zgody Google w sekcji Prywatność i wiadomości oraz podjęciu decyzji o wdrożeniu podstawowego trybu uzyskiwania zgody postępuj zgodnie z tymi instrukcjami.
Aby wdrożyć tryb podstawowy:
- tymczasowo wyłączyć zbieranie danych przez Analytics (Android, iOS);
- Gdy będziesz gotowy/gotowa do odblokowania funkcji Google Analytics, ponownie włącz zbieranie danych Analytics (Android, iOS).
W kroku 2 skonsultuj się z prawnikiem, aby ustalić kryteria ponownego włączenia funkcji Analytics.
Możesz na przykład ponownie włączyć funkcję Google Analytics po tym, jak użytkownik wyraził zgodę, ponownie włączając ją w wywołaniu zwrotnym loadAndShowConsentFormIfRequired
(dokumentacja interfejsu API: Android, iOS).
Aby określić, czy ponownie włączyć zbieranie danych Analytics na podstawie wyborów użytkownika w trybie uzyskiwania zgody, przeczytaj artykuł o kluczu UMP_consentModeValues
„local storage”. Wartość jest 4-cyfrowym ciągiem znaków.
- Pierwsza cyfra wskazuje wartość parametru ad_storage purpose
- Druga cyfra wskazuje wartość parametru ad_user_data, która określa cel.
- Trzecia cyfra wskazuje wartość parametru ad_personalization purpose.
- Czwarta cyfra wskazuje wartość parametru analytics_storage.
W tabeli poniżej opisano możliwe wartości poszczególnych cyfr:
Wartość | Znaczenie |
---|---|
0 |
Nie ma jeszcze żadnej wartości. |
1 |
Użytkownik GRANTED ten cel. |
2 |
Użytkownik DENIED ten cel. |
3 |
Tryb uzyskiwania zgody nie ma zastosowania w przypadku tego użytkownika. |
4 |
Tryb uzyskiwania zgody nie jest skonfigurowany do tego celu. |
W tym przykładzie funkcja UMP_consentModeValues
jest analizowana, a Google Analytics jest włączana, jeśli wszystkie cele są GRANTED
lub nie mają zastosowania, a w przeciwnym razie jest wyłączana:
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;
}
Zadzwoń do maybeReEnableAnalyticsCollection
, gdy:
- zaktualizowano informacje o zgodzie użytkownika.
- zgoda użytkownika.