---
title: "連絡先のトラッキング同意オプションを管理する"
slug: "manage-a-contact-s-tracking-consent-choices"
abstract: "コンセントマネージャーを使って連絡先のトラッキング同意オプションを管理する方法。"
---
# 連絡先のトラッキング同意オプションを管理する

IConsentManagerサービスを使って同意を与えたり、同意を取り消したり、コンテキストサイトで連絡先の同意オプションを取得することができます。

> !重要Sitecore.Analytics.Tracking.Identification.IContactIdentificationManager一時的なサービスです。

var consentManager = Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetRequiredService<Sitecore.Analytics.Tracking.Consent.IConsentManager>();

> !注<name of a service>Sitecore.Context.Siteによって異なり、利用可能な文脈で解決しなければなりません。

ウェブサイトが明確な追跡を必要とする場合、連絡先は [同意を与える](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/manage-a-contact-s-tracking-consent-choices.html#UUID-acb92969-5c6d-34ce-c7c1-7af439f42c54_section-idm4528684816849631602368156621 "Give consent") まで追跡されません。例えば、クッキー同意バナーのボタンをクリックするなどです。

> !注他の文脈でコンタクトの同意選択を管理するには、xConnect Client APIを使ってConsentInformation面を更新してください。例えば、コールセンターの従業員が電話越しにコンテントの同意選択を更新できるユーザーインターフェースを実装できます。

同意の選択肢を追跡することは、xConnectの[Sitecore.XConnect.Collection.Model.ConsentInformation連絡先ファセット](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/use-core-collection-model-facets.html "Use core collection model facets") に保存されます。このファセットはConsents辞書を提供し、同意の選択が保存されます。追跡が必要な同意は以下のキーで保存されます: xDB.Tracker.Consent.\*WebSiteName\*。例えば、*mywebsite*というウェブサイトの連絡先の追跡選択はxDB.Tracker.Consent.mywebsiteキーで保存されます。同意キー接頭辞xDB.Tracker.Consent.もSitecore.Analytics.XConnect.DataAccess.Constants.ConsentKeyPrefix定数としてアクセス可能です。

## 同意選択権を取得しましょう

現在のサイトに関するコンテキスト連絡先の同意オプションを取得するには:

using Microsoft.Extensions.DependencyInjection;
using Sitecore.Analytics.Tracking.Consent;
using Sitecore.Analytics.Tracking.Identification;
using Sitecore.DependencyInjection;
using System.Linq;

namespace Documentation.Examples
{
 public class ConsentExamples
 {
 public void GetConsentChoice()
 {
 var consentManager = ServiceLocator.ServiceProvider.GetRequiredService<IConsentManager>();

 // If the known identifier is null, the consent choice is retrieved from a cookie.
 // Supply the relevant Source and KnownIdentifier as parameters below.
 TrackingConsent consentChoice = consentManager.GetConsent(new KnownContactIdentifier(Source, KnownIdentifier);

 var consentGivenForSite = consentChoice.IsGiven;
 }
 }

このシナリオでは:

-   識別子が提供されない場合(つまりメソッドにnullが渡された場合)、トラッカーは IConsentStorage サービスから連絡先の同意選択を試みます。これはデフォルトで SC\_TRACKING\_CONSENT クッキーに保存されます。
-   識別子が提供されている場合、トラッカーはxConnectから読み込まれた連絡先の面から同意の選択肢を取得しようとします。

## 同意してください

コンテキストサイトの同意をお願いします:

using Microsoft.Extensions.DependencyInjection;
using Sitecore.Analytics.Tracking.Consent;
using Sitecore.Analytics.Tracking.Identification;
using Sitecore.DependencyInjection;
using System.Linq;

namespace Documentation.Examples
{
 public class ConsentExamples
 {
 public void GetConsentChoiceAndIdentify()
 {
 var consentManager = ServiceLocator.ServiceProvider.GetRequiredService<IConsentManager>();

 // Supply the relevant Source and KnownIdentifier as parameters below.
 consentManager.GiveConsent(new KnownContactIdentifier(Source, KnownIdentifier);
 }
 }
}

このシナリオでは:

-   トラッカーは IConsentStorage サービスを使って連絡先の同意選択を同意ストレージに書き込みます。デフォルトでは、この選択は SC\_TRACKING\_CONSENT クッキーに保存されます。
-   追跡を開始しました。
-   識別子パラメータが提供されている場合(nullでない場合)、トラッカーは連絡先を特定し、 [ContactManager.SetTrackingConsent() API](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/contactmanager-reference.html "ContactManager reference")によって現在の連絡先の同意選択肢が更新されます。

## 同意撤回

同意を取り消すには:

using Microsoft.Extensions.DependencyInjection;
using Sitecore.Analytics.Tracking.Consent;
using Sitecore.Analytics.Tracking.Identification;
using Sitecore.DependencyInjection;
using System.Linq;

namespace Documentation.Examples
{
 public class ConsentExamples
 {
 public void RevokeConsent()
 {
 var consentManager = ServiceLocator.ServiceProvider.GetRequiredService<IConsentManager>();

 // Supply the relevant Source and KnownIdentifier as parameters below.
 consentManager.RevokeConsent(new KnownContactIdentifier(Source, KnownIdentifier);
 }
 }

このシナリオでは:

-   追跡が進行中なら、それは停止します。
-   トラッカーは SC\_ANALYTICS\_GLOBAL\_COOKIE を無効にし、 IConsentStorage サービスを使ってコンセントストレージに連絡先の同意選択を更新します。デフォルトでは、この選択は SC\_TRACKING\_CONSENT クッキーに保存されます。
-   識別子パラメータが提供され(nullでない場合)、追跡が開始された場合、トラッカーは識別子が現在の連絡先と一致していることを確認し、その ContactManager.SetTrackingConsent() APIを使って連絡先に同意の選択肢を設定します。
-   識別子パラメータが提供されている(nullではない)がトラッキングが始まっていない場合、トラッカーはxDBからコンタクトが読み込まれていることを確認し、 ContactManager.SetTrackingConsent() APIを使ってコンタクトの同意選択を設定します。
-   識別子パラメータが提供されていない(null)場合、トラッカーは SC\_ANALYTICS\_GLOBAL\_COOKIE 内の情報を使って現在のデバイスに関連付けられている接触を特定します。その後、xDBから接触が読み込まれていることを確認し、 ContactManager.SetTrackingConsent() APIを使って連絡先の同意選択を設定します。