Contacts represent website visitors and store marketing-related information about them. To learn more about contacts, see Working with contacts.
To track contacts on websites presented by a separate MVC application, you need to:
- Enable on-line marketing in the Settings application of the related Kentico instance.
- Assign existing contacts to registered or signed-in users to make contact tracking effective.
Default cookie level or consent requirements
The contact tracking functionality in Kentico EMS 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 on MVC sites.
Contact detail updates are batch processed and logged at an interval together with Configuring activity and contact update processing.. To learn how to change the logging interval, see
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
// Gets the current contact ContactInfo currentContact = ContactManagementContext.GetCurrentContact();
Tip: If you wish to use the dependency injection 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:
Open your MVC project in Visual Studio.
- Call the ContactManagementContext.UpdateUserLoginContact method in the controller's sign-in and registration actions.
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)
In some cases, multiple contacts on your websites may actually represent a single real‑world person. Automatic merging 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.