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.
- checksums.yaml +4 -4
- data/ChangeLog +5 -0
- data/examples/v201603/shopping_campaigns/add_product_scope.rb +3 -2
- data/examples/v201605/shopping_campaigns/add_product_scope.rb +3 -2
- data/examples/v201607/shopping_campaigns/add_product_scope.rb +3 -2
- data/examples/v201609/account_management/create_account.rb +88 -0
- data/examples/v201609/account_management/get_account_changes.rb +135 -0
- data/examples/v201609/account_management/get_account_hierarchy.rb +132 -0
- data/examples/v201609/advanced_operations/add_ad_customizers.rb +183 -0
- data/examples/v201609/advanced_operations/add_ad_group_bid_modifier.rb +101 -0
- data/examples/v201609/advanced_operations/add_click_to_download_ad.rb +148 -0
- data/examples/v201609/advanced_operations/add_expanded_text_ad_with_upgraded_urls.rb +132 -0
- data/examples/v201609/advanced_operations/add_html5_ad.rb +137 -0
- data/examples/v201609/advanced_operations/add_responsive_display_ad.rb +130 -0
- data/examples/v201609/advanced_operations/add_universal_app_campaign.rb +215 -0
- data/examples/v201609/advanced_operations/create_and_attach_shared_keyword_set.rb +141 -0
- data/examples/v201609/advanced_operations/find_and_remove_criteria_from_shared_set.rb +174 -0
- data/examples/v201609/advanced_operations/get_ad_group_bid_modifiers.rb +102 -0
- data/examples/v201609/advanced_operations/use_portfolio_bidding_strategy.rb +146 -0
- data/examples/v201609/basic_operations/add_ad_groups.rb +142 -0
- data/examples/v201609/basic_operations/add_campaigns.rb +138 -0
- data/examples/v201609/basic_operations/add_expanded_text_ads.rb +108 -0
- data/examples/v201609/basic_operations/add_keywords.rb +114 -0
- data/examples/v201609/basic_operations/get_ad_groups.rb +102 -0
- data/examples/v201609/basic_operations/get_campaigns.rb +97 -0
- data/examples/v201609/basic_operations/get_campaigns_with_awql.rb +89 -0
- data/examples/v201609/basic_operations/get_expanded_text_ads.rb +122 -0
- data/examples/v201609/basic_operations/get_keywords.rb +109 -0
- data/examples/v201609/basic_operations/get_text_ads.rb +109 -0
- data/examples/v201609/basic_operations/pause_ad.rb +87 -0
- data/examples/v201609/basic_operations/remove_ad.rb +89 -0
- data/examples/v201609/basic_operations/remove_ad_group.rb +85 -0
- data/examples/v201609/basic_operations/remove_campaign.rb +87 -0
- data/examples/v201609/basic_operations/remove_keyword.rb +94 -0
- data/examples/v201609/basic_operations/update_ad_group.rb +85 -0
- data/examples/v201609/basic_operations/update_campaign.rb +86 -0
- data/examples/v201609/basic_operations/update_keyword.rb +106 -0
- data/examples/v201609/campaign_management/add_campaign_labels.rb +82 -0
- data/examples/v201609/campaign_management/add_complete_campaigns_using_batch_job.rb +354 -0
- data/examples/v201609/campaign_management/add_draft.rb +113 -0
- data/examples/v201609/campaign_management/add_keywords_using_incremental_batch_job.rb +210 -0
- data/examples/v201609/campaign_management/add_trial.rb +141 -0
- data/examples/v201609/campaign_management/get_all_disapproved_ads.rb +97 -0
- data/examples/v201609/campaign_management/get_all_disapproved_ads_with_awql.rb +89 -0
- data/examples/v201609/campaign_management/get_campaigns_by_label.rb +108 -0
- data/examples/v201609/campaign_management/graduate_trial.rb +106 -0
- data/examples/v201609/campaign_management/set_ad_parameters.rb +118 -0
- data/examples/v201609/campaign_management/set_criterion_bid_modifier.rb +104 -0
- data/examples/v201609/campaign_management/validate_text_ad.rb +109 -0
- data/examples/v201609/error_handling/handle_partial_failures.rb +130 -0
- data/examples/v201609/error_handling/handle_policy_violation_error.rb +141 -0
- data/examples/v201609/extensions/add_google_my_business_location_extensions.rb +193 -0
- data/examples/v201609/extensions/add_prices.rb +162 -0
- data/examples/v201609/extensions/add_site_links.rb +199 -0
- data/examples/v201609/extensions/add_site_links_using_feeds.rb +286 -0
- data/examples/v201609/migration/migrate_to_extension_settings.rb +386 -0
- data/examples/v201609/misc/get_all_images_and_videos.rb +104 -0
- data/examples/v201609/misc/setup_oauth2.rb +84 -0
- data/examples/v201609/misc/upload_image.rb +93 -0
- data/examples/v201609/misc/upload_media_bundle.rb +90 -0
- data/examples/v201609/misc/use_oauth2_jwt.rb +93 -0
- data/examples/v201609/misc/use_runtime_config.rb +92 -0
- data/examples/v201609/optimization/estimate_keyword_traffic.rb +191 -0
- data/examples/v201609/optimization/get_campaign_criterion_bid_modifier_simulations.rb +128 -0
- data/examples/v201609/optimization/get_keyword_bid_simulations.rb +95 -0
- data/examples/v201609/optimization/get_keyword_ideas.rb +136 -0
- data/examples/v201609/remarketing/add_audience.rb +118 -0
- data/examples/v201609/remarketing/add_conversion_tracker.rb +97 -0
- data/examples/v201609/remarketing/add_crm_based_user_list.rb +116 -0
- data/examples/v201609/remarketing/add_rule_based_user_lists.rb +167 -0
- data/examples/v201609/remarketing/upload_offline_call_conversions.rb +111 -0
- data/examples/v201609/remarketing/upload_offline_conversions.rb +98 -0
- data/examples/v201609/reporting/download_criteria_report.rb +92 -0
- data/examples/v201609/reporting/download_criteria_report_with_awql.rb +93 -0
- data/examples/v201609/reporting/get_report_fields.rb +75 -0
- data/examples/v201609/reporting/parallel_report_download.rb +164 -0
- data/examples/v201609/reporting/stream_criteria_report_results.rb +97 -0
- data/examples/v201609/shopping_campaigns/add_product_partition_tree.rb +267 -0
- data/examples/v201609/shopping_campaigns/add_product_scope.rb +130 -0
- data/examples/v201609/shopping_campaigns/add_shopping_campaign.rb +129 -0
- data/examples/v201609/shopping_campaigns/get_product_category_taxonomy.rb +115 -0
- data/examples/v201609/targeting/add_campaign_targeting_criteria.rb +166 -0
- data/examples/v201609/targeting/add_demographic_targeting_criteria.rb +112 -0
- data/examples/v201609/targeting/get_campaign_targeting_criteria.rb +106 -0
- data/examples/v201609/targeting/get_targetable_languages_and_carriers.rb +89 -0
- data/examples/v201609/targeting/lookup_location.rb +108 -0
- data/lib/adwords_api/api_config.rb +96 -4
- data/lib/adwords_api/batch_job_utils.rb +6 -0
- data/lib/adwords_api/report_utils.rb +9 -4
- data/lib/adwords_api/v201609/account_label_service.rb +46 -0
- data/lib/adwords_api/v201609/account_label_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_customizer_feed_service.rb +46 -0
- data/lib/adwords_api/v201609/ad_customizer_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_group_ad_service.rb +70 -0
- data/lib/adwords_api/v201609/ad_group_ad_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_group_bid_modifier_service.rb +54 -0
- data/lib/adwords_api/v201609/ad_group_bid_modifier_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_group_criterion_service.rb +62 -0
- data/lib/adwords_api/v201609/ad_group_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_group_extension_setting_service.rb +54 -0
- data/lib/adwords_api/v201609/ad_group_extension_setting_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_group_feed_service.rb +54 -0
- data/lib/adwords_api/v201609/ad_group_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_group_service.rb +62 -0
- data/lib/adwords_api/v201609/ad_group_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/ad_param_service.rb +46 -0
- data/lib/adwords_api/v201609/ad_param_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/adwords_user_list_service.rb +62 -0
- data/lib/adwords_api/v201609/adwords_user_list_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/batch_job_service.rb +54 -0
- data/lib/adwords_api/v201609/batch_job_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/bidding_strategy_service.rb +54 -0
- data/lib/adwords_api/v201609/bidding_strategy_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/budget_order_service.rb +54 -0
- data/lib/adwords_api/v201609/budget_order_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/budget_service.rb +54 -0
- data/lib/adwords_api/v201609/budget_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/campaign_criterion_service.rb +54 -0
- data/lib/adwords_api/v201609/campaign_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/campaign_extension_setting_service.rb +54 -0
- data/lib/adwords_api/v201609/campaign_extension_setting_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/campaign_feed_service.rb +54 -0
- data/lib/adwords_api/v201609/campaign_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/campaign_service.rb +62 -0
- data/lib/adwords_api/v201609/campaign_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/campaign_shared_set_service.rb +54 -0
- data/lib/adwords_api/v201609/campaign_shared_set_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/constant_data_service.rb +110 -0
- data/lib/adwords_api/v201609/constant_data_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/conversion_tracker_service.rb +54 -0
- data/lib/adwords_api/v201609/conversion_tracker_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/customer_extension_setting_service.rb +54 -0
- data/lib/adwords_api/v201609/customer_extension_setting_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/customer_feed_service.rb +54 -0
- data/lib/adwords_api/v201609/customer_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/customer_service.rb +62 -0
- data/lib/adwords_api/v201609/customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/customer_sync_service.rb +38 -0
- data/lib/adwords_api/v201609/customer_sync_service_registry.rb +47 -0
- data/lib/adwords_api/v201609/data_service.rb +94 -0
- data/lib/adwords_api/v201609/data_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/draft_async_error_service.rb +46 -0
- data/lib/adwords_api/v201609/draft_async_error_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/draft_service.rb +54 -0
- data/lib/adwords_api/v201609/draft_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/feed_item_service.rb +54 -0
- data/lib/adwords_api/v201609/feed_item_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/feed_mapping_service.rb +54 -0
- data/lib/adwords_api/v201609/feed_mapping_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/feed_service.rb +54 -0
- data/lib/adwords_api/v201609/feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/label_service.rb +54 -0
- data/lib/adwords_api/v201609/label_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/location_criterion_service.rb +46 -0
- data/lib/adwords_api/v201609/location_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/managed_customer_service.rb +78 -0
- data/lib/adwords_api/v201609/managed_customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/media_service.rb +54 -0
- data/lib/adwords_api/v201609/media_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/offline_call_conversion_feed_service.rb +38 -0
- data/lib/adwords_api/v201609/offline_call_conversion_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/offline_conversion_feed_service.rb +38 -0
- data/lib/adwords_api/v201609/offline_conversion_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/report_definition_service.rb +38 -0
- data/lib/adwords_api/v201609/report_definition_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/shared_criterion_service.rb +54 -0
- data/lib/adwords_api/v201609/shared_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/shared_set_service.rb +54 -0
- data/lib/adwords_api/v201609/shared_set_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/targeting_idea_service.rb +38 -0
- data/lib/adwords_api/v201609/targeting_idea_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/traffic_estimator_service.rb +38 -0
- data/lib/adwords_api/v201609/traffic_estimator_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/trial_async_error_service.rb +46 -0
- data/lib/adwords_api/v201609/trial_async_error_service_registry.rb +46 -0
- data/lib/adwords_api/v201609/trial_service.rb +54 -0
- data/lib/adwords_api/v201609/trial_service_registry.rb +46 -0
- data/lib/adwords_api/version.rb +1 -1
- data/test/adwords_api/test_adwords_api.rb +1 -1
- data/test/adwords_api/test_api_config.rb +8 -8
- data/test/adwords_api/test_batch_job_utils.rb +2 -2
- data/test/adwords_api/test_choices.rb +2 -2
- data/test/adwords_api/test_report_stream.rb +1 -1
- data/test/adwords_api/test_report_utils.rb +1 -1
- data/test/templates/v201609/basic_operations_get_campaigns.def +116 -0
- data/test/templates/v201609/basic_operations_update_keyword.def +125 -0
- data/test/templates/v201609/misc_use_oauth2_jwt.def +131 -0
- metadata +174 -2
@@ -0,0 +1,137 @@
|
|
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 code example adds an HTML5 ad to a given ad group.
|
20
|
+
# To get ad groups, run basic_operations/get_ad_groups.rb.
|
21
|
+
|
22
|
+
require 'adwords_api'
|
23
|
+
require 'base64'
|
24
|
+
|
25
|
+
def add_html5_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
|
+
# The HTML5 zip file contains all the HTML, CSS, and images needed for the
|
37
|
+
# HTML5 ad. For help on creating an HTML5 zip file, check out Google Web
|
38
|
+
# Designer (https://www.google.com/webdesigner).
|
39
|
+
html5_url = 'http://goo.gl/9Y7qI2'
|
40
|
+
html5_data = AdsCommon::Http.get(html5_url, adwords.config)
|
41
|
+
html5_data_base64 = Base64.encode64(html5_data)
|
42
|
+
|
43
|
+
# Create a media bundle containing the zip file with all the HTML5
|
44
|
+
# components.
|
45
|
+
media_bundle = {
|
46
|
+
:xsi_type => 'MediaBundle',
|
47
|
+
:data => html5_data_base64,
|
48
|
+
:entry_point => 'carousel/index.html',
|
49
|
+
:type => 'MEDIA_BUNDLE'
|
50
|
+
}
|
51
|
+
|
52
|
+
# Create the template elements for the ad. You can refer to
|
53
|
+
# https://developers.google.com/adwords/api/docs/appendix/templateads
|
54
|
+
# for the list of available template fields.
|
55
|
+
ad_data = {
|
56
|
+
:unique_name => 'adData',
|
57
|
+
:fields => [
|
58
|
+
{
|
59
|
+
:name => 'Custom_layout',
|
60
|
+
:field_media => media_bundle,
|
61
|
+
:type => 'MEDIA_BUNDLE'
|
62
|
+
},
|
63
|
+
{
|
64
|
+
:name => 'layout',
|
65
|
+
:field_text => 'Custom',
|
66
|
+
:type => 'ENUM'
|
67
|
+
}
|
68
|
+
]
|
69
|
+
}
|
70
|
+
|
71
|
+
html5_ad = {
|
72
|
+
:xsi_type => 'TemplateAd',
|
73
|
+
:name => 'Ad for HTML5',
|
74
|
+
:template_id => 419,
|
75
|
+
:final_urls => ['http://example.com/html5'],
|
76
|
+
:display_url => 'www.example.com/html5',
|
77
|
+
:dimensions => {
|
78
|
+
:width => 300,
|
79
|
+
:height => 250
|
80
|
+
},
|
81
|
+
:template_elements => [ad_data]
|
82
|
+
}
|
83
|
+
|
84
|
+
ad_group_ad = {
|
85
|
+
:ad_group_id => ad_group_id,
|
86
|
+
:ad => html5_ad,
|
87
|
+
:status => 'PAUSED'
|
88
|
+
}
|
89
|
+
|
90
|
+
operation = {
|
91
|
+
:operator => 'ADD',
|
92
|
+
:operand => ad_group_ad
|
93
|
+
}
|
94
|
+
|
95
|
+
response = ad_group_ad_srv.mutate([operation])
|
96
|
+
if response and !response.empty?
|
97
|
+
response[:value].each do |ad_group_ad|
|
98
|
+
puts "New HTML5 ad with ID %d and display url '%s' was added." %
|
99
|
+
[ad_group_ad[:ad][:id], ad_group_ad[:ad][:display_url]]
|
100
|
+
end
|
101
|
+
else
|
102
|
+
puts "No HTML5 ads were added."
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if __FILE__ == $0
|
107
|
+
API_VERSION = :v201609
|
108
|
+
|
109
|
+
begin
|
110
|
+
# Ad group ID to add text ads to.
|
111
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
112
|
+
add_html5_ad(ad_group_id)
|
113
|
+
|
114
|
+
# Authorization error.
|
115
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
116
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
117
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
118
|
+
"to retrieve and store OAuth2 tokens."
|
119
|
+
puts "See this wiki page for more details:\n\n " +
|
120
|
+
'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
|
121
|
+
|
122
|
+
# HTTP errors.
|
123
|
+
rescue AdsCommon::Errors::HttpError => e
|
124
|
+
puts "HTTP Error: %s" % e
|
125
|
+
|
126
|
+
# API errors.
|
127
|
+
rescue AdwordsApi::Errors::ApiException => e
|
128
|
+
puts "Message: %s" % e.message
|
129
|
+
puts 'Errors:'
|
130
|
+
e.errors.each_with_index do |error, index|
|
131
|
+
puts "\tError [%d]:" % (index + 1)
|
132
|
+
error.each do |field, value|
|
133
|
+
puts "\t\t%s: %s" % [field, value]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright 2016, 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 image representing the ad using the MediaService and
|
20
|
+
# then adds a responsive display ad to a given ad group.
|
21
|
+
# To get ad groups, run basic_operations/get_ad_groups.rb.
|
22
|
+
|
23
|
+
require 'adwords_api'
|
24
|
+
require 'base64'
|
25
|
+
|
26
|
+
def add_responsive_display_ad(ad_group_id)
|
27
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
28
|
+
# when called without parameters.
|
29
|
+
adwords = AdwordsApi::Api.new
|
30
|
+
|
31
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
32
|
+
# the configuration file or provide your own logger:
|
33
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
34
|
+
|
35
|
+
ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
|
36
|
+
media_srv = adwords.service(:MediaService, API_VERSION)
|
37
|
+
|
38
|
+
# Create an image.
|
39
|
+
image_url = 'https://goo.gl/3b9Wfh'
|
40
|
+
raw_image_data = AdsCommon::Http.get(image_url, adwords.config)
|
41
|
+
image = {
|
42
|
+
:xsi_type => 'Image',
|
43
|
+
:data => Base64.encode64(raw_image_data),
|
44
|
+
:type => 'IMAGE'
|
45
|
+
}
|
46
|
+
|
47
|
+
# Upload the image.
|
48
|
+
response = media_srv.upload([image])
|
49
|
+
if response and !response.empty?
|
50
|
+
image = response.first
|
51
|
+
else
|
52
|
+
raise StandardError, "Could not uplooad image. Aborting before creating ad."
|
53
|
+
end
|
54
|
+
|
55
|
+
# Create the responsive display ad.
|
56
|
+
responsive_display_ad = {
|
57
|
+
:xsi_type => 'ResponsiveDisplayAd',
|
58
|
+
# This ad format does not allow the creation of an image using the
|
59
|
+
# Image.data field. An image must first be created using the MediaService,
|
60
|
+
# and Image.mediaId must be populated when creating the ad.
|
61
|
+
:marketing_image => {
|
62
|
+
:media_id => image[:media_id]
|
63
|
+
},
|
64
|
+
:short_headline => 'Travel',
|
65
|
+
:long_headline => 'Traver the World',
|
66
|
+
:description => 'Take to the air!',
|
67
|
+
:business_name => 'Interplanetary Cruises',
|
68
|
+
:final_urls => ['http://www.example.com/']
|
69
|
+
}
|
70
|
+
|
71
|
+
# Create an ad group ad for the responsive display ad.
|
72
|
+
responsive_display_ad_group_ad = {
|
73
|
+
:ad_group_id => ad_group_id,
|
74
|
+
:ad => responsive_display_ad,
|
75
|
+
# Additional propertires (non-required).
|
76
|
+
:status => 'PAUSED'
|
77
|
+
}
|
78
|
+
|
79
|
+
# Create operation.
|
80
|
+
responsive_display_ad_group_ad_operations = {
|
81
|
+
:operator => 'ADD',
|
82
|
+
:operand => responsive_display_ad_group_ad
|
83
|
+
}
|
84
|
+
|
85
|
+
# Add the responsive display ad.
|
86
|
+
result = ad_group_ad_srv.mutate([responsive_display_ad_group_ad_operations])
|
87
|
+
|
88
|
+
# Display results.
|
89
|
+
if result && result[:value]
|
90
|
+
result[:value].each do |ad_group_ad|
|
91
|
+
puts ('New responsive display ad with id %d and short headline %s was ' +
|
92
|
+
'added.') % [ad_group_ad[:ad][:id], ad_group_ad[:ad][:short_headline]]
|
93
|
+
end
|
94
|
+
else
|
95
|
+
puts "No responsive display ads were added."
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if __FILE__ == $0
|
100
|
+
API_VERSION = :v201609
|
101
|
+
|
102
|
+
begin
|
103
|
+
# Ad group ID to add text ads to.
|
104
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
105
|
+
add_responsive_display_ad(ad_group_id)
|
106
|
+
|
107
|
+
# Authorization error.
|
108
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
109
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
110
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
111
|
+
"to retrieve and store OAuth2 tokens."
|
112
|
+
puts "See this wiki page for more details:\n\n " +
|
113
|
+
'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
|
114
|
+
|
115
|
+
# HTTP errors.
|
116
|
+
rescue AdsCommon::Errors::HttpError => e
|
117
|
+
puts "HTTP Error: %s" % e
|
118
|
+
|
119
|
+
# API errors.
|
120
|
+
rescue AdwordsApi::Errors::ApiException => e
|
121
|
+
puts "Message: %s" % e.message
|
122
|
+
puts 'Errors:'
|
123
|
+
e.errors.each_with_index do |error, index|
|
124
|
+
puts "\tError [%d]:" % (index + 1)
|
125
|
+
error.each do |field, value|
|
126
|
+
puts "\t\t%s: %s" % [field, value]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright 2016, 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 a universal app campaign.
|
20
|
+
#
|
21
|
+
# To get campaigns, run get_campaigns.rb. To upload image assets for this
|
22
|
+
# campaign, run upload_image.rb.
|
23
|
+
|
24
|
+
require 'adwords_api'
|
25
|
+
require 'date'
|
26
|
+
|
27
|
+
def add_universal_app_campaigns()
|
28
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
29
|
+
# when called without parameters.
|
30
|
+
adwords = AdwordsApi::Api.new
|
31
|
+
|
32
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
33
|
+
# the configuration file or provide your own logger:
|
34
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
35
|
+
|
36
|
+
campaign_srv = adwords.service(:CampaignService, API_VERSION)
|
37
|
+
budget_srv = adwords.service(:BudgetService, API_VERSION)
|
38
|
+
|
39
|
+
# Create a budget.
|
40
|
+
budget = {
|
41
|
+
:name => 'Interplanetary budget #%d' % (Time.new.to_f * 1000).to_i,
|
42
|
+
:amount => {:micro_amount => 50000000},
|
43
|
+
:delivery_method => 'STANDARD',
|
44
|
+
# Universal app campaigns don't support shared budgets.
|
45
|
+
:is_explicitly_shared => false
|
46
|
+
}
|
47
|
+
budget_operation = {:operator => 'ADD', :operand => budget}
|
48
|
+
|
49
|
+
# Add the budget.
|
50
|
+
return_budget = budget_srv.mutate([budget_operation])
|
51
|
+
budget_id = return_budget[:value].first[:budget_id]
|
52
|
+
|
53
|
+
# Create campaigns.
|
54
|
+
universal_app_campaign = {
|
55
|
+
:name => "Interplanetary Cruise #%d" % (Time.new.to_f * 1000).to_i,
|
56
|
+
:status => 'PAUSED',
|
57
|
+
# Set the advertising channel and subchannel types for universal app
|
58
|
+
# campaigns.
|
59
|
+
:advertising_channel_type => 'MULTI_CHANNEL',
|
60
|
+
:advertising_channel_sub_type => 'UNIVERSAL_APP_CAMPAIGN',
|
61
|
+
# Set the campaign's bidding strategy. Universal app campaigns only support
|
62
|
+
# the TARGET_CPA bidding strategy.
|
63
|
+
:bidding_strategy_configuration => {
|
64
|
+
:bidding_scheme => {
|
65
|
+
:xsi_type => 'TargetCpaBiddingScheme',
|
66
|
+
:target_cpa => {
|
67
|
+
:micro_amount => 1000000
|
68
|
+
}
|
69
|
+
}
|
70
|
+
},
|
71
|
+
# Budget (required) - note only the budget ID is required.
|
72
|
+
:budget => {:budget_id => budget_id},
|
73
|
+
# Optional fields:
|
74
|
+
:start_date =>
|
75
|
+
DateTime.parse((Date.today + 1).to_s).strftime('%Y%m%d'),
|
76
|
+
:end_date =>
|
77
|
+
DateTime.parse((Date.today + 365).to_s).strftime('%Y%m%d')
|
78
|
+
}
|
79
|
+
|
80
|
+
universal_app_setting = {
|
81
|
+
# Set the campaign's assets and ad text ideas. These values will be used to
|
82
|
+
# generate ads.
|
83
|
+
:xsi_type => 'UniversalAppCampaignSetting',
|
84
|
+
:app_id => 'com.interplanetarycruise.booking',
|
85
|
+
:description1 => 'Best Space Cruise Line',
|
86
|
+
:description2 => 'Visit all the planets',
|
87
|
+
:description3 => 'Trips 7 days a week',
|
88
|
+
:description4 => 'Buy your tickets now!'
|
89
|
+
# Optional: You can set up to 10 image assets for your campaign. See
|
90
|
+
# upload_image.rb for an example on how to upload images.
|
91
|
+
#
|
92
|
+
# :image_media_ids => [INSERT_IMGAGE_MEDIA_ID(s)_HERE]
|
93
|
+
}
|
94
|
+
|
95
|
+
# Optimize this campaign for getting new users for your app.
|
96
|
+
universal_app_setting[:universal_app_bidding_strategy_goal_type] =
|
97
|
+
'OPTIMIZE_FOR_INSTALL_CONVERSION_VOLUME'
|
98
|
+
|
99
|
+
# Optional: If you select OPTIMIZE_FOR_IN_APP_CONVERSION_VOLUME goal type,
|
100
|
+
# then also specify your in-app conversion types so AdWords can focus your
|
101
|
+
# campaign on people who are most likely to complete the corresponding in-app
|
102
|
+
# actions.
|
103
|
+
# Conversion type IDs can be retrieved using ConversionTrackerService.get.
|
104
|
+
#
|
105
|
+
# universal_app_campaign[:selective_optimization] = {
|
106
|
+
# :conversion_type_ids => [INSERT_CONVERSION_TYPE_ID(s)_HERE]
|
107
|
+
# }
|
108
|
+
|
109
|
+
# Optional: Set the campaign settings for Advanced location options.
|
110
|
+
geo_setting = {
|
111
|
+
:xsi_type => 'GeoTargetTypeSetting',
|
112
|
+
:positive_geo_target_type => 'DONT_CARE',
|
113
|
+
:negative_geo_target_type => 'DONT_CARE'
|
114
|
+
}
|
115
|
+
|
116
|
+
universal_app_campaign[:settings] = [
|
117
|
+
universal_app_setting,
|
118
|
+
geo_setting
|
119
|
+
]
|
120
|
+
|
121
|
+
# Construct the operation and add the campaign.
|
122
|
+
operations = [{
|
123
|
+
:operator => 'ADD',
|
124
|
+
:operand => universal_app_campaign
|
125
|
+
}]
|
126
|
+
|
127
|
+
campaigns = campaign_srv.mutate(operations)[:value]
|
128
|
+
|
129
|
+
if campaigns
|
130
|
+
campaigns.each do |campaign|
|
131
|
+
puts "Universal app campaign with name '%s' and ID %d was added." %
|
132
|
+
[campaign[:name], campaign[:id]]
|
133
|
+
set_campaign_targeting_criteria(adwords, campaign)
|
134
|
+
end
|
135
|
+
else
|
136
|
+
raise new StandardError, 'No universal app campaigns were added.'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def set_campaign_targeting_criteria(adwords, campaign)
|
141
|
+
campaign_criterion_service =
|
142
|
+
adwords.service(:CampaignCriterionService, API_VERSION)
|
143
|
+
|
144
|
+
criteria = [
|
145
|
+
{
|
146
|
+
:xsi_type => 'Location',
|
147
|
+
:id => 21137 # California
|
148
|
+
},
|
149
|
+
{
|
150
|
+
:xsi_type => 'Location',
|
151
|
+
:id => 2484 # Mexico
|
152
|
+
},
|
153
|
+
{
|
154
|
+
:xsi_type => 'Language',
|
155
|
+
:id => 1000 # English
|
156
|
+
},
|
157
|
+
{
|
158
|
+
:xsi_type => 'Language',
|
159
|
+
:id => 1003 # Spanish
|
160
|
+
}
|
161
|
+
]
|
162
|
+
|
163
|
+
operations = criteria.map do |criterion|
|
164
|
+
{
|
165
|
+
:operator => 'ADD',
|
166
|
+
:operand => {
|
167
|
+
:campaign_id => campaign[:id],
|
168
|
+
:criterion => criterion
|
169
|
+
}
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
response = campaign_criterion_service.mutate(operations)
|
174
|
+
|
175
|
+
if response and response[:value]
|
176
|
+
# Display the added campaign targets.
|
177
|
+
response[:value].each do |criterion|
|
178
|
+
puts 'Campaign criteria of type "%s" and id %d was added.' % [
|
179
|
+
criterion[:criterion][:criterion_type],
|
180
|
+
criterion[:criterion][:id]
|
181
|
+
]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
if __FILE__ == $0
|
187
|
+
API_VERSION = :v201609
|
188
|
+
|
189
|
+
begin
|
190
|
+
add_universal_app_campaigns()
|
191
|
+
|
192
|
+
# Authorization error.
|
193
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
194
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
195
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
196
|
+
"to retrieve and store OAuth2 tokens."
|
197
|
+
puts "See this wiki page for more details:\n\n " +
|
198
|
+
'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
|
199
|
+
|
200
|
+
# HTTP errors.
|
201
|
+
rescue AdsCommon::Errors::HttpError => e
|
202
|
+
puts "HTTP Error: %s" % e
|
203
|
+
|
204
|
+
# API errors.
|
205
|
+
rescue AdwordsApi::Errors::ApiException => e
|
206
|
+
puts "Message: %s" % e.message
|
207
|
+
puts 'Errors:'
|
208
|
+
e.errors.each_with_index do |error, index|
|
209
|
+
puts "\tError [%d]:" % (index + 1)
|
210
|
+
error.each do |field, value|
|
211
|
+
puts "\t\t%s: %s" % [field, value]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|