Accessing impressions of individual headlines in Responsive Search Ads

245 views
Skip to first unread message

Sriram Sekhar

unread,
Apr 2, 2023, 1:22:46 PM4/2/23
to Google Ads API and AdWords API Forum
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

Google Ads API Forum Advisor

unread,
Apr 3, 2023, 6:59:59 AM4/3/23
to sri...@capitalc.agency, adwor...@googlegroups.com

Hi Sriram,

I'm from the Google Ads API team. I hope you're doing well.

Based on our documentation, the ad_group_ad.ad.responsive_search_ad.headlines field returns a list of text assets for headlines which is why the API is returning an iterable. Can you please confirm if my understanding is correct that you're trying to retrieve metrics for individual headlines from this list? If yes, are you able to provide a UI screenshot wherein this is possible? I'm asking as the API is only supposed to mirror the behavior of the UI. You may send it to us via Reply privately to author option.

Regards,

Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2kES8g:ref
Reply all
Reply to author
Forward
0 new messages