The new Sitecore 8 Experience Profile is a vital part, yes almost a cornerstone of the new xDB concept.
In xDB, you store information about the current user, anonymous or named, as a Contact in the Experience Profile (stored in the MongoDB).
Any user begins his life as an anonymous user, and the associated Contact object has no identifier, only a key matched in the cookie of the current user.
In order to connect the Contact with a named user, you use the Tracker.Current.Session.Identify(userName) method:
if (!Tracker.IsActive) return; Tracker.Current.Session.Identify("extranet\\user@domain.com");
The method identifies the user@domain.com as a Contact, creates a named Contact if the contact does not exist, or merges the current contact data into one named Contact. Also, the Contact will be locked for this user.
Please note that Tracker.Current.Session.Identify(userName) accepts a string. You can create named contacts with any key. This is great if your named users does not come from Sitecore Users.
But here lies the danger. If you by accident Identifies extranet\anonymous, every anonymous visitor will be merged and locked to the same Contact. And since a contact can only be locked to one session at a time, any subsequent calls to Tracker.Current.Session.Identify will wait, and wait, and wait, … until the previous contact unlocks the Contact.
And the log will be filled with:
Message: Failed to extend contact lease for contact 43188c31-cbe9-4386-8739-c12c3dc049c2
Or even:
2844 18:01:11 ERROR Cannot finish Analytics page tracking
Exception: Sitecore.Analytics.Exceptions.ContactLockException
Message: Failed to extend contact lease for contact 43188c31-cbe9-4386-8739-c12c3dc049c2
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.Analytics.Pipelines.HttpRequest.EndAnalytics.Process(HttpRequestArgs args)
So it is VERY important that you check that the user identified is not your anonymous user:
// THIS IS BAD!!! // The user could be extranet\anonymous if (!Tracker.IsActive) return; Tracker.Current.Session.Identify(Sitecore.Context.User.Name); // THIS COULD BE A SOLUTION: if (!Tracker.IsActive) return; if (Sitecore.Current.User.Name.ToLower() == "extranet\\anonymous") return; Tracker.Current.Session.Identify(Sitecore.Context.User.Name); // OR MAYBE THIS? if (!Tracker.IsActive) return; if (!Sitecore.Context.User.IsAuthenticated) return; Tracker.Current.Session.Identify(Sitecore.Context.User.Name);
MORE TO READ:
- How to Programatically associate visitor data into Contact Card by Sheetal Jain
- Examining a Multisite Sitecore xDB Configuration by David Peterson
- Merging Visitor cookies in Sitecore CMS 7.5 and the Experience Database by Thomas Eldblom (the article applies to Sitecore 8 as well)
