Skip to content

Commit e90b108

Browse files
fix(google-ads): fix campaign and keyword metrics returning invalid data format (#167)
- Wrap retrieve_campaign_metrics response in {"results": ...} to match the expected output schema (fixes ValidationError in production) - Apply the same fix to retrieve_keyword_metrics (same issue) - Default cost_micros to 0 instead of 1 when missing, preventing incorrect Return On Ad Spend calculations
1 parent 7035e1e commit e90b108

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

google-ads/google_ads.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def fetch_campaign_data(client, customer_id, date_ranges_input, campaign_type=No
231231
budget = row_dict.get('campaign_budget', {})
232232

233233
conversions_value = metrics.get('conversions_value', 0.0)
234-
cost_micros = metrics.get('cost_micros', 1)
234+
cost_micros = metrics.get('cost_micros', 0)
235235
cost = micros_to_currency(cost_micros)
236236

237237
roas = 0
@@ -444,7 +444,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):
444444
try:
445445
results = fetch_campaign_data(client, customer_id, date_ranges_input, campaign_type)
446446
logger.info("Successfully retrieved campaign data.")
447-
return ActionResult(data=results, cost_usd=0.00)
447+
return ActionResult(data={"results": results}, cost_usd=0.00)
448448
except Exception as e:
449449
logger.exception(f"Exception during campaign data retrieval: {str(e)}")
450450
raise
@@ -472,7 +472,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):
472472
try:
473473
results = fetch_keyword_data(client, customer_id, date_ranges_input, campaign_ids, ad_group_ids)
474474
logger.info("Successfully retrieved keyword data.")
475-
return ActionResult(data=results, cost_usd=0.00)
475+
return ActionResult(data={"results": results}, cost_usd=0.00)
476476
except Exception as e:
477477
logger.exception(f"Exception during keyword data retrieval: {str(e)}")
478478
raise

0 commit comments

Comments
 (0)