0

We have currently enabled the Sitecore OOB Personalization module, and have developed some custom conditions and actions to display a particular component on the website.

When a user authenticated on the sire, we are identifying the contact with a primary key, such that all interaction the user has done is associated with the primary key in the Mongo DB database later on.

Following activation of the Personalization module on our Production environment(which is a load-balanced environment), the component was working fine during testing. Yet, after some time we noticed that the component was not being displayed on a few individual servers. When we cleared the HTML cache on these specific servers, the component was working as required for some time but got hidden again afterward.

It was a random behavior that was happening with this component on different servers, and not on specific individual servers(there is no HTML cache enabled on the MVC rendering for the component).

In our logs, we noticed that the following errors were being obtained a few times on those individual servers

Exception: Sitecore.Analytics.Exceptions.ContactLockException Message: 
Failed to extend contact lease for contact f217ae9d-a38f-4752-be0c-d824965f4d3b 
Source: Sitecore.Analytics at Sitecore.Analytics.Tracking.ContactManager.SaveAndReleaseContact(Contact contact) at Sitecore.Analytics.Pipelines.EndAnalytics.ReleaseContact.Process(PipelineArgs args) at (Object , Object[] ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at
 Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, Boolean failIfNotExists) 
at Sitecore.Analytics.Pipelines.HttpRequest.EndAnalytics.Process(HttpRequestArgs args)

Following the occurrence of this error on the server, we noticed that one of the following conditions was being set as true

if (Sitecore.Analytics.Tracking.Profile != null &&
 Sitecore.Analytics.Tracking.Profile.Count > 0) 

for all contacts who were trying to access the site(noticed these in the logs when accessing the individual server where the component was not being displayed).

Can you indicate in which specific use case we get this type of issue?

You may find below the code snippet we have for the identification of the contact(the variable urn is our primary key)

ContactManager contactManager = Factory.CreateObject("tracking/contactManager", true) as ContactManager;
if (contactManager != null)
{
Contact contact1 = contactManager.LoadContactReadOnly(urn);
if (contact1 == null || contact1.ContactId == Guid.Empty)
    Tracker.Current.Session.Identify(urn);
else
{
    ContactRepository contactRepository = Sitecore.Configuration.Factory.CreateObject("tracking/contactRepository", true) as ContactRepository;
    if (contactRepository != null)
    {
                    Contact newContact = contactRepository.CreateContact(ID.NewID);
                    contact1.IsTemporaryInstance = true;
                    newContact.Identifiers.IdentificationLevel = ContactIdentificationLevel.Known;
                    newContact.Identifiers.Identifier = urn;
                    contactRepository.MergeContacts(newContact, contact1);
    }
  }
}
  • Which version of Sitecore do you use precisely? – Peter Procházka Jul 30 '18 at 14:21
  • @PeterProchazka Sitecore 8.2 update 4. – adarsh Jul 31 '18 at 12:37
0

For web users, I think you are doing way too much work. If this was off Web Session and you needed to create contacts on the site, maybe in bulk, then this would be good code.

Under most circumstances, Sitecore does all the contact work for you. There is also no need for contactRepository.MergeContacts anymore, that is built in now.

Get Contact

var contact = Tracker.Current.Contact;

Get a logged in contact

Tracker.Current.Session.Identify(urn);
var contact = Tracker.Current.Contact;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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