How can I collect a combination of metrics by the associated dimensions: country, impressions, clicks, ad_group_type, cost, and date?

108 views
Skip to first unread message

Chad Wood

unread,
Dec 14, 2022, 5:53:46 PM12/14/22
to Google Ads API and AdWords API Forum
Hello,

Here's my current query:

SELECT
....geographic_view.country_criterion_id,
....metrics.clicks,
....metrics.impressions,
....metrics.cost_micros,
....ad_group.type,
....segments.date
FROM
....geographic_view
WHERE
....segments.date BETWEEN '2022-12-01' AND '2022-12-01'

This produces the country_criterion_id, and I have no idea how to convert that to a country_id or country_name. I need the country_name, but a country_id will do fine.

By the way, the geo_target_constant resource is not compatible with ad_group.type. This is very important though, as the data needs paired with defaultChannelGrouping data from GA4. So I need both country and ad_group.type.

What is the solution here? Also getting campaign_name would be nice, but not required.

Thanks!

Chad Wood

unread,
Dec 14, 2022, 5:54:41 PM12/14/22
to Google Ads API and AdWords API Forum
Sorry, realizing I butchered my title. cost, impressions, and clicks are not dimensions.

Chad Wood

unread,
Dec 14, 2022, 6:05:08 PM12/14/22
to Google Ads API and AdWords API Forum
Just found this: campaign.advertising_channel_type
Any chance geo_target_constant is compatible with campaign?

I think I saw in a previous error that it is not. I'll give it a try though.

Chad Wood

unread,
Dec 14, 2022, 6:21:05 PM12/14/22
to Google Ads API and AdWords API Forum
By the way, here's a copy of the response I get. (I updated my query slightly)

[
....{
........'campaign': {
............'advertising_channel_type': 'DISPLAY',
............'name': 'Trix_Are_Not_For_Rabbits',
........},
........'metrics': {
............'clicks': '0',
............'cost_micros': '0',
............'impressions': '2'
.........},
........'segments': {
............'date': '2022-12-01'
........},
........'geographic_view': {
............'resource_name': 'customers/2972229294/geographicViews/2036~LOCATION_OF_PRESENCE',
............'country_criterion_id': '2036'
........}
....}
]

Here's what the ideal response would look like:
[
....{
........'campaign': {
............'advertising_channel_type': 'DISPLAY',
............'name': 'Trix_Are_Not_For_Rabbits',
........},
........'metrics': {
............'clicks': '0',
............'cost_micros': '0',
............'impressions': '2'
.............},
........'segments': {
............'date': '2022-12-01'
........},
........'geographic_view': {
............'canonical_name': 'FRANCE'
........}
....}
]

Notice it has the Channel, Country, Date, and 3 Metrics in there.

Chad Wood

unread,
Dec 14, 2022, 7:08:55 PM12/14/22
to Google Ads API and AdWords API Forum
Alright, found an answer worth a proof of concept:
https://developers.google.com/adwords/api/docs/appendix/geotargeting

Problem is, how stable is this?

Latest .csv (2022-09-14)

Previous .csv (2022-08-18)

In less than 30 days this CSV had two updates. Guess I'll need an API to query the data new every time it is needed?

Chad Wood

unread,
Dec 14, 2022, 7:11:44 PM12/14/22
to Google Ads API and AdWords API Forum
Apparently, that CSV only has the column I need for "legacy support". If that is the case, what is the newer solution?

Chad Wood

unread,
Dec 14, 2022, 7:36:28 PM12/14/22
to Google Ads API and AdWords API Forum
Okay I think this meets my needs: But is this the best way? It is very inefficient to need to download a CSV in order to figure this out.

import csv
import requests

CSV_URL = 'https://developers.google.com/static/adwords/api/docs/appendix/geo/geotargets-2022-09-14.csv'

with requests.Session() as s:
....download = s.get(CSV_URL)
....decoded_content = download.content.decode('utf-8')

....cr = csv.reader(decoded_content.splitlines(), delimiter=',')
....data = list(cr)
   
df = pd.DataFrame(my_list[1:], columns=my_list[0])
df.loc[df['Target Type']=='Country']

Google Ads API Forum Advisor

unread,
Dec 15, 2022, 1:20:39 AM12/15/22
to chadwo...@gmail.com, adwor...@googlegroups.com

Hi Chad, 

Thanks for reaching out to the Google Ads API Forum. I hope you are doing well today.

I understand that you have issues on how to convert country_id to country name. I will recommend to separate API request with the following query:

SELECT geo_target_constant.canonical_name,
geo_target_constant.country_code,
geo_target_constant.id,
geo_target_constant.name,
geo_target_constant.status,
geo_target_constant.target_type
FROM geo_target_constant
WHERE geo_target_constant.resource_name = 'geoTargetConstants/<<criterion ID>>'

It is true that the geo_target_constant resource is not compatible with ad_group.type. However, while using geographic_view report, you should be able to use ad_group report fields such as name, type etc as it is a segmented report.

In addition, to get name of campaign, you should be able to pull this using geographic_view report as campaign resource is segmented, and pulling campaign.name is possible. However,  is geo_target_constant report compatible with the campaign.

You should be able to use a sample GAQL for geographic_view here where campaign fields are added. Then a separate request to pull the canonical_name using geo_target_constant report.

With regards to this link, we do not have any Google Ads API service / method to download it so it is not recommended to use AdsWords API.

I hope it helps. Have a great day.

Regards,

Google Logo
Marjorie
Google Ads API Team
 


ref:_00D1U1174p._5004Q2h3Ar4:ref
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages