Google の同意管理ソリューション SDK

以下の SDK の Google デベロッパー ガイドをご覧ください。


SDK の全体的な要件と実装については、このドキュメントの冒頭にあるガイドを参照してください。[プライバシーとメッセージ] の同意モードのサポートを有効にしている場合は、ここで説明する追加機能を実装することもできます。

関連する SDK を実装し、[プライバシーとメッセージ] で Google 同意モードを有効にして、基本的な同意モードを実装することを決定したら、次の手順を行います。

基本モードを実装するには:

  1. アナリティクスのデータ収集を一時的に無効にする(AndroidiOS)。
  2. Google アナリティクスの機能をブロック解除する準備ができたら、アナリティクスのデータ収集を再度有効にします(AndroidiOS)。

ステップ 2 では、アナリティクス機能を再度有効にする条件を決定するため、法律の専門家に相談してください。

たとえば、ユーザーが同意を選択した後で Google アナリティクスの機能を再度有効にするには、loadAndShowConsentFormIfRequired のコールバックで Google アナリティクスの機能を再度有効にします(API リファレンス: AndroidiOS)。

または、ユーザーの同意モードの選択に基づいてアナリティクスの収集を再度有効にするかどうかを判断するには、UMP_consentModeValues ローカル ストレージ キーを読み取ります。値は 4 桁の文字列です。

  • 最初の桁は、ad_storage の目的の値を示します。
  • 2 桁目は ad_user_data の目的の値を示します。
  • 3 桁目は、ad_personalization の目的の値を示します。
  • 4 桁目は analytics_storage の目的の値を示します。

次の表に、各桁の有効な値を示します。

意味
0 まだ値は利用できません。
1 ユーザーがこの目的を GRANTED しています。
2 ユーザーがこの目的を DENIED しています。
3 このユーザーには同意モードは適用されません。
4 同意モードは、この目的のために設定されていません。

次の例では、UMP_consentModeValues を解析し、すべての目的が GRANTED であるか適用されない場合は Google アナリティクスを有効にし、それ以外の場合はアナリティクスの収集を無効にします。

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 は、次のような場合に呼び出します。

  • 同意情報が更新された
  • 同意が得られるまで