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

Skip to content

Added 2 Important Examples for New Feature Budget Recommendations #905

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 6 commits into from
Mar 19, 2025

Conversation

fblascogarma
Copy link
Contributor

I've added 2 important examples of the new feature Budget Recommendations, which was launched in Google Ads API v18.

I've iterated based on Laura's feedback (@laurachevalier4 ). I had to create a new PR and I closed the previous one (#904 ).

If you have feedback, please let me know and I can work on the changes, but don't change the PR as it complicates things on my end. Thanks!

@fblascogarma fblascogarma requested a review from a team as a code owner February 7, 2025 22:00
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
"""
# Start Recommendation Service.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesn't add value, can you remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

# Start Recommendation Service.
recommendation_service = client.get_service("RecommendationService")

# Build Request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

request.positive_locations_ids = [2840] # 2840 is for United States
request.asset_group_info = [{ "final_url": "https://www.your-company.com/" }]

# Send Request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!


# Get budget recommendations with their associated impact metrics.
for rec in recommendations:
if hasattr(rec, 'campaign_budget_recommendation'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check actually necessary, if you're only generating CAMPAIGN_BUDGET recommendations?
I think it might be helpful to keep it regardless, for the sake of example, but if it's not necessary here I'd comment it out and add an explanation like "Check whether this is a campaign budget recommendation. This isn't needed when we're only generating recommendations of a single type, but it demonstrates how you could check on the recommendation type when generating recommendations of multiple types."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it's possible that the API responds with no recommendations. We don't know how often this happens, but it's a possibility. It happens. That's why I'm checking here if there are budget recommendations.
I'll add a comment above the "if" saying "Check if the API responded with recommendations".
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the case, wouldn't recommendations itself be empty?

# limitations under the License.
"""This example is to get impact metrics for a custom budget.

Use this example to get impact metrics for a budget amount during campaign creation workflows.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "for a given budget amount"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

from google.ads.googleads.errors import GoogleAdsException


def main(client, customer_id, budget_amount_user):
Copy link
Contributor

Choose a reason for hiding this comment

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

budget_amount_user is a little bit of a confusing variable name, to me. Can we just say "budget_amount"? Or if you feel like it needs to be said that it's a user value, "user_provided_budget_amount"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, good suggestion. I'll change it to "user_provided_budget_amount" so it's clearer.

Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
budget_amount_user: a budget amount (not in micros) advertiser wants to use.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the description to "a user-provided budget amount (not in micros), to retrieve impact metrics for."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

customer_id: a client customer ID.
budget_amount_user: a budget amount (not in micros) advertiser wants to use.
"""
# Start Recommendation Service.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove the comments I pointed out in the other example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely!

BenRKarl
BenRKarl previously approved these changes Mar 7, 2025
This example uses the following:
1) Performance Max for the campaign type
2) United States for the geo targeting
3) Maximize Conversions Value for the bidding strategy
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Conversion (no s)

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!

budget_recommendations_list.append(budget_data)
budget_amounts.append(round((budget_amount/1000000), 2))
else:
print("campaign_budget_recommendation not found for this account.")
Copy link
Contributor

@laurachevalier4 laurachevalier4 Mar 12, 2025

Choose a reason for hiding this comment

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

Related to my other comment: the if statement is at the recommendation level. But in theory, if there are no recommendations, wouldn't we not even get to the if/else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. The object will be empty if there's not recommendation, so we can skip the if/else altogether. Thanks!!

Copy link
Contributor

@laurachevalier4 laurachevalier4 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 few additional comments that need to be addressed before I can approve! Thanks for making the updates so far, it's already much more readable from my perspective.

print(f"budget_impact_metrics:\n{budget_impact_metrics}")
"""
budget_impact_metrics:
[{'budget_amount': 100.0, 'potential_metrics': cost_micros: 700000000
Copy link
Contributor

@laurachevalier4 laurachevalier4 Mar 18, 2025

Choose a reason for hiding this comment

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

should 'potential_metrics' be a nested dict here? Or is this how it gets printed?
On that note, I recommend running these examples once more (if you haven't already) to make sure it's working as expected!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how it gets printed. And yes, I run final tests for both examples after all the edits and it works like a charm! hahah

print(f"budget_recommendations_list:\n{budget_recommendations_list}")
"""
budget_recommendations_list:
[{'budget_amount': 44.56, 'potential_metrics': cost_micros: 311920000
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as in the other file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same answer as in the other. That's how it gets printed, and I ran tests for both examples after all the edits and works perfectly

@BenRKarl BenRKarl merged commit 6b13083 into googleads:main Mar 19, 2025
1 check passed
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.

3 participants