同意管理
Android Kotlinの同意管理の実装方法を学びます。
使用法
同意管理モジュールは推奨され、初期化時に自動的に有効化されます。AndroidモバイルとAndroid TVでサポートされています。
TealiumConfig内で同意管理ポリシーを初期化します。その後、tealium.consentManagerでTealiumインスタンスを使用してユーザーの同意を管理します。
同意管理と同意ポリシーについて詳しく学びましょう。
同意
ポリシーの構成
初期化時に以下のいずれかの同意ポリシーを構成します:
ConsentPolicy.GDPRConsentPolicy.CCPA
一度に一つのポリシーのみがデバイス上で強制されます。
val config = TealiumConfig(...).apply {
consentManagerPolicy = ConsentPolicy.GDPR
}
同意の有効期限
consentExpiryプロパティを使用して、同意選択の有効期限を構成します。
以下の例では、同意管理ポリシーをGDPRに構成し、有効期限を90日に構成しています:
val config = TealiumConfig(...).apply {
consentManagerPolicy = ConsentPolicy.GDPR
consentExpiry = ConsentExpiry(90, TimeUnit.DAYS)
}
同意が期限切れになったときにコールバックをトリガーするには、onUserConsentPreferencesUpdated()メソッドを使用してConsentStatusがUNKNOWNになったときを確認します:
Tealium.create(BuildConfig.TEALIUM_INSTANCE, config) {
events.subscribe(object : UserConsentPreferencesUpdatedListener {
override fun onUserConsentPreferencesUpdated(userConsentPreferences: UserConsentPreferences,
policy: ConsentManagementPolicy) {
if (userConsentPreferences.consentStatus == ConsentStatus.UNKNOWN) {
Logger.dev(BuildConfig.TAG, "Re-prompt for consent")
}
}
})
}
全面的な同意の構成
全面的な同意を構成するには:
tealium.consentManager.userConsentStatus = ConsentStatus.CONSENTED
全面的な同意を構成すると、暗黙的に同意カテゴリが利用可能なConsentCategoryタイプの全リストに構成されます。
カテゴリ別の部分的な同意の構成
部分的な同意を構成するには、同意カテゴリのサブセットを指定します。これにより、userConsentStatusがCONSENTEDに暗黙的に構成されます。
tealium.consentManager.userConsentCategories = setOf(ConsentCategory.ANALYTICS, ConsentCategory.EMAIL)
同意の拒否の構成
同意を拒否するには、同意ステータスを構成します:
tealium.consentManager.userConsentStatus = ConsentStatus.NOT_CONSENTED
あるいは、同意カテゴリをnullに構成します。
カスタム同意
あなたの組織の同意要件が、私たちの標準的なOpt-inおよびOpt-out同意管理ポリシーに含まれていない場合、カスタム同意ポリシーを作成します。
ConsentManagementPolicyインターフェースを実装します。val customPolicy = object: ConsentManagementPolicy { //implement methods... }setCustomPolicy()メソッドを使用して、ConsentPolicy.CUSTOMenumにConsentManagementPolicyの実装を渡します。ConsentPolicy.CUSTOM.setCustomPolicy(customPolicy)consentManagerPolicyプロパティを介してTealiumConfigオブジェクトにConsentPolicy.CUSTOMオプションを渡します。config.consentManagerPolicy = ConsentPolicy.CUSTOM
カスタムConsentManagementPolicy実装は、提供されたsuperPolicyに既存の同意管理メソッドとプロパティを委任することができ、それぞれのイベントでpolicyキーを自身の名前で上書きします。
class CustomPolicy(
val superPolicy: ConsentManagementPolicy
) : ConsentManagementPolicy by superPolicy {
override val name: String = "custom_policy"
override fun policyStatusInfo(): Map<String, Any> {
return superPolicy.policyStatusInfo().toMutableMap().apply {
put(ConsentManagerConstants.CONSENT_POLICY, name)
}
}
}
val customPolicy = CustomPolicy(ConsentPolicy.GDPR.create(
UserConsentPreferences(ConsentStatus.UNKNOWN, null)))
カスタム同意ポリシーが実装された後、必要に応じてConsentManagementPolicyで利用可能な以下のプロパティとメソッドを上書きします:
| プロパティ / メソッド | タイプ | 説明 |
|---|---|---|
name |
String |
ConsentManagementPolicyの名前 |
userConsentPreferences |
UserConsentPreferences |
ConsentManagerがプリファレンスの変更時に自動的に更新する現在のUserConsentPreferences |
consentLoggingEnabled |
Boolean |
同意の変更のログ記録が必要かどうかを構成します |
consentLoggingEventName |
String |
同意の変更をログに記録するときに使用するイベント名(キー:tealium_event)を構成します |
defaultConsentExpiry] |
ConsentExpiry |
ConsentManagementPolicyのデフォルトの有効期限を構成します |
cookieUpdateRequired |
Boolean |
TagManagementモジュールのwebview内のクッキーを更新するかどうかを構成します |
cookieUpdateEventName |
String |
cookieUpdateRequiredがtrueに構成されているときに使用するイベント名を構成します |
policyStatusInfo() |
Map<String, Any> |
各ディスパッチのペイロードに追加するキー値データのマップを返します |
shouldQueue() |
Boolean |
ConsentPolicyのルールに従ってディスパッチをキューに入れるかどうかを返します |
shouldDrop() |
Boolean |
ConsentPolicyのルールに従ってディスパッチをドロップするかどうかを返します |
例
以下の例では、ポリシーデータキーを再マッピングして、Tealium EventStreamの固定同意値を避けます:
class CustomPolicy(
val superPolicy: ConsentManagementPolicy
) : ConsentManagementPolicy by superPolicy {
return superPolicy.policyStatusInfo().toMutableMap().apply {
get(ConsentManagerConstants.CONSENT_STATUS)?.let { status ->
remove(ConsentManagerConstants.CONSENT_STATUS)
put("custom_consent_status", status)
}
get(ConsentManagerConstants.CONSENT_CATEGORIES)?.let { categories ->
remove(ConsentManagerConstants.CONSENT_CATEGORIES)
put("custom_consent_categories", categories)
}
}
}
以下の例では、送信される同意ログイベント名をカスタマイズします:
class CustomPolicy(
val superPolicy: ConsentManagementPolicy
) : ConsentManagementPolicy by superPolicy {
override val consentLoggingEventName: String
get() {
return when(userConsentPreferences.consentStatus) {
ConsentStatus.CONSENTED -> "user_consented"
ConsentStatus.NOT_CONSENTED -> "user_not_consented"
ConsentStatus.UNKNOWN -> "user_consent_unknown"
}
}
}
以下の例では、thirdPartyConsentProviderが別の同意プロバイダーへの参照である場合、第三者の同意値を返します:
class CustomPolicy(
val superPolicy: ConsentManagementPolicy,
val thirdPartyConsentLibrary: OtherConsentProvider
) : ConsentManagementPolicy by superPolicy {
override fun policyStatusInfo(): Map<String, Any> {
val status = thirdPartyConsentLibrary
.getConsent(userConsentPreferences.consentStatus == ConsentStatus.CONSENTED)
return mapOf("my_consent_status" to status)
}
}
最終更新日 :: 2024年March月29日