Hi Team,
I'm trying to pull the audience data at campaign level. However, i'm unable
to get the audience id and name from the below code
First Initial Query: SELECT campaign_criterion.user_list.user_list,
campaign.id, metrics.conversions, metrics.conversions_value,
metrics.impressions, metrics.cost_micros, metrics.ctr, metrics.clicks,
segments.date, campaign.name FROM campaign_audience_view WHERE
segments.date BETWEEN '2024-11-01' AND '2024-11-01' ORDER BY segments.date
DESC
code is:
if schema_key == "audience":
audience_resource_name =
row.campaign_criterion.resource_name.split("~")[1]
print("Extracted audience_resource_name:",
audience_resource_name)
audience_query = f"""
SELECT user_list.name, user_list.type
FROM user_list
WHERE user_list.resource_name =
'customers/{customer_id}/userLists/{audience_resource_name}'
"""
audience_request =
google_ads_client.get_type("SearchGoogleAdsRequest")
audience_request.customer_id = customer_id
audience_request.query = audience_query
try:
audience_response =
google_ads_service.search(audience_request)
print("Audience response type:",
type(audience_response))
print(audience_response)
audience_results = list(audience_response)
print(f"Number of results/pages:
{len(audience_results)}")
if not audience_results:
print("No results returned. Check your query or
permissions.")
for page in audience_results:
print("Processing page...")
for audience_row in page.results:
print("Audience Row:", audience_row)
audience_name = audience_row.user_list.name
audience_type = audience_row.user_list.type
print("Audience Name:", audience_name)
print("Audience Type:", audience_type)
except Exception as e:
print("Error fetching audience data:", e)
Response from the above code is:
Extracted audience_resource_name: 51668103655
INFO:google.ads.googleads.client:Request made: ClientCustomerId:
1234567890, Host: googleads.googleapis.com, Method:
/google.ads.googleads.v18.services.GoogleAdsService/Search, RequestId:
-VCpxQwbpw_NyJIjkMxWSw, IsFault: False, FaultMessage: None
Audience response type: <class
'google.ads.googleads.v18.services.services.google_ads_service.pagers.SearchPager'>
SearchPager<field_mask {
paths: "user_list.name"
paths: "user_list.type"
}
>
I'm audience able to get the criterion id which is 51668103655. However,
i'm unable to get the audience name, type and it is saying like
SearchPager<field_mask {
paths: "user_list.name"
paths: "user_list.type"
}
Please help me on how to acheive this.
--
CONFIDENTIALITY INFORMATION AND DISCLAIMER
This email message and its
attachments may contain confidential, proprietary or legally privileged
information and is intended solely for the use of the individual or entity
to whom it is addressed. If you have erroneously received this message,
please delete all copies of it immediately and notify the sender. If you
are not the intended recipient of the email message you should not
disseminate, distribute or copy this e-mail. E-mail transmission cannot be
guaranteed to be secure or error-free as information could be intercepted,
corrupted, lost, destroyed, incomplete or contain viruses and NetElixir
accepts no liability for any damage caused by the limitations of the e-mail
transmission. Thank you for your cooperation.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 visit
https://groups.google.com/d/msgid/adwords-api/323d253a-e6a1-4cfc-81a7-1fc1aa9d3182n%40googlegroups.com.