Skip to main content

benecaster_after_analytics_prune

Action Premium

Fires after an analytics prune run completes, with per-table deletion counts and elapsed time. Fires from both the nightly cron run and manual ‘Prune now’ operations. Does not fire when a run is aborted by the benecaster_analytics_prune_skip filter.

Use this hook to log completion metrics, alert a monitoring system when row counts are unexpectedly large, or trigger a downstream data sync after aged rows are removed.

Parameters

Name Type Default Description
$source string One of 'cron' or 'manual'
$result array Result object: {tables: {dataset: rows_deleted}, elapsed_ms: int} — the `tables` keys are opaque internal dataset identifiers; iterate them rather than hard-coding any one

Examples

Log prune summary to error log

add_action( 'benecaster_after_analytics_prune', function ( string $source, array $result ): void {
    $total_deleted = array_sum( $result['tables'] );

    if ( $total_deleted > 0 ) {
        error_log( sprintf(
            '[Benecaster] Analytics prune complete — source=%s deleted=%d elapsed=%dms',
            $source,
            $total_deleted,
            $result['elapsed_ms']
        ) );
    }
}, 10, 2 );

Notes

All deletions have already been committed when this action fires — it is an observation point only. A table count of 0 means no rows in that table fell outside the retention window during this run; this is not an error. The elapsed_ms value is useful for performance monitoring in environments with large analytics datasets.

Need this built rather than just documented? See our services →