Filter the analytics entity data returned by the Analytics data source before it is stored in the data warehouse.
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.
File: includes/classes/data-sources/WPDAI_Analytics_Data_Source.php
Context: When returning analytics data from the data source.
| 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 |
Type: array
The (possibly modified) analytics data structure.
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;
}