Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 5 commits into from
May 1, 2025

Conversation

gunjankathuria01
Copy link
Contributor

Adding code snippets for Audience Insights APIs for Google Ads.

@gunjankathuria01 gunjankathuria01 requested a review from a team as a code owner April 24, 2025 21:21
@gunjankathuria01
Copy link
Contributor Author

Please review the change for Audience Insights API code samples

Copy link
Contributor

@BenRKarl BenRKarl left a 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")
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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
)

Copy link
Contributor Author

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line

Copy link
Contributor Author

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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")
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo!! Fixed

@BenRKarl BenRKarl merged commit 26b54d4 into googleads:main May 1, 2025
1 check passed
@gunjankathuria01 gunjankathuria01 deleted the add_audience_insights branch May 1, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants