'How to retrieve LabelIds and Labels using Google Ads API in Ad Peformance Reporting?
I am trying to create a report for Extended Text Ads using Google Ads API.
I was able to do this for my reporting using Adwords API whereby I selected labels and labelids in the columns field.
cols = [
'AccountDescriptiveName', 'AdGroupId', 'AdGroupName', 'AdGroupStatus',
'AdNetworkType2', 'AdType', 'CampaignId', 'CampaignName',
'CampaignStatus', 'Clicks', 'Conversions', 'Cost', 'CreativeFinalUrls',
'Description', 'ExpandedTextAdDescription2', 'HeadlinePart1',
'HeadlinePart2', 'ExpandedTextAdHeadlinePart3', 'Id', 'Impressions',
'LabelIds', 'Labels', 'Path1', 'Path2', 'Status'
]
sel = create_selector(
cols,
pred_fields=['Status', 'CampaignStatus', 'AdGroupStatus', 'AdNetworkType2', 'AdType'],
pred_operators=['EQUALS', 'EQUALS', 'EQUALS', 'EQUALS', 'EQUALS'],
pred_values=['ENABLED', 'ENABLED', 'ENABLED', 'SEARCH', 'EXPANDED_TEXT_AD'])
ads_df = get_report_as_df(
client,
selector=sel,
report_type='AD_PERFORMANCE_REPORT',
date_range_type='LAST_30_DAYS',
)
However, from what I understand the new GAQL approach requires using the ad_group_ad resource which does not have labelids and labelname inside? I know there is a ad_group_ad_label resource however, I am not sure how I can make use of it. Also https://developers.google.com/google-ads/api/docs/migration/mapping#ad_performance tells me that I should "Select label.resource_name from the resource ad_group_ad_label" but as GAQL queries only allow retrieval of one resource how do I go about it?
Currently I have these in my GAQL Query
SELECT
customer.descriptive_name,
ad_group.id,
ad_group.name,
ad_group.status,
ad_group_ad.ad.type,
campaign.id,
campaign.name,
campaign.status,
metrics.clicks,
metrics.conversions,
metrics.cost_micros,
ad_group_ad.ad.final_urls,
ad_group_ad.ad.expanded_text_ad.description,
ad_group_ad.ad.expanded_text_ad.description2,
ad_group_ad.ad.expanded_text_ad.headline_part1,
ad_group_ad.ad.expanded_text_ad.headline_part2,
ad_group_ad.ad.expanded_text_ad.headline_part3,
ad_group_ad.ad.id,
metrics.impressions,
ad_group_ad.ad.expanded_text_ad.path1,
ad_group_ad.ad.expanded_text_ad.path2,
ad_group_ad.status
FROM
ad_group_ad
WHERE
ad_group_ad.status = ENABLED
AND campaign.status = ENABLED
AND ad_group.status = ENABLED
AND ad_group_ad.ad.type = EXPANDED_TEXT_AD
Solution 1:[1]
I had the same problem just now. Found that if I select ad_group.labels
from ad_group
.
I can then use the labels returned from that query to lookup labels by resource name:
SELECT
label.id,
label.name
FROM label
WHERE
label.resource_name IN ('customers/111111/labels/111111', 'customers/2222222/labels/22222')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kurupt_89 |