Manage a contact's tracking consent choices
You can use the IConsentManager service to give consent, revoke consent, and retrieve a contact's consent choice for the context website:
Sitecore.Analytics.Tracking.Identification.IContactIdentificationManager is a transient service.
<name of a service> depends on the Sitecore.Context.Site and must be resolved in the context where it is available.
If a website requires explicit tracking, contacts are not tracked until they give consent - for example, by clicking a button in a cookie consent banner.
To manage a contact's consent choice in any other context, use the xConnect Client API to update the ConsentInformation facet. For example, you can implement a user interface that allows a call center employee to update a contact's consent choices over the phone.
Tracking consent choices are stored in the Sitecore.XConnect.Collection.Model.ConsentInformation contact facet in xConnect. This facet provides the Consents dictionary, which is where the consent choices are stored. Consents that need to be tracked are stored by the following key: xDB.Tracker.Consent.WebSiteName. For example, a contact's tracking choice for a web site called mywebsite is stored by the xDB.Tracker.Consent.mywebsite key. The consent key prefix, xDB.Tracker.Consent., is also accessible as the Sitecore.Analytics.XConnect.DataAccess.Constants.ConsentKeyPrefix constant.
Get consent choice
Get consent choice
To get the context contact's consent choice for the current site:
In this scenario:
-
If the identifier is not provided (that is, null is passed to the method), the tracker attempts to get the contact's consent choice from the
IConsentStorageservice. This is stored in theSC_TRACKING_CONSENTcookie by default. -
If the identifier is provided, the tracker attempts to get the consent choice from the contact's facet, loaded from xConnect.
Give consent
Give consent
To give consent for the context site:
In this scenario:
-
The tracker writes the contact's consent choice to the consent storage using the
IConsentStorageservice. By default, this choice is stored in theSC_TRACKING_CONSENTcookie. -
Tracking is started.
-
If the identifier parameter is provided (it is not null), the tracker identifies the contact and the updated consent choice is set for the current contact by the
ContactManager.SetTrackingConsent()API.
Revoke consent
Revoke consent
To revoke consent:
In this scenario:
-
If tracking is in progress, it stops.
-
The tracker invalidates the
SC_ANALYTICS_GLOBAL_COOKIEand and updates the contact's consent choice to the consent storage using theIConsentStorageservice. By default, this choice is stored in theSC_TRACKING_CONSENTcookie. -
If the identifier parameter is provided (it is not null) and tracking has started, the tracker ensures that the identifier matches the current contact and sets the consent choice to the contact using the
ContactManager.SetTrackingConsent()API. -
If the identifier parameter is provided (it is not null) but tracking has not started, the tracker ensures that the contact is loaded from xDB and sets the consent choice for the contact using the
ContactManager.SetTrackingConsent()API. -
If the identifier parameter is not provided (it is null), the tracker uses information in the
SC_ANALYTICS_GLOBAL_COOKIEto determine which contact is associated with the current device. It then ensures that the contact is loaded from xDB and sets the consent choice for the contact using theContactManager.SetTrackingConsent()API.