Sitecore 9 Tracker.Current.Session.Identify is replaced with Tracker.Current.Session.IdentifyAs

In Sitecore 9, Sitecore have decided to change how you identify named users, i.e. how you match a Contact with a user that is logged into your website. The  Tracker.Current.Session.Identify method is obsolete. It has been replaced with Tracker.Current.Session.IdentifyAs:

// Sitecore 8 identification method:
public static void IdentifyUser(string username)
{
  // Never identify an anonymous user
  if (username.ToLower() == "extranet\\anonymous")
	return;

  if (Tracker.Current != null && Tracker.Current.IsActive && Tracker.Current.Session != null)
  {
	Tracker.Current.Session.Identify(username);
  }
}

// Sitecore 9 identification method:
public static void IdentifyUser(string username)
{
  // Never identify an anonymous user
  if (username.ToLower() == "extranet\\anonymous")
	return;

  string identificationSource = "website";
  if (Tracker.Current != null && Tracker.Current.IsActive && Tracker.Current.Session != null)
  {
	Tracker.Current.Session.IdentifyAs(identificationSource, username);
  }
}

The IdentifyAs() takes 2 parameters:

  • Source: A string that identifies where this contact comes from (for instance, “twitter” or “website”)
  • Identifier: The identifier itself (username, email, customerID or any other string based on your implementation)

Thanks to Sitecore support for the claification.

MORE TO READ:

 

Advertisement

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, General .NET, Sitecore 9 and tagged , , , , , . Bookmark the permalink.

2 Responses to Sitecore 9 Tracker.Current.Session.Identify is replaced with Tracker.Current.Session.IdentifyAs

  1. Pingback: Sitecore 8 and Tracker.Current.Session.Identify – Overriding expired contact session lock for contact id | Brian Pedersen's Sitecore and .NET Blog

  2. Pingback: Part 1 – Experience Profile – Identify Users Early – Aceik

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.