I am working on XDB analytics code upgrade from Sitecore 8.2 to Sitecore 9.3

Some of the xdb repository not working in Sitecore 9.3 analytics.

For Example :tracking/contactRepository, tracking/contactManager as shown below

public void MergeTwoKnownContacts(string dyingContactIdentity, Contact survivingContact)
        if (survivingContact == null || string.IsNullOrEmpty(dyingContactIdentity))

        ContactRepository ContactRepository = Factory.CreateObject("tracking/contactRepository", true) as ContactRepository;

        Contact dyingContact = GetContact(dyingContactIdentity, "Contact Merge");

        if (ContactRepository != null && dyingContact != null)
            // The data will be transferred from the dyingContact to the survivingContact
            ContactRepository.MergeContacts(survivingContact, dyingContact);

As per my understating "tracking/contactRepository" and tracking/contactManager would not be support in Sitecore 9.x. I Would like to understand What is the replacement of the repository in Sitecore 9.x analytics.

Appreciated someone help to understand. Thanks in advance!!

2 Answers 2


The ContactRepository should not be used in Sitecore 9+ to modify a contact that does not have an ongoing session, use the xConnect Client API. From your MergeTwoKnownContacts method, it looks like you are merging two contacts. To merge an existing source contact into an existing target contact, you should use the client.MergeContacts() method. Contacts are merged by the xConnect service layer after Submit() / SubmitAsync() has been called.

public void ExampleSync()
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
                    // New known contact
                    var identifers = new ContactIdentifier[] { new ContactIdentifier("twitter", "myrtlesitecore", ContactIdentifierType.Known) };

                    var newContact = new Contact(identifers);


                    // Contact must be saved before a merge

                    // Reference to existing contact
                    var reference = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB"));

                    Contact existingContact = client.Get<Sitecore.XConnect.Contact>(reference, new Sitecore.XConnect.ContactExpandOptions() { });

                    // Data copied FROM existingContact TO newContact
                    client.MergeContacts(existingContact, newContact);


                catch (XdbExecutionException ex)
                    // Manage exceptions

above is a sync example for contact merge. Sitecore has very good documentation for the merge contact with merge logic - https://doc.sitecore.com/developers/92/sitecore-experience-platform/en/merge-contacts.html


You can use the below to get the contactManager.

ContactManager _contactManager = Factory.CreateObject("tracking/contactManager", true) as ContactManager;

Then you can use the below line to get the contact from ContactManager

var contact = _contactManager.LoadContact(Tracker.Current.Contact.ContactId);

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.