Skip to main content

benecaster_after_analytics_prune

Action Premium Since v1.0.0

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](/hooks/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: {table_name: rows_deleted}, elapsed_ms: int}

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 (events=%d daily=%d downloads=%d)',
            $source,
            $total_deleted,
            $result['elapsed_ms'],
            $result['tables']['benecaster_subscriber_events'],
            $result['tables']['benecaster_analytics_daily'],
            $result['tables']['benecaster_download_log']
        ) );
    }
}, 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.