We are currently experiencing an issue in our Production environment (CD or CM in a scaled CD, CM, PRC, REP and xConnect setup) where client returns contact about 10% of the time when using the example xConnect contact creation code here.
using Sitecore.Analytics.Model;
using Sitecore.Analytics.Model.Entities;
using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using Sitecore.XConnect.Collection.Model;
namespace Documentation
{
public class TrackAnonymousContacts
{
public void Example()
{
if (Sitecore.Analytics.Tracker.Current.Contact.IsNew)
{
var manager = Sitecore.Configuration.Factory.CreateObject("tracking/contactManager", true) as Sitecore.Analytics.Tracking.ContactManager;
if (manager != null)
{
Sitecore.Analytics.Tracker.Current.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave;
manager.SaveContactToCollectionDb(Sitecore.Analytics.Tracker.Current.Contact);
var trackerIdentifier = new IdentifiedContactReference(Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, Sitecore.Analytics.Tracker.Current.Contact.ContactId.ToString("N"));
using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
try
{
var contact = client.Get<Contact>(trackerIdentifier, new Sitecore.XConnect.ContactExpandOptions());
if (contact != null)
{
client.SetFacet<PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, new PersonalInformation()
{
FirstName = "Myrtle" // Replace with real input source
});
client.Submit();
manager.RemoveFromSession(Sitecore.Analytics.Tracker.Current.Contact.ContactId);
Sitecore.Analytics.Tracker.Current.Session.Contact = manager.LoadContact(Sitecore.Analytics.Tracker.Current.Contact.ContactId);
}
}
catch (XdbExecutionException ex)
{
// Manage conflicts / exceptions
}
}
}
}
}
}
}
We do not see this issue in any other environments and it is impacting our conversion / identification of users. We've deployed additional logging and various potential solutions eg. Retry contact creation X times, using different manager methods or first identifying the user before pushing contact facets.
It is also worth noting it's running on 9.0 Update-2 and that there are no errors in the logs for the contact creation in either Sitecore or xConnect.
Has anyone experienced this issue before?
Tracker.Current.Contact.ContactId
is when you are runningSaveContactToCollectionDb
then see if you can find the contact with that ID in the database (checkxdb_collection.ContactIdentifiers
table and see if you can find the ContactId in theIdentifiers
column. You may have to translate the ContactId from Guid.ToString("N") to hex values first (as that is what is stored in theIdentifiers
column). If the contact cannot be found after having runSaveContactToCollectionDb
you still won't know what's wrong, but you should have narrowed the problem down a bit :)