Setting up automatic deletion of contacts
Enterprise license required
Features described on this page require the Kentico Xperience Enterprise 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.
- Open the Settings application.
- Navigate to the On‑line marketing -> Contact management -> Inactive contacts category in the settings tree.
- Select one of the deletion options:
- Delete contacts who were not active for the last X days
- Delete contacts without an email address that were not active for the last X days
- Or create your own custom contact deletion configuration
- 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.
- 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 adding and registering a custom implementation of the IDeleteContacts interface:
Important: Add the custom class to your Xperience administration project (not the MVC live site project). The class is used when executing the Delete inactive contacts scheduled task, which is done by the administration application.
Create a class that implements the IDeleteContacts interface (we recommend adding the class within a custom Code Library).
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 value filled in for the ContactStateID field.
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> public 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 ContactInfo.Provider.Get().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); } }
Register the class using the RegisterDeleteContactsImplementation attribute.
The customization is now available as a new option in Settings (application) -> On‑line marketing -> Contact management -> Inactive contacts.