Skip to content
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

Rename get product category constants #474

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 0 additions & 120 deletions examples/recommendations/apply_recommendation.rb

This file was deleted.

64 changes: 50 additions & 14 deletions examples/recommendations/detect_and_apply_recommendations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@ def detect_and_apply_recommendations(customer_id)
client = Google::Ads::GoogleAds::GoogleAdsClient.new

query = <<~QUERY
SELECT recommendation.resource_name
SELECT recommendation.resource_name, recommendation.campaign,
recommendation.keyword_recommendation
Copy link
Member

Choose a reason for hiding this comment

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

Can we put one field per line?

FROM recommendation
WHERE recommendation.type = KEYWORD
LIMIT #{MAX_RESULT_SIZE}
QUERY

reccomendation_service = client.service.recommendation
google_ads_service = client.service.google_ads

NUMBER_OF_RUNS.times do |i|
search_response = google_ads_service.search(
customer_id: customer_id,
query: query,
page_size: PAGE_SIZE,
)
operations = search_response.map do |row|
client.operation.apply_recommendation do |aro|
aro.resource_name = row.recommendation.resource_name
end
end

unless operations.empty?
response = recommendation_service.apply_recommendation(
customer_id: customer_id,
operations: operations,
)
search_response.each do |row|
recommendation = row.recommendation

response.each do |result|
puts "Applied recommendation with resource name #{result.resource_name}."
puts "Keyword recommendation ('#{recommendation.resource_name}') was found for "\
"campaign '#{recommendation.campaign}'."
if recommendation.keyword_recommendation
keyword = recommendation.keyword_recommendation.keyword
puts "\tKeyword = '#{keyword.text}'\n\ttype = '#{keyword.match_type}'"
end

apply_recommendation(client, customer_id, recommendation.resource_name)
end

if i < NUMBER_OF_RUNS - 1
Copy link
Member

Choose a reason for hiding this comment

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

Why does this still exist if we're reducing the number of runs to 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, ignore this changes!

Expand All @@ -70,10 +70,46 @@ def detect_and_apply_recommendations(customer_id)
end
end

# [START apply_recommendation]
def apply_recommendation(client, customer_id, recommendation_resource)
# If you have a recommendation_id instead of the resournce_name
Copy link
Member

Choose a reason for hiding this comment

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

typo in resource_name

# you can create a resource name from it like this:
# recommendation_resource =
# client.path.recommendation(customer_id, recommendation_id)

apply_recommendation_operation = client.operation.apply_recommendation
apply_recommendation_operation.resource_name = recommendation_resource

# Each recommendation type has optional parameters to override the recommended
# values. This is an example to override a recommended ad when a
# TextAdRecommendation is applied.
# For details, please read
# https://developers.google.com/google-ads/api/reference/rpc/google.ads.google_ads.v1.services#google.ads.google_ads.v1.services.ApplyRecommendationOperation
Copy link
Member

Choose a reason for hiding this comment

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

This link is a 404

#
# text_ad_parameters = client.resource.text_ad_parameters do |tap|
# tap.ad = client.resource.ad do |ad|
# ad.id = "INSERT_AD_ID_AS_INTEGER_HERE"
# end
# end
# apply_recommendation_operation.text_ad = text_ad_parameters

# Issues a mutate request to apply the recommendation.
recommendation_service = client.service.recommendation
response = recommendation_service.apply_recommendation(
customer_id: customer_id,
operations: [apply_recommendation_operation],
)
applied_recommendation = response.results.first

puts "Applied recommendation with resource name: '#{applied_recommendation.resource_name}'."
end
# [END apply_recommendation]

if __FILE__ == $0
MAX_RESULT_SIZE = 2
NUMBER_OF_RUNS = 3
NUMBER_OF_RUNS = 1
PERIOD_IN_SECONDS = 5
PAGE_SIZE = 1000

options = {}
# The following parameter(s) should be provided to run the example. You can
Expand Down
118 changes: 0 additions & 118 deletions examples/recommendations/get_text_ad_recommendations.rb

This file was deleted.