Google Ads Get Campaign ads spends based on date and all states of USA
I have many campaigns and I want to summarize the spends by all the states (USA states) and based on from and to dates.
I went through the https://developers.google.com/google-ads/api/docs/reporting/overview but I dont see any point that can determine the spends based on states.
Which endpoint I need to use in Google Ads API: In the FB I am using https://graph.facebook.com/v13.0/act_2264578877108750/insights?access_token=<ACCESS_TOKEN>&fields=spend&breakdowns=region%2Ccountry&level=ad&time_range=%7B%27since%27%3A%272022-05-15%27%2C%27until%27%3A%272022-05-15%27%7D&limit=100&after=OTkZD
Any help is really appreciated.
Reporting in the Ads API works by defining a query in GAQL that describes the data you want to obtain. For your use case, a possible query would look something like this:
SELECT campaign.name, segments.geo_target_state, metrics.cost_micros FROM geographic_view WHERE geographic_view.location_type = LOCATION_OF_PRESENCE AND segments.date BETWEEN 20220101 AND 20220430This will return rows for every combination of campaign name and state with the respective spend, while the WHERE clause makes sure that the use actually was in that state when the click happened—as opposed to somebody being interested in it.
Note that segments.geo_target_state will be returned as an ID, you can find the reference data here. Additionally, metrics.cost_micros will be returned in millionth of the base currency of the accounts, i.e. you'll need to multiply the value by 1'000'000.
About which endpoint to use: REST isn't recommended by Google (you should rather be using gRPC via a client library), but this here should work:
curl "https://googleads.googleapis.com/v10/customers/${CUSTOMER_ID}/googleAds:searchStream" \ --header "Content-Type: application/json" \ --header "developer-token: ${DEVELOPER_TOKEN}" \ --header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \ --header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \ --data '{ "query": " SELECT campaign.name, segments.geo_target_state, metrics.cost_micros FROM geographic_view WHERE geographic_view.location_type = LOCATION_OF_PRESENCE AND segments.date BETWEEN 20220101 AND 20220430 " }'Thank you so much @dorian, Is there a way to combine this SELECT geo_target_constant.name, geo_target_constant.canonical_name FROM geo_target_constant WHERE geo_target_constant.id = to the above query?
There's no way to do joins directly in GAQL, if that's what you're asking. You'll have to do separate queries and match the values client-side.
Thanks @dorian I owe you more than just Thanks.
@CodeGuy Accepting the answer would be plenty thanks enough :)
I am so sorry for that, I didnt realize it until you reminded me. Thank you