Hi all,
I am currently working on a Python script to fetch the impressions of
individual headlines in Responsive Search Ads (RSAs) using the Google Ads
API. However, I am facing an issue with the current implementation as the
headlines are returned as an iterable variable, while the impressions are
row-level variables.
Here's the code snippet that I've been working with:
def get_rsas_headlines_and_impressions(client, customer_id):
client = GoogleAdsClient.load_from_storage(path="google-ads.yaml")
ga_service = client.get_service("GoogleAdsService")
query = '''
SELECT
ad_group_ad.ad.responsive_search_ad.headlines,
metrics.impressions
FROM ad_group_ad_asset_view
WHERE
ad_group_ad_asset_view.field_type IN ('HEADLINE')
AND ad_group_ad.ad.type = 'RESPONSIVE_SEARCH_AD'
ORDER BY metrics.impressions DESC
'''
ga_search_request = client.get_type("SearchGoogleAdsRequest")
ga_search_request.customer_id = customer_id
ga_search_request.query = query
ga_search_request.page_size = _DEFAULT_PAGE_SIZE
response = ga_service.search(request=ga_search_request)
rsa_headlines_impressions = []
for row in response:
# Loop through the headlines and get the text
headlines = []
if row.ad_group_ad.ad.responsive_search_ad.headlines:
for headline in
row.ad_group_ad.ad.responsive_search_ad.headlines:
headlines.append(headline.text)
impressions = row.metrics.impressions
rsa_headlines_impressions.append({
"headline": headlines,
"impressions": impressions
})
return rsa_headlines_impressions
The only way I am able to access the headlines object is by iterating
through it, otherwise it throws an error:"Object of type RepeatedComposite
is not JSON serializable" . The issue with this implementation is that I am
unable to fetch the impressions for each individual headline within the
RSA. The current code retrieves impressions at the row level, and headlines
are returned as an iterable variable. As a result, the impressions are
attributed to the entire asset, rather than each individual headline.
Is there a way to modify the GAQL query or the code to access the
impressions of individual headlines within a Responsive Search Ad? Any
guidance or code snippets would be greatly appreciated.
Thanks in advance for your help!
Sriram
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/37308df6-429c-4704-b7ff-f73d1d384baen%40googlegroups.com.