Identifying contacts

Contact identification is the process of connecting the current session, device and contact session to an identifier. This is implemented using the IdentifyAs() method as shown:

Sitecore.Analytics.Tracker.Current.Session.IdentifyAs("sitecoreextranet", "myrtlesitecore");

When IdentifyAs() is called during an anonymous contact’s session, one of the following occurs:

  • If the identifier does not exist, it is created. The current contact becomes known.
  • If the identifier does exist, the existing known contact is loaded from xConnect and merged with the anonymous contact.

Identifiers consist of an identifier and a source. An identifier is a unique piece of information about the contact, such as a username, and the identifier source indicates where the identifier came from. A contact can have multiple identifiers. The following table lists a few examples of known identifiers and sources:

Identifier Source
myrtlesitecore twitter
m_McSitecore brandextranet
abc10769150 facebookauth

Important

You cannot use an anonymous identifier to identify a contact. The only exception to this rule is the alias identifier.

Tracker identifier

Every contact that has visited your website has an anonymous tracker identifier. The tracker identifier matches Sitecore.Analytics.Tracker.Current.Contact.ContactId property, and is different from the contact’s ID in xConnect. Refer to the Set contact facets topic for more information.

When to identify

Identification is separate from authentication, and usually occurs at the same time. However, once a contact has been identified on a device, the tracker uses the analytics cookie to automatically re-identify (not re-authenticate) that contact even when the ASP.NET session cookie is removed.

Depending on your requirements, there are different identification strategies that you can implement to identify contacts across their devices. For example:

Scenario Identification
Contact logs in. Username can be used as an identifier - call IdentifyAs(“usernamesource”, “username”) if login is successful.
Contact opens e-mail link sent by E-mail Experience Manager. E-mail link includes contact’s alias identifier in a query string. This data is used to identify the contact.

In the following example, contact identification occurs after the contact has successfully logged in:

Identifier sources

It is your responsibility to decide what source to use when identifying a contact. There is no central repository of sources. If contacts use the same details to login across all systems, ensure your source is consistent across all login and registration code.

Identification scenarios

The following table describes what happens when IdentifyAs() is called:

Scenario Identification
Current contact is anonymous Current contact exists in xConnect Identifier already exists Information in the anonymous contact merges with the known contact, making the anonymous contact record obsolete and replacing it with a pointer to the known contact record. After merging, the context contact is deleted from the session state. The merged contact includes custom contact facets and interaction history.
Current contact is anonymous Current contact is new Identifier already exists Tracker continues the current interaction on behalf of the known contact. No merge occurs, as anonymous contact did not exist in xConnect.
Current contact is a known contact Identifier already exists Current interaction is terminated and a new interaction for the known contact begins. The new interaction begins on the last page of the terminated interaction, and the link between the current device and the known contact is updated.
Current contact is anonymous Identifier does not exist The current contact is saved to xConnect along with a new known identifier, and the session continues.