---
title: Setting up contact tracking
related:
  - https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management.md
  - https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/working-with-contacts.md
  - https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/working-with-contacts/merging-contacts.md
  - https://docs.kentico.com/13/developing-websites/mvc-development-overview.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Contacts represent website visitors and store marketing-related information about them. To learn more about contacts, see [Working with contacts](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/working-with-contacts.md).

To ensure that contact tracking works correctly on your website, you need to:

1. [Enable on-line marketing](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-contacts.md) in the **Settings** application of the related Xperience instance.
2. [Assign existing contacts to registered or signed-in users](#assigning-the-related-contact-to-registered-users) to make contact tracking effective.

> **Note:** **Default cookie level or consent requirements**
>
> The contact tracking functionality in Kentico Xperience Enterprise only works if the **Default cookie level** setting is set to _Visitor_ or _All_, or for visitors who give tracking consent and increase their cookie level. For more information, see [Working with consents](https://docs.kentico.com/13/configuring-xperience/data-protection/gdpr-compliance/working-with-consents.md).

Contact detail updates are batch processed and logged at an interval together with activities. To learn how to change the logging interval, see [Configuring activity and contact update processing](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-activities/enabling-activity-tracking.md#configuring-activity-and-contact-update-processing).

## Obtaining the current contact

The system uses a browser cookie as persistent storage for the current contact. By default, the storage is empty. However, once you ask for the current contact, the system sets the contact's GUID (unique identifier) to every response cookie.

To get the current contact in the implementation of an MVC website, call the **ContactManagementContext.GetCurrentContact** method. The context class and method are available in the **CMS.ContactManagement** namespace (part of the API provided by the _Kentico.Xperience.Libraries_ NuGet package).

```csharp

using CMS.ContactManagement;


```

```csharp title="Example"

            // Gets the current contact
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact();


```

If there is no contact related to the currently processed request, the _GetCurrentContact_ method automatically creates and returns a new anonymous contact by default. You can disable the automatic creation of new contacts by calling the method with a _false_ bool parameter.

> **Tip:** **Tip**: If you wish to use the [dependency injection](https://docs.kentico.com/13/developing-websites/initializing-xperience-services-with-dependency-injection.md) design pattern on your website, you can create a custom service to provide the required contact management functionality. Call the methods of the _ContactManagementContext_ class within the service's implementation.

## Assigning the related contact to registered users

For effective tracking of contacts, you need each registered user to use the same contact for all their visits. To ensure that registered users correctly use a permanent contact:

- Assign a contact to users immediately after registration
- Switch a visitor's contact to their user's contact after the visitor signs in

Use the following steps to implement the required functionality on your MVC site:

1. Open your MVC project in Visual Studio.
2. Edit the controllers that process [sign-ins](https://docs.kentico.com/13/managing-users/user-registration-and-authentication/setting-up-authentication.md) and [registrations](https://docs.kentico.com/13/managing-users/user-registration-and-authentication/enabling-user-registration.md).
3. Call the **ContactManagementContext.UpdateUserLoginContact** method in the controller's sign-in and registration actions.
   - Pass the user name of the signed in or registered user via the method's parameter (represented by the _userName_ variable in the code example).
   - Call the method only **after** a successful sign-in or registration.

     ```csharp

     using CMS.ContactManagement;

     ```

     ```csharp

                 ContactManagementContext.UpdateUserLoginContact(userName);


     ```

The _UpdateUserLoginContact_ method performs the following functions:

- Permanently assigns the current contact to the specified user (for newly registered users)
- If the user already has a contact assigned, merges the current contact into it (as long as the current contact does not belong to a different user)
- Updates the contact cookie in the visitor's browser to the correct contact (if necessary)

## Merging contacts

In some cases, multiple [contacts](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/working-with-contacts.md) on your websites may actually represent a single real‑world person. [Automatic merging](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/working-with-contacts/merging-contacts.md) allows you to get rid of duplicates by combining several contacts into a single object. The system automatically merges contacts that are associated with the same email address.
