Filter: wpd_alpha_insights_data_source_analytics
Filter the analytics entity data returned by the Analytics data source before it is stored in the data warehouse.
Description
After the analytics data source builds its data (events, sessions, totals, data_by_date, etc.), this filter is applied. You can modify metrics, add derived fields, or alter the structure. The data warehouse then stores the returned value for the analytics entity.
Location
File: includes/classes/data-sources/WPDAI_Analytics_Data_Source.php
Context: When returning analytics data from the data source.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $analytics_data | array | Analytics data structure (totals, data_by_date, data_table, total_db_records, etc.) |
| $data_warehouse | WPDAI_Data_Warehouse | The data warehouse instance |
Return
Type: array
The (possibly modified) analytics data structure.
Example Usage
Inject a custom metric
add_filter( 'wpd_alpha_insights_data_source_analytics', 'add_analytics_custom_metric', 10, 2 );
function add_analytics_custom_metric( $analytics_data, $data_warehouse ) {
if ( isset( $analytics_data['totals'] ) && is_array( $analytics_data['totals'] ) ) {
$analytics_data['totals']['custom_events_count'] = 0; // Compute from your logic
}
return $analytics_data;
}
Related
- wpd_ai_analytics_data_fetch_batch_size – Analytics batch size
- wpd_ai_session_data_chunk_size – Session chunk size