-
Notifications
You must be signed in to change notification settings - Fork 500
Add code samples for audience insights APIs #932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add code samples for audience insights APIs #932
Conversation
Please review the change for Audience Insights API code samples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple comments, I'll continue reviewing after they're resolved.
request = client.get_type("GenerateAudienceCompositionInsightsRequest") | ||
request.customer_id = customer_id | ||
|
||
request.audience = client.get_type("InsightsAudience") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this line. You can set the request.audience
fields, as you do later in the example, without this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
customer_id, user_interest | ||
) | ||
user_interests_info.user_interest_category = user_interest_category | ||
attributes.user_interest = user_interests_info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this:
attributes = client.get_type("AudienceInsightsAttribute")
user_interests_info = client.get_type("UserInterestInfo")
user_interest_category = googleads_service.user_interest_path(
customer_id, user_interest
)
user_interests_info.user_interest_category = user_interest_category
attributes.user_interest = user_interests_info
Just do this:
attributes = client.get_type("AudienceInsightsAttribute")
attributes.user_interest.user_interest_category = googleads_service.user_interest_path(
customer_id, user_interest
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
insights_info.attributes.append(attributes) | ||
request.audience.topic_audience_combinations.append(insights_info) | ||
|
||
request.audience = client.get_type("InsightsAudience") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
request.customer_insights_group = custom_name | ||
|
||
audience_definition = client.get_type("InsightsAudienceDefinition") | ||
audience = client.get_type("InsightsAudience") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like this is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
request.customer_id = customer_id | ||
request.customer_insights_group = custom_name | ||
|
||
audience_definition = client.get_type("InsightsAudienceDefinition") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this line to:
audience_definition = request.audience_definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
kg_dimension = client.enums.AudienceInsightsDimensionEnum.KNOWLEDGE_GRAPH | ||
request.dimensions = [category_dimension, kg_dimension] | ||
request.customer_insights_group = custom_name | ||
response = audience_insights_service.list_audience_insights_attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to call the list_audience_insights_attributes
method, like this:
list_audience_insights_attributes(request=request)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo!! Fixed
Adding code snippets for Audience Insights APIs for Google Ads.