geographic_view, report with python library

237 views
Skip to first unread message

jubap...@gmail.com

unread,
Apr 28, 2022, 5:52:58 PM4/28/22
to Google Ads API and AdWords API Forum
Hello, I am tried to clone date range geographic view report by python 
But when I want to segments city, county, (province, canton, state) at the same time, It will return an empty file.I can only segment by city and county.
Is there a way to query city county sate level at the same time? And also showing the name of the city, the name of the sate. not the id.

thanks


sample code is below:

ga_service = client.get_service("GoogleAdsService")
    # GAQL query create
    query = """
        SELECT segments.geo_target_city,
            geographic_view.country_criterion_id,
            segments.geo_target_region,
            metrics.impressions,
            campaign.name,
            campaign.id,
            ad_group.name,
            metrics.clicks,
            metrics.cost_micros,
            metrics.conversions,
            metrics.conversions_value
        FROM geographic_view
        WHERE segments.date BETWEEN '"""  + start_date + """' AND '""" + end_date + """'
    """
   
    # name of the city (not id)
   
    # create empty data frame
    # igonre metro as this time
    column_names = ['City',
                'Country/Territory',
                'segments.geo_target_region',
                'Impressions',
                'Campaign',
                'Campaign ID',
                'Ad group',
                'Clicks',
                'Cost',
                'Conversions',
                'Total conv. value']

    df = pd.DataFrame(columns = column_names)
                                   
    # Issues a search request using streaming.
    search_request = client.get_type("SearchGoogleAdsStreamRequest")
    search_request.customer_id = customer_id
    search_request.query = query
    stream = ga_service.search_stream(search_request)
    query_lists = []
    for batch in stream:
        #print(batch)
        for row in batch.results:
            geographic_view = row.geographic_view
            segments = row.segments
            campaign = row.campaign
            metrics = row.metrics
            ad_group = row.ad_group
           
            query_list = [segments.geo_target_city,
                         
            geographic_view.country_criterion_id,
                          segments.geo_target_region,
                          segments.geo_target_canton,
            metrics.impressions,
            campaign.name,
            campaign.id,
            ad_group.name,
            metrics.clicks,
            metrics.cost_micros,
            metrics.conversions,
            metrics.conversions_value]
            query_lists.append(query_list)

    df = pd.DataFrame(np.array(query_lists), columns=column_names)

Google Ads API Forum Advisor

unread,
May 3, 2022, 3:01:19 AM5/3/22
to jubap...@gmail.com, adwor...@googlegroups.com

Hello,

 

I'm Kevin from the Google Ads API Team.

 

Can you please provide the complete request and response logs with request ID so we can take a closer look at the issue? If you haven't enabled detailed logging yet for the Python client library, you may check out this link for the guide. You may send the requested information via Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

 

Regards,

Google Logo
Kevin Gil
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aOgUY:ref

jubap...@gmail.com

unread,
May 3, 2022, 12:26:32 PM5/3/22
to Google Ads API and AdWords API Forum
thank you I had send an e-mail to googleadsa...@google.com.

Google Ads API Forum Advisor

unread,
May 4, 2022, 12:54:50 PM5/4/22
to jubap...@gmail.com, adwor...@googlegroups.com
Hi Juba,

Thank you for providing the requested details privately. Let's continue our conversation on the other thread you've created where you send the requested information already checked this and will provide a helpful solution there.

Thanks,
Google Logo
Nirmita
Google Ads API Team
 


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