Setting up automatic deletion of contacts

Kentico EMS required

Features described on this page require the Kentico EMS license.

The contact management application generates a very large amount of data, particularly on high‑traffic websites. The system creates contacts and logs activities for every visitor (depending on the Default cookie level), which may be overwhelming for your marketers. To address this, we recommend that you configure the system to regularly delete contacts that meet certain conditions. This allows you to filter out inactive, outdated or otherwise unnecessary contacts without having to remove them individually.

Setting automatic contact deletion not only helps you keep only active contacts in the system, but can also improve system performance.

Deleting contacts from the system also causes deletion of their approved consent agreements. We recommend consulting this with a lawyer and setting up automatic deletion of contacts only when the consent agreements of your contacts will not be needed in the future.

Configuring automatic contact deletion

You can configure automatic contact deletion in the Settings application.

  1. Open the Settings application.
  2. Navigate to the On‑line marketing -> Contact management -> Inactive contacts category in the settings tree.
  3. Select one of the deletion options:
  4. In last X Days, specify the number of days for which contacts have to be inactive to be deleted by the system.
    • The minimum value is 10 days.
    • For contacts that haven’t performed any activity, the system considers the date of their creation as the last time they were active.
  5. Click Save.

The system now deletes inactive contacts based on the selected settings.

Contact deletion interval

The system deletes contacts using a global scheduled task named Delete inactive contacts. To preserve live website performance, the system runs the scheduled task only during off-peak hours (between 2:00 and 6:00 am) and deletes 1000 contacts at a time at most.

The task runs in a separate thread by default and the deleting itself is done by the database server.

Customizing automatic contact deletion settings

If none of the settings available for contact deletion suit your needs, you can programmatically create your own configuration. Do that by implementing the Kentico’s IDeleteContacts interface:

  1. Create a class that implements the IDeleteContacts interface.

  2. Implement your own logic for how inactive contacts should be deleted. The following example configures the system to delete all contacts that do not have a ‘ContactStateID’ filled in.

    
    
    
     using System;
     using System.Linq;
    
     using CMS.DataEngine;
     using CMS.ContactManagement;
    
     [assembly: RegisterDeleteContactsImplementation(
         "DeleteContactsCustom",
         "settingskey.om.deleteinactivecontacts.method.custom",
         typeof(DeleteContactsCustom))]
    
     /// <summary>
     /// Custom implementation for deleting inactive/unnecessary contacts.
     /// </summary>
     class DeleteContactsCustom : IDeleteContacts
     {
         /// <summary>
         /// Deletes contacts.
         /// </summary>
         /// <param name="days">The number of days specified in the settings. Use the parameter if you want to delete contacts older than this number of days.</param> 
         /// <returns>The number of contacts that haven't been deleted.</returns>
         public int Delete(int days, int batchSize)
         {
             var whereCondition = GetWhere();
             ContactInfoProvider.DeleteContactInfos(whereCondition, batchSize);
             return ContactInfoProvider.GetContacts().Where(whereCondition).Count();
         }
    
         /// <summary>
         /// Selects all contacts that do not have a 'ContactStateID' (are from outside the US).
         /// </summary>
         public string GetWhere()
         {
             var condition = new WhereCondition();
             condition.And(new WhereCondition().WhereEmpty("ContactStateID"));
             return condition.ToString(true);
         }
     }
    
    
     
  3. Save the file.

The customization is now available as a new option in Settings (application) -> On‑line marketing -> Contact management -> Inactive contacts.