google-adwords-api 0.21.0 → 0.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +5 -0
  3. data/examples/v201603/shopping_campaigns/add_product_scope.rb +3 -2
  4. data/examples/v201605/shopping_campaigns/add_product_scope.rb +3 -2
  5. data/examples/v201607/shopping_campaigns/add_product_scope.rb +3 -2
  6. data/examples/v201609/account_management/create_account.rb +88 -0
  7. data/examples/v201609/account_management/get_account_changes.rb +135 -0
  8. data/examples/v201609/account_management/get_account_hierarchy.rb +132 -0
  9. data/examples/v201609/advanced_operations/add_ad_customizers.rb +183 -0
  10. data/examples/v201609/advanced_operations/add_ad_group_bid_modifier.rb +101 -0
  11. data/examples/v201609/advanced_operations/add_click_to_download_ad.rb +148 -0
  12. data/examples/v201609/advanced_operations/add_expanded_text_ad_with_upgraded_urls.rb +132 -0
  13. data/examples/v201609/advanced_operations/add_html5_ad.rb +137 -0
  14. data/examples/v201609/advanced_operations/add_responsive_display_ad.rb +130 -0
  15. data/examples/v201609/advanced_operations/add_universal_app_campaign.rb +215 -0
  16. data/examples/v201609/advanced_operations/create_and_attach_shared_keyword_set.rb +141 -0
  17. data/examples/v201609/advanced_operations/find_and_remove_criteria_from_shared_set.rb +174 -0
  18. data/examples/v201609/advanced_operations/get_ad_group_bid_modifiers.rb +102 -0
  19. data/examples/v201609/advanced_operations/use_portfolio_bidding_strategy.rb +146 -0
  20. data/examples/v201609/basic_operations/add_ad_groups.rb +142 -0
  21. data/examples/v201609/basic_operations/add_campaigns.rb +138 -0
  22. data/examples/v201609/basic_operations/add_expanded_text_ads.rb +108 -0
  23. data/examples/v201609/basic_operations/add_keywords.rb +114 -0
  24. data/examples/v201609/basic_operations/get_ad_groups.rb +102 -0
  25. data/examples/v201609/basic_operations/get_campaigns.rb +97 -0
  26. data/examples/v201609/basic_operations/get_campaigns_with_awql.rb +89 -0
  27. data/examples/v201609/basic_operations/get_expanded_text_ads.rb +122 -0
  28. data/examples/v201609/basic_operations/get_keywords.rb +109 -0
  29. data/examples/v201609/basic_operations/get_text_ads.rb +109 -0
  30. data/examples/v201609/basic_operations/pause_ad.rb +87 -0
  31. data/examples/v201609/basic_operations/remove_ad.rb +89 -0
  32. data/examples/v201609/basic_operations/remove_ad_group.rb +85 -0
  33. data/examples/v201609/basic_operations/remove_campaign.rb +87 -0
  34. data/examples/v201609/basic_operations/remove_keyword.rb +94 -0
  35. data/examples/v201609/basic_operations/update_ad_group.rb +85 -0
  36. data/examples/v201609/basic_operations/update_campaign.rb +86 -0
  37. data/examples/v201609/basic_operations/update_keyword.rb +106 -0
  38. data/examples/v201609/campaign_management/add_campaign_labels.rb +82 -0
  39. data/examples/v201609/campaign_management/add_complete_campaigns_using_batch_job.rb +354 -0
  40. data/examples/v201609/campaign_management/add_draft.rb +113 -0
  41. data/examples/v201609/campaign_management/add_keywords_using_incremental_batch_job.rb +210 -0
  42. data/examples/v201609/campaign_management/add_trial.rb +141 -0
  43. data/examples/v201609/campaign_management/get_all_disapproved_ads.rb +97 -0
  44. data/examples/v201609/campaign_management/get_all_disapproved_ads_with_awql.rb +89 -0
  45. data/examples/v201609/campaign_management/get_campaigns_by_label.rb +108 -0
  46. data/examples/v201609/campaign_management/graduate_trial.rb +106 -0
  47. data/examples/v201609/campaign_management/set_ad_parameters.rb +118 -0
  48. data/examples/v201609/campaign_management/set_criterion_bid_modifier.rb +104 -0
  49. data/examples/v201609/campaign_management/validate_text_ad.rb +109 -0
  50. data/examples/v201609/error_handling/handle_partial_failures.rb +130 -0
  51. data/examples/v201609/error_handling/handle_policy_violation_error.rb +141 -0
  52. data/examples/v201609/extensions/add_google_my_business_location_extensions.rb +193 -0
  53. data/examples/v201609/extensions/add_prices.rb +162 -0
  54. data/examples/v201609/extensions/add_site_links.rb +199 -0
  55. data/examples/v201609/extensions/add_site_links_using_feeds.rb +286 -0
  56. data/examples/v201609/migration/migrate_to_extension_settings.rb +386 -0
  57. data/examples/v201609/misc/get_all_images_and_videos.rb +104 -0
  58. data/examples/v201609/misc/setup_oauth2.rb +84 -0
  59. data/examples/v201609/misc/upload_image.rb +93 -0
  60. data/examples/v201609/misc/upload_media_bundle.rb +90 -0
  61. data/examples/v201609/misc/use_oauth2_jwt.rb +93 -0
  62. data/examples/v201609/misc/use_runtime_config.rb +92 -0
  63. data/examples/v201609/optimization/estimate_keyword_traffic.rb +191 -0
  64. data/examples/v201609/optimization/get_campaign_criterion_bid_modifier_simulations.rb +128 -0
  65. data/examples/v201609/optimization/get_keyword_bid_simulations.rb +95 -0
  66. data/examples/v201609/optimization/get_keyword_ideas.rb +136 -0
  67. data/examples/v201609/remarketing/add_audience.rb +118 -0
  68. data/examples/v201609/remarketing/add_conversion_tracker.rb +97 -0
  69. data/examples/v201609/remarketing/add_crm_based_user_list.rb +116 -0
  70. data/examples/v201609/remarketing/add_rule_based_user_lists.rb +167 -0
  71. data/examples/v201609/remarketing/upload_offline_call_conversions.rb +111 -0
  72. data/examples/v201609/remarketing/upload_offline_conversions.rb +98 -0
  73. data/examples/v201609/reporting/download_criteria_report.rb +92 -0
  74. data/examples/v201609/reporting/download_criteria_report_with_awql.rb +93 -0
  75. data/examples/v201609/reporting/get_report_fields.rb +75 -0
  76. data/examples/v201609/reporting/parallel_report_download.rb +164 -0
  77. data/examples/v201609/reporting/stream_criteria_report_results.rb +97 -0
  78. data/examples/v201609/shopping_campaigns/add_product_partition_tree.rb +267 -0
  79. data/examples/v201609/shopping_campaigns/add_product_scope.rb +130 -0
  80. data/examples/v201609/shopping_campaigns/add_shopping_campaign.rb +129 -0
  81. data/examples/v201609/shopping_campaigns/get_product_category_taxonomy.rb +115 -0
  82. data/examples/v201609/targeting/add_campaign_targeting_criteria.rb +166 -0
  83. data/examples/v201609/targeting/add_demographic_targeting_criteria.rb +112 -0
  84. data/examples/v201609/targeting/get_campaign_targeting_criteria.rb +106 -0
  85. data/examples/v201609/targeting/get_targetable_languages_and_carriers.rb +89 -0
  86. data/examples/v201609/targeting/lookup_location.rb +108 -0
  87. data/lib/adwords_api/api_config.rb +96 -4
  88. data/lib/adwords_api/batch_job_utils.rb +6 -0
  89. data/lib/adwords_api/report_utils.rb +9 -4
  90. data/lib/adwords_api/v201609/account_label_service.rb +46 -0
  91. data/lib/adwords_api/v201609/account_label_service_registry.rb +46 -0
  92. data/lib/adwords_api/v201609/ad_customizer_feed_service.rb +46 -0
  93. data/lib/adwords_api/v201609/ad_customizer_feed_service_registry.rb +46 -0
  94. data/lib/adwords_api/v201609/ad_group_ad_service.rb +70 -0
  95. data/lib/adwords_api/v201609/ad_group_ad_service_registry.rb +46 -0
  96. data/lib/adwords_api/v201609/ad_group_bid_modifier_service.rb +54 -0
  97. data/lib/adwords_api/v201609/ad_group_bid_modifier_service_registry.rb +46 -0
  98. data/lib/adwords_api/v201609/ad_group_criterion_service.rb +62 -0
  99. data/lib/adwords_api/v201609/ad_group_criterion_service_registry.rb +46 -0
  100. data/lib/adwords_api/v201609/ad_group_extension_setting_service.rb +54 -0
  101. data/lib/adwords_api/v201609/ad_group_extension_setting_service_registry.rb +46 -0
  102. data/lib/adwords_api/v201609/ad_group_feed_service.rb +54 -0
  103. data/lib/adwords_api/v201609/ad_group_feed_service_registry.rb +46 -0
  104. data/lib/adwords_api/v201609/ad_group_service.rb +62 -0
  105. data/lib/adwords_api/v201609/ad_group_service_registry.rb +46 -0
  106. data/lib/adwords_api/v201609/ad_param_service.rb +46 -0
  107. data/lib/adwords_api/v201609/ad_param_service_registry.rb +46 -0
  108. data/lib/adwords_api/v201609/adwords_user_list_service.rb +62 -0
  109. data/lib/adwords_api/v201609/adwords_user_list_service_registry.rb +46 -0
  110. data/lib/adwords_api/v201609/batch_job_service.rb +54 -0
  111. data/lib/adwords_api/v201609/batch_job_service_registry.rb +46 -0
  112. data/lib/adwords_api/v201609/bidding_strategy_service.rb +54 -0
  113. data/lib/adwords_api/v201609/bidding_strategy_service_registry.rb +46 -0
  114. data/lib/adwords_api/v201609/budget_order_service.rb +54 -0
  115. data/lib/adwords_api/v201609/budget_order_service_registry.rb +46 -0
  116. data/lib/adwords_api/v201609/budget_service.rb +54 -0
  117. data/lib/adwords_api/v201609/budget_service_registry.rb +46 -0
  118. data/lib/adwords_api/v201609/campaign_criterion_service.rb +54 -0
  119. data/lib/adwords_api/v201609/campaign_criterion_service_registry.rb +46 -0
  120. data/lib/adwords_api/v201609/campaign_extension_setting_service.rb +54 -0
  121. data/lib/adwords_api/v201609/campaign_extension_setting_service_registry.rb +46 -0
  122. data/lib/adwords_api/v201609/campaign_feed_service.rb +54 -0
  123. data/lib/adwords_api/v201609/campaign_feed_service_registry.rb +46 -0
  124. data/lib/adwords_api/v201609/campaign_service.rb +62 -0
  125. data/lib/adwords_api/v201609/campaign_service_registry.rb +46 -0
  126. data/lib/adwords_api/v201609/campaign_shared_set_service.rb +54 -0
  127. data/lib/adwords_api/v201609/campaign_shared_set_service_registry.rb +46 -0
  128. data/lib/adwords_api/v201609/constant_data_service.rb +110 -0
  129. data/lib/adwords_api/v201609/constant_data_service_registry.rb +46 -0
  130. data/lib/adwords_api/v201609/conversion_tracker_service.rb +54 -0
  131. data/lib/adwords_api/v201609/conversion_tracker_service_registry.rb +46 -0
  132. data/lib/adwords_api/v201609/customer_extension_setting_service.rb +54 -0
  133. data/lib/adwords_api/v201609/customer_extension_setting_service_registry.rb +46 -0
  134. data/lib/adwords_api/v201609/customer_feed_service.rb +54 -0
  135. data/lib/adwords_api/v201609/customer_feed_service_registry.rb +46 -0
  136. data/lib/adwords_api/v201609/customer_service.rb +62 -0
  137. data/lib/adwords_api/v201609/customer_service_registry.rb +46 -0
  138. data/lib/adwords_api/v201609/customer_sync_service.rb +38 -0
  139. data/lib/adwords_api/v201609/customer_sync_service_registry.rb +47 -0
  140. data/lib/adwords_api/v201609/data_service.rb +94 -0
  141. data/lib/adwords_api/v201609/data_service_registry.rb +46 -0
  142. data/lib/adwords_api/v201609/draft_async_error_service.rb +46 -0
  143. data/lib/adwords_api/v201609/draft_async_error_service_registry.rb +46 -0
  144. data/lib/adwords_api/v201609/draft_service.rb +54 -0
  145. data/lib/adwords_api/v201609/draft_service_registry.rb +46 -0
  146. data/lib/adwords_api/v201609/feed_item_service.rb +54 -0
  147. data/lib/adwords_api/v201609/feed_item_service_registry.rb +46 -0
  148. data/lib/adwords_api/v201609/feed_mapping_service.rb +54 -0
  149. data/lib/adwords_api/v201609/feed_mapping_service_registry.rb +46 -0
  150. data/lib/adwords_api/v201609/feed_service.rb +54 -0
  151. data/lib/adwords_api/v201609/feed_service_registry.rb +46 -0
  152. data/lib/adwords_api/v201609/label_service.rb +54 -0
  153. data/lib/adwords_api/v201609/label_service_registry.rb +46 -0
  154. data/lib/adwords_api/v201609/location_criterion_service.rb +46 -0
  155. data/lib/adwords_api/v201609/location_criterion_service_registry.rb +46 -0
  156. data/lib/adwords_api/v201609/managed_customer_service.rb +78 -0
  157. data/lib/adwords_api/v201609/managed_customer_service_registry.rb +46 -0
  158. data/lib/adwords_api/v201609/media_service.rb +54 -0
  159. data/lib/adwords_api/v201609/media_service_registry.rb +46 -0
  160. data/lib/adwords_api/v201609/offline_call_conversion_feed_service.rb +38 -0
  161. data/lib/adwords_api/v201609/offline_call_conversion_feed_service_registry.rb +46 -0
  162. data/lib/adwords_api/v201609/offline_conversion_feed_service.rb +38 -0
  163. data/lib/adwords_api/v201609/offline_conversion_feed_service_registry.rb +46 -0
  164. data/lib/adwords_api/v201609/report_definition_service.rb +38 -0
  165. data/lib/adwords_api/v201609/report_definition_service_registry.rb +46 -0
  166. data/lib/adwords_api/v201609/shared_criterion_service.rb +54 -0
  167. data/lib/adwords_api/v201609/shared_criterion_service_registry.rb +46 -0
  168. data/lib/adwords_api/v201609/shared_set_service.rb +54 -0
  169. data/lib/adwords_api/v201609/shared_set_service_registry.rb +46 -0
  170. data/lib/adwords_api/v201609/targeting_idea_service.rb +38 -0
  171. data/lib/adwords_api/v201609/targeting_idea_service_registry.rb +46 -0
  172. data/lib/adwords_api/v201609/traffic_estimator_service.rb +38 -0
  173. data/lib/adwords_api/v201609/traffic_estimator_service_registry.rb +46 -0
  174. data/lib/adwords_api/v201609/trial_async_error_service.rb +46 -0
  175. data/lib/adwords_api/v201609/trial_async_error_service_registry.rb +46 -0
  176. data/lib/adwords_api/v201609/trial_service.rb +54 -0
  177. data/lib/adwords_api/v201609/trial_service_registry.rb +46 -0
  178. data/lib/adwords_api/version.rb +1 -1
  179. data/test/adwords_api/test_adwords_api.rb +1 -1
  180. data/test/adwords_api/test_api_config.rb +8 -8
  181. data/test/adwords_api/test_batch_job_utils.rb +2 -2
  182. data/test/adwords_api/test_choices.rb +2 -2
  183. data/test/adwords_api/test_report_stream.rb +1 -1
  184. data/test/adwords_api/test_report_utils.rb +1 -1
  185. data/test/templates/v201609/basic_operations_get_campaigns.def +116 -0
  186. data/test/templates/v201609/basic_operations_update_keyword.def +125 -0
  187. data/test/templates/v201609/misc_use_oauth2_jwt.def +131 -0
  188. metadata +174 -2
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Copyright:: Copyright 2015, Google Inc. All Rights Reserved.
5
+ #
6
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This example adds an ad customizer feed using Extension Services. Then it adds
20
+ # an ad that uses the feed to populate dynamic data.
21
+
22
+ require 'adwords_api'
23
+ require 'date'
24
+
25
+ def add_ad_customizers(feed_name, ad_group_ids)
26
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
27
+ # when called without parameters.
28
+ adwords = AdwordsApi::Api.new
29
+
30
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
31
+ # the configuration file or provide your own logger:
32
+ # adwords.logger = Logger.new('adwords_xml.log')
33
+
34
+ feed_item_srv = adwords.service(:FeedItemService, API_VERSION)
35
+ ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
36
+
37
+ # Create a customizer feed. One feed per account can be used for all ads.
38
+ feed_data = create_customizer_feed(adwords, feed_name)
39
+
40
+ # Now adding feed items -- the values we'd like to place.
41
+ now_date = Date.today()
42
+
43
+ items_data = [
44
+ {
45
+ :name => 'Mars',
46
+ :price => '$1234.56',
47
+ :date => now_date.strftime('%Y%m01 000000'),
48
+ :ad_group_id => ad_group_ids[0]
49
+ },
50
+ {
51
+ :name => 'Venus',
52
+ :price => '$1450.00',
53
+ :date => now_date.strftime('%Y%m15 000000'),
54
+ :ad_group_id => ad_group_ids[1]
55
+ }
56
+ ]
57
+
58
+ feed_items = items_data.map do |item|
59
+ {
60
+ :feed_id => feed_data[:feed_id],
61
+ :attribute_values => [
62
+ {
63
+ :feed_attribute_id => feed_data[:name_id],
64
+ :string_value => item[:name]
65
+ },
66
+ {
67
+ :feed_attribute_id => feed_data[:price_id],
68
+ :string_value => item[:price]
69
+ },
70
+ {
71
+ :feed_attribute_id => feed_data[:date_id],
72
+ :string_value => item[:date]
73
+ }
74
+ ],
75
+ :ad_group_targeting => {
76
+ :targeting_ad_group_id => item[:ad_group_id]
77
+ }
78
+ }
79
+ end
80
+
81
+ feed_items_operations = feed_items.map do |item|
82
+ {:operator => 'ADD', :operand => item}
83
+ end
84
+
85
+ response = feed_item_srv.mutate(feed_items_operations)
86
+ if response and response[:value]
87
+ response[:value].each do |feed_item|
88
+ puts 'Feed item with ID %d was added.' % feed_item[:feed_item_id]
89
+ end
90
+ else
91
+ raise new StandardError, 'No feed items were added.'
92
+ end
93
+
94
+ # All set! We can now create ads with customizations.
95
+ expanded_text_ad = {
96
+ :xsi_type => 'ExpandedTextAd',
97
+ :headline_part1 => 'Luxury Cruise to {=%s.Name}' % feed_name,
98
+ :headline_part2 => 'Only {=%s.Price}' % feed_name,
99
+ :description => 'Offer ends in {=countdown(%s.Date)}!' % feed_name,
100
+ :final_urls => ['http://www.example.com']
101
+ }
102
+
103
+ # We add the same ad to both ad groups. When they serve, they will show
104
+ # different values, since they match different feed items.
105
+ operations = ad_group_ids.map do |ad_group_id|
106
+ {
107
+ :operator => 'ADD',
108
+ :operand => {
109
+ :ad_group_id => ad_group_id,
110
+ :ad => expanded_text_ad.dup()
111
+ }
112
+ }
113
+ end
114
+
115
+ response = ad_group_ad_srv.mutate(operations)
116
+ if response and response[:value]
117
+ ads = response[:value]
118
+ ads.each do |ad|
119
+ puts "\tCreated an ad with ID %d, type '%s' and status '%s'" %
120
+ [ad[:ad][:id], ad[:ad][:ad_type], ad[:status]]
121
+ end
122
+ else
123
+ raise StandardError, 'No ads were added.'
124
+ end
125
+ end
126
+
127
+ def create_customizer_feed(adwords, feed_name)
128
+ ad_customizer_srv = adwords.service(:AdCustomizerFeedService, API_VERSION)
129
+ feed = {
130
+ :feed_name => feed_name,
131
+ :feed_attributes => [
132
+ {:name => 'Name', :type => 'STRING'},
133
+ {:name => 'Price', :type => 'PRICE'},
134
+ {:name => 'Date', :type => 'DATE_TIME'}
135
+ ]
136
+ }
137
+ operation = {:operand => feed, :operator => 'ADD'}
138
+ added_feed = ad_customizer_srv.mutate([operation])[:value].first()
139
+ puts "Created ad customizer feed with ID = %d and name = '%s'." %
140
+ [added_feed[:feed_id], added_feed[:feed_name]]
141
+ return {
142
+ :feed_id => added_feed[:feed_id],
143
+ :name_id => added_feed[:feed_attributes][0][:id],
144
+ :price_id => added_feed[:feed_attributes][1][:id],
145
+ :date_id => added_feed[:feed_attributes][2][:id]
146
+ }
147
+ end
148
+
149
+ if __FILE__ == $0
150
+ API_VERSION = :v201609
151
+
152
+ begin
153
+ feed_name = 'INSERT_FEED_NAME_HERE'.to_s
154
+ ad_group_ids = [
155
+ 'INSERT_AD_GROUP_ID_HERE'.to_i,
156
+ 'INSERT_AD_GROUP_ID_HERE'.to_i
157
+ ]
158
+ add_ad_customizers(feed_name, ad_group_ids)
159
+
160
+ # Authorization error.
161
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
162
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
163
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
164
+ "to retrieve and store OAuth2 tokens."
165
+ puts "See this wiki page for more details:\n\n " +
166
+ 'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
167
+
168
+ # HTTP errors.
169
+ rescue AdsCommon::Errors::HttpError => e
170
+ puts "HTTP Error: %s" % e
171
+
172
+ # API errors.
173
+ rescue AdwordsApi::Errors::ApiException => e
174
+ puts "Message: %s" % e.message
175
+ puts 'Errors:'
176
+ e.errors.each_with_index do |error, index|
177
+ puts "\tError [%d]:" % (index + 1)
178
+ error.each do |field, value|
179
+ puts "\t\t%s: %s" % [field, value]
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
5
+ #
6
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This example illustrates how to add an ad group level mobile bid modifier
20
+ # override for a campaign.
21
+
22
+ require 'adwords_api'
23
+
24
+ def add_ad_group_bid_modifier(ad_group_id, bid_modifier)
25
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
26
+ # when called without parameters.
27
+ adwords = AdwordsApi::Api.new
28
+
29
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
30
+ # the configuration file or provide your own logger:
31
+ # adwords.logger = Logger.new('adwords_xml.log')
32
+
33
+ bid_modifier_srv = adwords.service(:AdGroupBidModifierService, API_VERSION)
34
+
35
+ # Mobile criterion ID.
36
+ criterion_id = 30001
37
+
38
+ # Prepare to add an ad group level override.
39
+ operation = {
40
+ # Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
41
+ # modifier can be removed with the 'REMOVE' operator.
42
+ :operator => 'ADD',
43
+ :operand => {
44
+ :ad_group_id => ad_group_id,
45
+ :criterion => {
46
+ :xsi_type => 'Platform',
47
+ :id => criterion_id
48
+ },
49
+ :bid_modifier => bid_modifier
50
+ }
51
+ }
52
+
53
+ # Add ad group level mobile bid modifier.
54
+ response = bid_modifier_srv.mutate([operation])
55
+ if response and response[:value]
56
+ modifier = response[:value].first
57
+ value = modifier[:bid_modifier] || 'unset'
58
+ puts ('Campaign ID %d, AdGroup ID %d, Criterion ID %d was updated with ' +
59
+ 'ad group level modifier: %s') %
60
+ [modifier[:campaign_id], modifier[:ad_group_id],
61
+ modifier[:criterion][:id], value]
62
+ else
63
+ puts 'No modifiers were added.'
64
+ end
65
+ end
66
+
67
+ if __FILE__ == $0
68
+ API_VERSION = :v201609
69
+
70
+ begin
71
+ # ID of an ad group to add an override for.
72
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
73
+ # Bid modifier to override with.
74
+ bid_modifier = 1.5
75
+
76
+ add_ad_group_bid_modifier(ad_group_id, bid_modifier)
77
+
78
+ # Authorization error.
79
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
80
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
81
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
82
+ "to retrieve and store OAuth2 tokens."
83
+ puts "See this wiki page for more details:\n\n " +
84
+ 'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
85
+
86
+ # HTTP errors.
87
+ rescue AdsCommon::Errors::HttpError => e
88
+ puts "HTTP Error: %s" % e
89
+
90
+ # API errors.
91
+ rescue AdwordsApi::Errors::ApiException => e
92
+ puts "Message: %s" % e.message
93
+ puts 'Errors:'
94
+ e.errors.each_with_index do |error, index|
95
+ puts "\tError [%d]:" % (index + 1)
96
+ error.each do |field, value|
97
+ puts "\t\t%s: %s" % [field, value]
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
5
+ #
6
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This code example creates a click-to-download ad, also known as an app
20
+ # promotion ad to a given ad group. To list ad groups, run get_ad_groups.rb.
21
+
22
+ require 'adwords_api'
23
+ require 'base64'
24
+
25
+ def add_click_to_download_ad(ad_group_id)
26
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
27
+ # when called without parameters.
28
+ adwords = AdwordsApi::Api.new
29
+
30
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
31
+ # the configuration file or provide your own logger:
32
+ # adwords.logger = Logger.new('adwords_xml.log')
33
+
34
+ ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
35
+
36
+ # Optionally specify a landscape image. The image needs to be in a BASE64
37
+ # encoded form. Here we download a demo image and encode it for this ad.
38
+ image_url = 'http://goo.gl/9JmyKk'
39
+ image_data = AdsCommon::Http.get(image_url, adwords.config)
40
+ image_data_base64 = Base64.encode64(image_data)
41
+
42
+ # Create the template elements for the ad. You can refer to
43
+ # https://developers.google.com/adwords/api/docs/appendix/templateads
44
+ # for the list of available template fields.
45
+ ad_data = {
46
+ :unique_name => 'adData',
47
+ :fields => [
48
+ {
49
+ :name => 'headline',
50
+ :field_text => 'Enjoy your drive in Mars',
51
+ :type => 'TEXT'
52
+ },
53
+ {
54
+ :name => 'description1',
55
+ :field_text => 'Realistic physics simulation',
56
+ :type => 'TEXT'
57
+ },
58
+ {
59
+ :name => 'description2',
60
+ :field_text => 'Race against players online',
61
+ :type => 'TEXT'
62
+ },
63
+ {
64
+ :name => 'appId',
65
+ :field_text => 'com.example.demogame',
66
+ :type => 'TEXT'
67
+ },
68
+ {
69
+ :name => 'appStore',
70
+ :field_text => '2',
71
+ :type => 'ENUM'
72
+ },
73
+ {
74
+ :name => 'landscapeImage',
75
+ :field_media => {
76
+ :xsi_type => 'Image',
77
+ :data => image_data_base64,
78
+ },
79
+ :type => 'IMAGE'
80
+ }
81
+ ]
82
+ }
83
+
84
+ # Create click to download ad.
85
+ click_to_download_app_ad = {
86
+ :xsi_type => 'TemplateAd',
87
+ :name => 'Ad for demo game',
88
+ :template_id => 353,
89
+ :final_urls =>
90
+ ['http://play.google.com/store/apps/details?id=com.example.demogame'],
91
+ :display_url => 'play.google.com',
92
+ :template_elements => [ad_data]
93
+ }
94
+
95
+ # Create ad group ad.
96
+ ad_group_ad = {
97
+ :ad_group_id => ad_group_id,
98
+ :ad => click_to_download_app_ad,
99
+ # Optional.
100
+ :status => 'PAUSED'
101
+ }
102
+
103
+ # Add ad.
104
+ response = ad_group_ad_srv.mutate([
105
+ {:operator => 'ADD', :operand => ad_group_ad}
106
+ ])
107
+ if response and response[:value]
108
+ response[:value].each do |ad|
109
+ puts 'Added new click-to-download ad with ID %d and final url "%s".' %
110
+ [ad[:ad][:id], ad[:ad][:final_urls][0]]
111
+ end
112
+ else
113
+ raise StandardError, 'No ads were added.'
114
+ end
115
+ end
116
+
117
+ if __FILE__ == $0
118
+ API_VERSION = :v201609
119
+
120
+ begin
121
+ # Ad group ID to add text ads to.
122
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
123
+ add_click_to_download_ad(ad_group_id)
124
+
125
+ # Authorization error.
126
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
127
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
128
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
129
+ "to retrieve and store OAuth2 tokens."
130
+ puts "See this wiki page for more details:\n\n " +
131
+ 'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
132
+
133
+ # HTTP errors.
134
+ rescue AdsCommon::Errors::HttpError => e
135
+ puts "HTTP Error: %s" % e
136
+
137
+ # API errors.
138
+ rescue AdwordsApi::Errors::ApiException => e
139
+ puts "Message: %s" % e.message
140
+ puts 'Errors:'
141
+ e.errors.each_with_index do |error, index|
142
+ puts "\tError [%d]:" % (index + 1)
143
+ error.each do |field, value|
144
+ puts "\t\t%s: %s" % [field, value]
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Copyright:: Copyright 2014, Google Inc. All Rights Reserved.
5
+ #
6
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This code example adds an expanded text ad that uses advanced features of
20
+ # upgraded URLs.
21
+
22
+ require 'adwords_api'
23
+
24
+ def add_text_ad_with_upgraded_urls(ad_group_id)
25
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
26
+ # when called without parameters.
27
+ adwords = AdwordsApi::Api.new
28
+
29
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
30
+ # the configuration file or provide your own logger:
31
+ # adwords.logger = Logger.new('adwords_xml.log')
32
+
33
+ ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
34
+
35
+ # Since your tracking URL will have two custom parameters, provide their
36
+ # values too. This can be provided at campaign, ad group, ad, criterion, or
37
+ # feed item levels.
38
+ season_parameter = {
39
+ :key => 'season',
40
+ :value => 'christmas'
41
+ }
42
+
43
+ promo_code_parameter = {
44
+ :key => 'promocode',
45
+ :value => 'NYC123'
46
+ }
47
+
48
+ tracking_url_parameters = {
49
+ :parameters => [season_parameter, promo_code_parameter]
50
+ }
51
+
52
+ expanded_text_ad = {
53
+ :xsi_type => 'ExpandedTextAd',
54
+ :headline_part1 => 'Luxury Cruise to Mars',
55
+ :headline_part2 => 'Visit the Red Planet in style.',
56
+ :description => 'Low-gravity fun for everyone!',
57
+ # Specify a tracking URL for 3rd party tracking provider. You may specify
58
+ # one at customer, campaign, ad group, ad, criterion, or feed item levels.
59
+ :tracking_url_template => 'http://tracker.example.com/' +
60
+ '?season={_season}&promocode={_promocode}&u={lpurl}',
61
+ :url_custom_parameters => tracking_url_parameters,
62
+ # Specify a list of final URLs. This field cannot be set if :url field
63
+ # is set. This may be specified at ad, criterion, and feed item levels.
64
+ :final_urls => [
65
+ 'http://www.example.com/cruise/space/',
66
+ 'http://www.example.com/locations/mars/'
67
+ ],
68
+ # Specify a list of final mobile URLs. This field cannot be set if :url
69
+ # field is set. This may be specificed at ad, criterion, and
70
+ # feed item levels.
71
+ :final_mobile_urls => [
72
+ 'http://mobile.example.com/cruise/space/',
73
+ 'http://mobile.example.com/locations/mars/'
74
+ ]
75
+ }
76
+
77
+ operation = {
78
+ :operator => 'ADD',
79
+ :operand => {:ad_group_id => ad_group_id, :ad => expanded_text_ad}
80
+ }
81
+
82
+ # Add ads.
83
+ response = ad_group_ad_srv.mutate([operation])
84
+ if response and response[:value]
85
+ response[:value].each do |ad|
86
+ text_ad = ad[:ad]
87
+ puts "Ad with ID %d was added." % [text_ad[:id]]
88
+ puts "\tFinal URLs: %s" % [text_ad[:final_urls].join(', ')]
89
+ puts "\tFinal Mobile URLs: %s" % [text_ad[:final_mobile_urls].join(', ')]
90
+ puts "\tTracking URL template: %s" % [text_ad[:tracking_url_template]]
91
+ custom_parameters =
92
+ text_ad[:url_custom_parameters][:parameters].map do |custom_parameter|
93
+ "%s=%s" % [custom_parameter[:key], custom_parameter[:value]]
94
+ end
95
+ puts "\tCustom parameters: %s" % [custom_parameters.join(', ')]
96
+ end
97
+ else
98
+ raise StandardError, 'No ads were added.'
99
+ end
100
+ end
101
+
102
+ if __FILE__ == $0
103
+ API_VERSION = :v201609
104
+
105
+ begin
106
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
107
+ add_text_ad_with_upgraded_urls(ad_group_id)
108
+
109
+ # Authorization error.
110
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
111
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
112
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
113
+ "to retrieve and store OAuth2 tokens."
114
+ puts "See this wiki page for more details:\n\n " +
115
+ 'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
116
+
117
+ # HTTP errors.
118
+ rescue AdsCommon::Errors::HttpError => e
119
+ puts "HTTP Error: %s" % e
120
+
121
+ # API errors.
122
+ rescue AdwordsApi::Errors::ApiException => e
123
+ puts "Message: %s" % e.message
124
+ puts 'Errors:'
125
+ e.errors.each_with_index do |error, index|
126
+ puts "\tError [%d]:" % (index + 1)
127
+ error.each do |field, value|
128
+ puts "\t\t%s: %s" % [field, value]
129
+ end
130
+ end
131
+ end
132
+ end