Filter: wpd_alpha_insights_data_source_google_campaigns
Filter the Google Ads (google_campaigns) entity data returned by the Google Campaigns data source before it is stored in the data warehouse.
Description
After the Google Campaigns data source builds its data (totals, data_by_date, categorized_data, etc.), this filter is applied. You can modify campaign metrics or add custom keys. The data warehouse then stores the returned value for the google_campaigns entity. Requires Google Ads integration setup.
Location
File: includes/classes/data-sources/pro/WPDAI_Google_Campaigns_Data_Source.php
Context: When returning Google campaigns data from the data source.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $google_campaign_data | array | Google campaigns data structure (totals, data_by_date, categorized_data, total_db_records, etc.) |
| $data_warehouse | WPDAI_Data_Warehouse | The data warehouse instance |
Return
Type: array
The (possibly modified) google_campaigns data structure.
Example Usage
Add a derived metric
add_filter( 'wpd_alpha_insights_data_source_google_campaigns', 'add_google_roas_metric', 10, 2 );
function add_google_roas_metric( $google_campaign_data, $data_warehouse ) {
if ( isset( $google_campaign_data['totals'] ) && is_array( $google_campaign_data['totals'] ) ) {
$spend = $google_campaign_data['totals']['total_ad_spend'] ?? 0;
$revenue = $google_campaign_data['totals']['total_conversion_value'] ?? 0;
$google_campaign_data['totals']['roas'] = $spend > 0 ? $revenue / $spend : 0;
}
return $google_campaign_data;
}
Related
- wpd_alpha_insights_data_source_facebook_campaigns – Facebook campaigns data