Deleting contacts and interactions from the xDB

Current version: 9.3

In Sitecore 9.2 and later, you can delete a contact and all associated interactions, facets, and identifiers. Use this functionality to remove data that is no longer valuable to your business - for example, you may want to delete contacts that do not have any interactions from the past two years. The following video demonstrates how to find and delete inactive contacts:

Be aware that:

  • Deleting a contact is different from executing the right to be forgotten.

  • You cannot delete a subset of interactions, or delete interactions without deleting the contact.

  • Deleting a contact removes that contact's interactions, which affects aggregated data in the xDB Reporting database if you choose to rebuild.

    Note

    The xDB Reporting database will include deleted data until you choose to rebuild.

  • Contacts that are deleted during an active session will be partially recreated by the tracker on session end.

The following example demonstrates how to delete a batch of two contacts:

RequestResponse
using System;
using System.Threading.Tasks;
using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using Sitecore.XConnect.Operations;

namespace Documentation
{
    public class DeleteContact
    {
        // Async example
        public async void ExampleAsync()
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    // Get contact
                    var referenceOne = new Sitecore.XConnect.ContactReference(Guid.Parse("A9812105-2D45-A612-82E6-34E6D7117DCB"));
                    var referenceTwo = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB"));

                    Task<Sitecore.XConnect.Contact> contactTaskOne = client.GetAsync<Sitecore.XConnect.Contact>(referenceOne, new Sitecore.XConnect.ContactExpandOptions() { });
                    Task<Sitecore.XConnect.Contact> contactTaskTwo = client.GetAsync<Sitecore.XConnect.Contact>(referenceTwo, new Sitecore.XConnect.ContactExpandOptions() { });

                    Contact contactOne = await contactTaskOne;
                    Contact contactTwo = await contactTaskTwo;

                    // Delete contact

                    client.DeleteContact(contactOne);
                    client.DeleteContact(contactTwo);

                    await client.SubmitAsync();
                }
                catch (XdbExecutionException ex)
                {
                    // Manage exceptions
                }
            }
        }

        // Sync example
        public void Example()
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    // Get contact
                    var referenceOne = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F55-E611-12E6-22E6D7117DCB"));
                    var referenceTwo = new Sitecore.XConnect.ContactReference(Guid.Parse("DB814105-1F45-E611-82E6-34E6D7117DCB"));


                    var contactOne = client.Get<Sitecore.XConnect.Contact>(referenceOne, new Sitecore.XConnect.ContactExpandOptions() { });
                    var contactTwo = client.Get<Sitecore.XConnect.Contact>(referenceTwo, new Sitecore.XConnect.ContactExpandOptions() { });

                    // Delete contact

                    client.DeleteContact(contactOne);
                    client.DeleteContact(contactTwo);

                    client.Submit();
                }
                catch (XdbExecutionException ex)
                {
                    // Manage exceptions
                }
            }
        }
    }
}

Contact delete logic

When you delete a contact:

  • The following data is removed from the xDB Collection database:

    • Interaction facets

    • Interactions

    • Contact facets

    • Contact

    • Contact identifier indexes

    Note

    Device profiles associated with the contact are not removed.

  • The xDB Search Indexer removes all contact and interaction data from the xDB index.

  • The Marketing Automation Engine's xConnect service plugin (Sitecore.XConnect.Service.Plugins.MarketingAutomation.XdbContactEventWatcher) adds a high priority work item to remove the deleted contact from all automation plans.

Keep the following in mind when using the delete operation:

  • The delete operation ignores concurrency token validation. This means that the contact will be deleted even if it is being updated by a parallel thread, and contact identifiers are deleted even if the contact identifier index is locked.

  • The delete operation is transactionless, which may result in data being partially deleted if a system error occurs at the provider level (SQL or MongoDB).

Delete and merged contacts

When two contacts are merged, references are added between the source and target contact. The target contact references the source contact via a merge identifier, and the source contact references the target contact via a facet property.

A contact that has been part of multiple merge operations results in a merge tree of related contacts. In the following diagram, Known2 is the target of several merge operations and the current root of the merge tree:

Note

The example uses text identifiers instead of GUIDs for readability.

Sitecore 9.2 and 9.3 differ slightly in how the following scenario are handled:

  • Deleting a contact in the middle of the merge tree (for example, Known1).

  • Deleting the root contact (for example, Known2).

Delete and merged contacts in 9.2

In Sitecore 9.2, the following logic applies when you delete a contact:

  • If you delete a contact in the middle of the merge tree (for example, Known1), you break the chain that links Known2 with Anon1 and Anon2. Anon1 and Anon2 become orphans.

  • If you delete the root contact, no other contacts are deleted. The contacts marked Obsolete in the diagram remain in the xDB Collection database.

Delete and merged contacts in 9.3 and later

In 9.3 and later, the following logic applies when you delete a contact:

  • If you delete a contact in the middle of the merge tree (for example, Known1), new references are created between the root contact and the remaining contacts in the branch. In the following example, references are added between Known2 and Anon1/Anon2.

  • If you delete the root contact, the entire merge tree is deleted. This means that deleting Known2 also deletes Anon1, Anon2, Anon3, and Known1.

Delete and the right to be forgotten

Deleting a contact is not the same as using xConnect's right to be forgotten feature. Your organization must decide which option meets the requirements for GDPR and other data privacy legislation in your particular case.

Warning

Be aware that contacts that are deleted during an active session will be partially recreated by the tracker, including any known or anonymous identifiers.

Do you have some feedback for us?

If you have suggestions for improving this article,