2

I am working on Sitecore 10.2 and trying to update facets in xDB. The below function is working fine on local but it is not working on VM. xDB is enabled on Sitecore instance.

public bool SaveContactData(string firstName, string lastName, string identifierSource, string email, string phoneNumber, string language, string userAgent)
{
    try
    {
        var contactReference = GetIdentifiedContactReference(identifierSource, email);

        using (var client = SitecoreXConnectClientConfiguration.GetClient())
        {
            var contact = client.Get(contactReference, new ContactExpandOptions(CollectionModel.FacetKeys.PersonalInformation, CollectionModel.FacetKeys.EmailAddressList, PhoneNumberList.DefaultFacetKey));

            //CONTACT IS COMING NULL
        }
        return true;
    }
    catch (Exception ex)
    {
        Log.Error("Error saving data to profile", ex, this);
        return false;
    }
}

private IdentifiedContactReference GetIdentifiedContactReference(string identifierSource, string identifier)
{
    if (Tracker.Enabled && !Tracker.Current.IsActive)
    {
        Tracker.StartTracking();
    }

    if (Tracker.Current?.Contact == null)
    {
        Log.Warn("Tracker.Current?.Contact == null", this);
        return null;
    }

    if (Tracker.Current.Contact.IsNew)
    {
        Tracker.Current.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave;
        _contactManager.SaveContactToCollectionDb(Tracker.Current.Contact);
        IdentifyContact(identifierSource, identifier);
        return new IdentifiedContactReference(identifierSource, identifier);

    }

    var id = Tracker.Current.Contact.Identifiers.FirstOrDefault();
    return Tracker.Current.Contact.IsNew || Tracker.Current.Contact.Identifiers.Count == 0
        ? new IdentifiedContactReference(identifierSource, identifier)
        : new IdentifiedContactReference(id?.Source, id?.Identifier);
}
1
  • What are the main differences between the two systems? E.g., is the VM one scaled or anything else remarkable. My first approach would be to take a look into the XDB Services logs. (xconnect, AutomationEngine, IndexWorker, ProcessingEngine)
    – Fabian
    Commented Aug 10, 2022 at 12:53

3 Answers 3

1

Can you confirm that data is arriving in the xDB databases? You should be able to see a record in the device profiles table, with value that matches your SC_GLOBAL cookie value (or any records in interactions table with current date time).

One thing that caught me out a few times is that in sitecore 10+ tracking data is not sent to xDB when using the CM sitecore role. You must test using CD or standalone role.

The code below is the way I get the identifier, seems to work consistently

var trackerIdentifier = new IdentifiedContactReference(Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, Sitecore.Analytics.Tracker.Current.Contact.ContactId.ToString("N"));
1
  • 1000x thanks for "You must test using CD or standalone role." Commented May 7 at 20:13
1

I did a few things, and after that, it started working:

  1. First check if xDB is enabled, which was enabled already
  2. Then I checked if "SC_ANALYTICS_GLOBAL_COOKIE" is coming or not, which was not coming on the server so I checked "Analytics.CookieDomain" setting which was wrong so I updated that setting
<setting name="Analytics.CookieDomain" value="******" />
0

Be sure to check that the following settings:

  <sitecore>
    <settings>
      <setting name="Xdb.Enabled" value="true" />
      <setting name="Xdb.Tracking.Enabled" value="true" />
    </settings>
  </sitecore>

Are set to true. These can be found in the "\App_Config\Sitecore\Marketing.xDB\Sitecore.Xdb.config" file.

1
  • Yes as mentioned in question, it is already enable Commented Aug 10, 2022 at 2:36

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.