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, 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.

Configuring automatic contact deletion

You can configure automatic contact deletion for individual sites in the Settings application.

  1. Open Settings (application) -> On‑line marketing -> Contact management -> Inactive contacts.
  2. Select one of the deletion options:
  3. 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 on the site, the system considers the date of their creation as the last time they were active.
  4. 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.

Note that task does not delete global contacts.

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.OnlineMarketing;
     using CMS.SiteProvider;
    
     [assembly: RegisterDeleteContactsImplementation(
         "DeleteContactsCustom",
         "settingskey.om.deleteinactivecontacts.method.custom",
         typeof(DeleteContactsCustom))]
    
     /// <summary>
     /// Custom implementation for deleting inactive/unnecessary contacts on a site.
     /// </summary>
     class DeleteContactsCustom : IDeleteContacts
     {
         /// <summary>
         /// Deletes contacts on a specific site.
         /// </summary>
         /// <param name="site">The site on which the contacts are deleted.</param>
         /// <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(SiteInfo site, int days, int batchSize)
         {
             if (site == null)
             {
                 throw new ArgumentNullException("site");
             }
             var whereCondition = GetWhere(site);
             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) on a specific site.
         /// </summary>
         public string GetWhere(SiteInfo site)
         {
             var condition = new WhereCondition();
             condition.And(new WhereCondition().WhereEmpty("ContactStateID"));
             condition.And(new WhereCondition().WhereEquals("ContactSiteID", site.SiteID));
             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.