Hi support team,
As in the image below, I am trying to set the daily budget based on the budget left and the day left dynamically.
Is there an easy way to get the Cost within spending limit or Budget left for a campaign?
Currently, I do it in this way:
1. get the start_date of a campaign
2. query the metrics.cost_micros from start_date until today
query = f"""
SELECT
campaign_budget.amount_micros,
campaign_budget.total_amount_micros,
metrics.cost_micros,
FROM
campaign_budget
WHERE
AND segments.date = '{input_date}'
"""
3. Because metrics.cost_micros is the "served cost" I have to calculate the real cost like this: real_cost = min(metrics.cost_micros, 2*campaign_budget.amount_micros)
4. Sum the real_cost in every day up as the "Cost within spending limit".
But in this way, there is a bug.
Google query campaign_budget.amount_micros always returns the current daily_budget value, even the segments.date set on another day.
E.g. in the image below, on Oct, 26, 2021, the campaign_budget.amount_micros should be 850000, but the return value is amount_micros: 1220000 even the segments.date = '2021-10-25'.
1220000 is the current daily_budget.
In summary there are 1 question and 1 issue to report:
1. How to get the budget left or cost within spending limit easily?
2. There is a potential bug when query campaign_budget.amount_micros. The return value is different from the value on segments.date date
Looking forward to your response.
Thank you!
Haiyang