segments not working

130 views
Skip to first unread message

Mason Digital

unread,
Jan 10, 2020, 2:17:33 PM1/10/20
to AdWords API and Google Ads API Forum
Using v2 of Google Ads API

I cannot get any segments other than segments.date to return any data/not give me an error. Below is an example using segments.conversion_action_name
I also want to pull data with segments.geo_target_most_specific_location and that does not seem to be working either. Am I not following this correctly?


def main(client, customer_id, page_size):
    ga_service = client.get_service('GoogleAdsService', version='v2')

    query = ('SELECT campaign.name, segments.date, segments.conversion_action_name, metrics.impressions, metrics.clicks, metrics.cost_micros, metrics.phone_calls, metrics.all_conversions FROM campaign WHERE segments.date BETWEEN \'2020-01-01\' AND \'2020-01-05\' '
             'ORDER BY campaign.name')

    results = ga_service.search(customer_id, query=query, page_size=page_size)

Google Ads API Forum Advisor Prod

unread,
Jan 10, 2020, 4:27:40 PM1/10/20
to repo...@masondigital.com, adwor...@googlegroups.com

Hi Mason,

Thanks for reaching out to us. Could you please confirm if my understanding is correct that you’re not receiving errors, but the report query you run in python does not return any data? If so, could you please first check on your end if the data you’re trying to query exists in the Google Ads UI? If the data does not exist in your account in the UI then it will not appear in the report. Please let me know if you run into further issues.

Thank you,
Bryan, Google Ads API Team

ref:_00D1U1174p._5001USw6xe:ref

Mason Digital

unread,
Jan 10, 2020, 5:13:19 PM1/10/20
to AdWords API and Google Ads API Forum
Thanks for responding.

No if I add any other segments like the above example where I included segments.conversion_action_name to the FROM clause I receive an error using the Python client library.

Request made: ClientCustomerId: ((MYCLIENTIDISHERE)), Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v2.services.GoogleAdsService/Search, RequestId: None, IsFault: True, FaultMessage: None
Traceback (most recent call last):
  File "get_ads.py", line 70, in <module>
    main(google_ads_client, "4431704982", _DEFAULT_PAGE_SIZE)
  File "get_ads.py", line 43, in main
    for row in results:
  File "/usr/local/lib/python3.7/site-packages/google/api_core/page_iterator.py", line 212, in _items_iter
    for page in self._page_iter(increment=False):
  File "/usr/local/lib/python3.7/site-packages/google/api_core/page_iterator.py", line 243, in _page_iter
    page = self._next_page()
  File "/usr/local/lib/python3.7/site-packages/google/api_core/page_iterator.py", line 534, in _next_page
    response = self._method(self._request)
  File "/usr/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
    on_error=on_error,
  File "/usr/local/lib/python3.7/site-packages/google/api_core/retry.py", line 184, in retry_target
    return target()
  File "/usr/local/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 222, in __call__
    compression=compression)
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 257, in _with_call
    return call.result(), call
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 126, in result
    raise self._exception
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 248, in continuation
    compression=new_compression)
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 272, in with_call
    compression=compression)
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 257, in _with_call
    return call.result(), call
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 126, in result
    raise self._exception
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 248, in continuation
    compression=new_compression)
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 272, in with_call
    compression=compression)
  File "/usr/local/lib/python3.7/site-packages/grpc/_interceptor.py", line 256, in _with_call
    continuation, client_call_details, request)
  File "/usr/local/lib/python3.7/site-packages/google/ads/google_ads/interceptors/exception_interceptor.py", line 139, in intercept_unary_unary
    self._handle_grpc_failure(response)
  File "/usr/local/lib/python3.7/site-packages/google/ads/google_ads/interceptors/exception_interceptor.py", line 105, in _handle_grpc_failure
    google_ads_failure = self._get_google_ads_failure(trailing_metadata)
  File "/usr/local/lib/python3.7/site-packages/google/ads/google_ads/interceptors/exception_interceptor.py", line 68, in _get_google_ads_failure
    ga_failure = error_protos.errors_pb2.GoogleAdsFailure()
AttributeError: module 'google.ads.google_ads.v2.proto.errors' has no attribute 'errors_pb2'

Mason Digital

unread,
Jan 13, 2020, 10:28:45 AM1/13/20
to AdWords API and Google Ads API Forum
I figured it out, thanks for your help.

I was querying the wrong report objects. Didn't realize there was another layer. Also Phone_Calls is a metric that cannot be extracted at the user-location level.


On Friday, January 10, 2020 at 4:27:40 PM UTC-5, adsapiforumadvisor wrote:

Max Khlystov

unread,
Jan 29, 2020, 11:04:28 AM1/29/20
to AdWords API and Google Ads API Forum
Could you provide which layer you are currently using ?

понедельник, 13 января 2020 г., 18:28:45 UTC+3 пользователь Mason Digital написал:
Reply all
Reply to author
Forward
0 new messages