---
title: "The ContactFactory class"
slug: "the-contactfactory-class"
abstract: ""
---
# The ContactFactory class

The `ContactFactory` class is used to get the id of the current runtime user. The default implementation is dependent on Sitecore Analytics for tracking; if this does not suit your needs you can change it by extending the `ContactFactory` class and overriding the `GetContact` method.

The following is an example of how the default instance works. When you have the id of your user from the ECS, you identify the `Tracker.Current.Contact` with that ID (using the `Tracker.Current.Session.Identify()`method),and from that point on this ID is returned by the `ContactFactory` class. If no ID is available from the external user then the id created by Sitecore Analytics is used instead.

```csharp
public virtual string GetContact()
{
if (Tracker.Current == null)
{
if (HttpContext.Current != null &&
HttpContext.Current.User != null)
{
return HttpContext.Current.User.Identity.Name;
}

return System.Threading.Thread.CurrentPrincipal.Identity.Name;
}
var user = Tracker.Current.Contact.Identifiers.Identifier;
if (string.IsNullOrEmpty(user))
{
  user = Sitecore.Data.ID.Parse(Tracker.Current.Contact.ContactId).ToString();
}
return user;
}

```