Data Deletion Best Practices

As your application expands, your data volume increases. Over time, obsolete events, outdated records, and raw drill data accumulate, silently increasing storage costs and cluttering your dashboard. Maintaining clean data is not just housekeeping; it affects performance, costs, and the reliability of analytics. 

This guide covers why data deletion is important, the options Countly offers, and how to implement each, whether through a user interface or scripts.

Why Data Deletion Matters

Here are the most common reasons teams choose to delete data in Countly:

  • Reduce storage costs: Raw event data and drill records grow continuously. Removing data you no longer need keeps your database lean and your infrastructure costs in check.
  • Improve dashboard performance: Excess data slows down queries. Cleaning up old or unused records improves load times and makes reports more responsive.
  • Remove clutter from the UI: Outdated event keys and view names remain visible in your dashboard even after they stop receiving data, making it harder to find what matters.
  • Prevent accidental re-use: Unused event keys that linger in your system can be unintentionally triggered again by a future SDK update or a misconfiguration.
  • Meet data retention policies: Many organizations have internal or regulatory requirements around how long user data is kept. Countly’s deletion tools make compliance easier.

Deletion Options in Countly

Countly provides three methods for data deletion, each targeting a different type of data and use case. Understanding the differences will help you choose the right approach.

Goal Method Affects Aggregated? Affects Drill? Removes Key from UI?
Reduce old event/view counts Clear Data Older Than X (UI) Yes No No
Auto-delete raw event data after X years TTL Indexes (Scripts) No Yes No
Fully remove unused event/view keys Deletion API or Custom Script Yes Yes Yes

Deletion Methods in Detail

Select a method below to see the full procedure, including what it does, where it deletes from, and how to use it.

Clear Data Older Than X (UI) TTL Indexes Deletion API or Script
What It Does

This is the easiest choice and needs no scripting. It removes aggregated data for Events and Views older than a time frame you choose. For example, 6 months or 1 year. Updates are immediately shown in the dashboard metrics.

This method only affects aggregated data (e.g., event counts, durations, unique users). It does not delete raw drill data, nor does it remove event or view keys from lists such as the Events Page or Data Manager.

What Happens After Deletion

After clearing old data, you will notice:

  • Reduced counts for events and views that had activity in the deleted time range.
  • A count of 0 for events or views that had no activity within the selected period.
  • Event and view keys remain visible in the dashboard. They are stored as metadata in separate collections and are not touched by this operation.

For example, if an event called "Login" had 800 total counts and you clear data older than 6 months, you might see the count drop to 500, because 300 of those events occurred more than 6 months ago.

Where It Deletes From

This option removes data from the following aggregated collections:

  • countly.events
  • countly.app_viewdata(APP_name)
How to Use It
  • Go to your Countly dashboard.
  • Navigate to Management > Applications.
  • Click on the ellipsis dots (...) on the upper right side:
  • Select your desired time range. 
  • Confirm the deletion.

Best Practice: Blocking Deleted Keys

After deleting an event or view key, it is strongly recommended to also block the deleted keys via Filtering Rules. This prevents the key from being re-ingested if it is accidentally triggered again by your application.

Without this step, Countly will automatically re-create the key in its metadata collections the next time an event with that name arrives, undoing your cleanup.

Lastly, we recommend performing data cleanup of unused events/views at the SDK level; this is essential when deleting keys due to a naming change or a deprecated feature, and it is important that old code paths cannot accidentally resurrect a deleted event/view.

Choosing the Right Method

Not sure which option to use? Here is a quick guide:

  • Use Clear Data Older Than X if you want a quick, UI-based way to reduce old event or view counts without touching raw data.
  • Use TTL Indexes if you want a hands-off, automated approach to managing raw drill data retention over the long term.
  • Use the Deletion API or custom script if you need to fully remove an event or view key from your system, including from the dashboard UI.
  • Combine methods for comprehensive cleanup: use the Deletion API or customer script to remove the key, and block it at the SDK level to prevent re-ingestion.

Related Resources

Was this page helpful?
Reach out to us for any other questions.
Helpful?

Looking for more Help?