google-adwords-api 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/README +124 -107
- data/examples/v201306/misc/use_oauth2_jwt.rb +5 -1
- data/examples/v201309/misc/use_oauth2_jwt.rb +5 -1
- data/examples/v201402/account_management/create_account.rb +95 -0
- data/examples/v201402/account_management/get_account_alerts.rb +122 -0
- data/examples/v201402/account_management/get_account_changes.rb +145 -0
- data/examples/v201402/account_management/get_account_hierarchy.rb +103 -0
- data/examples/v201402/advanced_operations/add_ad_group_bid_modifier.rb +105 -0
- data/examples/v201402/advanced_operations/add_click_to_download_ad.rb +137 -0
- data/examples/v201402/advanced_operations/add_places_location_extensions.rb +159 -0
- data/examples/v201402/advanced_operations/add_places_location_extensions.rb~ +159 -0
- data/examples/v201402/advanced_operations/add_site_links.rb +306 -0
- data/examples/v201402/advanced_operations/get_ad_group_bid_modifiers.rb +106 -0
- data/examples/v201402/advanced_operations/update_site_links.rb +194 -0
- data/examples/v201402/advanced_operations/upload_offline_conversions.rb +117 -0
- data/examples/v201402/advanced_operations/use_shared_bidding_strategy.rb +163 -0
- data/examples/v201402/basic_operations/add_ad_groups.rb +142 -0
- data/examples/v201402/basic_operations/add_ad_groups.rb~ +147 -0
- data/examples/v201402/basic_operations/add_campaigns.rb +153 -0
- data/examples/v201402/basic_operations/add_keywords.rb +116 -0
- data/examples/v201402/basic_operations/add_text_ads.rb +113 -0
- data/examples/v201402/basic_operations/delete_ad.rb +93 -0
- data/examples/v201402/basic_operations/delete_ad_group.rb +110 -0
- data/examples/v201402/basic_operations/delete_campaign.rb +111 -0
- data/examples/v201402/basic_operations/delete_keyword.rb +98 -0
- data/examples/v201402/basic_operations/get_ad_groups.rb +106 -0
- data/examples/v201402/basic_operations/get_campaigns.rb +101 -0
- data/examples/v201402/basic_operations/get_campaigns_with_awql.rb +93 -0
- data/examples/v201402/basic_operations/get_keywords.rb +112 -0
- data/examples/v201402/basic_operations/get_text_ads.rb +114 -0
- data/examples/v201402/basic_operations/pause_ad.rb +92 -0
- data/examples/v201402/basic_operations/update_ad_group.rb +89 -0
- data/examples/v201402/basic_operations/update_campaign.rb +90 -0
- data/examples/v201402/basic_operations/update_keyword.rb +110 -0
- data/examples/v201402/campaign_management/add_experiment.rb +166 -0
- data/examples/v201402/campaign_management/add_keywords_in_bulk.rb +158 -0
- data/examples/v201402/campaign_management/add_location_extension.rb +125 -0
- data/examples/v201402/campaign_management/get_all_disapproved_ads.rb +101 -0
- data/examples/v201402/campaign_management/get_all_disapproved_ads_with_awql.rb +93 -0
- data/examples/v201402/campaign_management/promote_experiment.rb +85 -0
- data/examples/v201402/campaign_management/set_ad_parameters.rb +122 -0
- data/examples/v201402/campaign_management/set_criterion_bid_modifier.rb +108 -0
- data/examples/v201402/campaign_management/validate_text_ad.rb +114 -0
- data/examples/v201402/error_handling/handle_captcha_challenge.rb +93 -0
- data/examples/v201402/error_handling/handle_partial_failures.rb +134 -0
- data/examples/v201402/error_handling/handle_policy_violation_error.rb +145 -0
- data/examples/v201402/error_handling/handle_two_factor_authorization_error.rb +88 -0
- data/examples/v201402/misc/create_ad_words_session_without_properties_file.rb +94 -0
- data/examples/v201402/misc/create_ad_words_session_without_properties_file.rb~ +94 -0
- data/examples/v201402/misc/get_all_images_and_videos.rb +108 -0
- data/examples/v201402/misc/setup_oauth2.rb +88 -0
- data/examples/v201402/misc/upload_image.rb +97 -0
- data/examples/v201402/misc/use_oauth2_jwt.rb +97 -0
- data/examples/v201402/optimization/estimate_keyword_traffic.rb +137 -0
- data/examples/v201402/optimization/get_keyword_bid_simulations.rb +100 -0
- data/examples/v201402/optimization/get_keyword_ideas.rb +130 -0
- data/examples/v201402/optimization/get_placement_ideas.rb +112 -0
- data/examples/v201402/remarketing/add_audience.rb +123 -0
- data/examples/v201402/remarketing/add_conversion_tracker.rb +105 -0
- data/examples/v201402/remarketing/add_conversion_tracker.rb~ +109 -0
- data/examples/v201402/reporting/download_criteria_report.rb +87 -0
- data/examples/v201402/reporting/download_criteria_report_with_awql.rb +86 -0
- data/examples/v201402/reporting/get_report_fields.rb +79 -0
- data/examples/v201402/reporting/parallel_report_download.rb +171 -0
- data/examples/v201402/shopping_campaigns/add_product_partition_tree.rb +269 -0
- data/examples/v201402/shopping_campaigns/add_product_partition_tree.rb~ +269 -0
- data/examples/v201402/shopping_campaigns/add_product_scope.rb +133 -0
- data/examples/v201402/shopping_campaigns/add_shopping_campaign.rb +135 -0
- data/examples/v201402/shopping_campaigns/add_shopping_campaign.rb~ +136 -0
- data/examples/v201402/shopping_campaigns/get_product_category_taxonomy.rb +117 -0
- data/examples/v201402/shopping_campaigns/get_product_category_taxonomy.rb~ +128 -0
- data/examples/v201402/shopping_campaigns/set_product_sales_channel.rb +98 -0
- data/examples/v201402/shopping_campaigns/set_product_sales_channel.rb~ +98 -0
- data/examples/v201402/targeting/add_campaign_targeting_criteria.rb +157 -0
- data/examples/v201402/targeting/add_demographic_targeting_criteria.rb +116 -0
- data/examples/v201402/targeting/get_campaign_targeting_criteria.rb +110 -0
- data/examples/v201402/targeting/get_targetable_languages_and_carriers.rb +94 -0
- data/examples/v201402/targeting/lookup_location.rb +112 -0
- data/lib/adwords_api.rb +7 -0
- data/lib/adwords_api/api_config.rb +76 -4
- data/lib/adwords_api/report_header_handler.rb +1 -1
- data/lib/adwords_api/v201402/ad_group_ad_service.rb +42 -0
- data/lib/adwords_api/v201402/ad_group_ad_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/ad_group_bid_modifier_service.rb +42 -0
- data/lib/adwords_api/v201402/ad_group_bid_modifier_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/ad_group_criterion_service.rb +42 -0
- data/lib/adwords_api/v201402/ad_group_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/ad_group_feed_service.rb +42 -0
- data/lib/adwords_api/v201402/ad_group_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/ad_group_service.rb +42 -0
- data/lib/adwords_api/v201402/ad_group_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/ad_param_service.rb +38 -0
- data/lib/adwords_api/v201402/ad_param_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/adwords_user_list_service.rb +38 -0
- data/lib/adwords_api/v201402/adwords_user_list_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/alert_service.rb +34 -0
- data/lib/adwords_api/v201402/alert_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/bidding_strategy_service.rb +42 -0
- data/lib/adwords_api/v201402/bidding_strategy_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/budget_order_service.rb +42 -0
- data/lib/adwords_api/v201402/budget_order_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/budget_service.rb +42 -0
- data/lib/adwords_api/v201402/budget_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/campaign_ad_extension_service.rb +38 -0
- data/lib/adwords_api/v201402/campaign_ad_extension_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/campaign_criterion_service.rb +42 -0
- data/lib/adwords_api/v201402/campaign_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/campaign_feed_service.rb +42 -0
- data/lib/adwords_api/v201402/campaign_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/campaign_service.rb +42 -0
- data/lib/adwords_api/v201402/campaign_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/constant_data_service.rb +66 -0
- data/lib/adwords_api/v201402/constant_data_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/conversion_tracker_service.rb +38 -0
- data/lib/adwords_api/v201402/conversion_tracker_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/customer_feed_service.rb +42 -0
- data/lib/adwords_api/v201402/customer_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/customer_service.rb +38 -0
- data/lib/adwords_api/v201402/customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/customer_sync_service.rb +34 -0
- data/lib/adwords_api/v201402/customer_sync_service_registry.rb +47 -0
- data/lib/adwords_api/v201402/data_service.rb +46 -0
- data/lib/adwords_api/v201402/data_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/experiment_service.rb +38 -0
- data/lib/adwords_api/v201402/experiment_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/feed_item_service.rb +42 -0
- data/lib/adwords_api/v201402/feed_item_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/feed_mapping_service.rb +42 -0
- data/lib/adwords_api/v201402/feed_mapping_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/feed_service.rb +42 -0
- data/lib/adwords_api/v201402/feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/geo_location_service.rb +34 -0
- data/lib/adwords_api/v201402/geo_location_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/location_criterion_service.rb +38 -0
- data/lib/adwords_api/v201402/location_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/managed_customer_service.rb +50 -0
- data/lib/adwords_api/v201402/managed_customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/media_service.rb +42 -0
- data/lib/adwords_api/v201402/media_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/mutate_job_service.rb +42 -0
- data/lib/adwords_api/v201402/mutate_job_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/offline_conversion_feed_service.rb +34 -0
- data/lib/adwords_api/v201402/offline_conversion_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/report_definition_service.rb +34 -0
- data/lib/adwords_api/v201402/report_definition_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/targeting_idea_service.rb +38 -0
- data/lib/adwords_api/v201402/targeting_idea_service_registry.rb +46 -0
- data/lib/adwords_api/v201402/traffic_estimator_service.rb +34 -0
- data/lib/adwords_api/v201402/traffic_estimator_service_registry.rb +46 -0
- data/lib/adwords_api/version.rb +1 -1
- data/test/adwords_api/test_adwords_api.rb +15 -2
- data/test/adwords_api/test_adwords_api.rb~ +127 -0
- data/test/templates/v201306/basic_operations_get_campaigns.def +1 -1
- data/test/templates/v201306/misc_use_oauth2_jwt.def +1 -1
- data/test/templates/v201309/basic_operations_get_campaigns.def +1 -1
- data/test/templates/v201309/misc_use_oauth2_jwt.def +1 -1
- metadata +146 -2
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This code example imports offline conversion values for specific clicks to
|
22
|
+
# your account. To get Google Click ID for a click, run
|
23
|
+
# CLICK_PERFORMANCE_REPORT.
|
24
|
+
#
|
25
|
+
# Tags: ConversionTrackerService.mutate, OfflineConversionFeedService.mutate
|
26
|
+
|
27
|
+
require 'adwords_api'
|
28
|
+
require 'date'
|
29
|
+
|
30
|
+
def upload_offline_conversions(conversion_name, google_click_id,
|
31
|
+
conversion_time, conversion_value)
|
32
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
33
|
+
# when called without parameters.
|
34
|
+
adwords = AdwordsApi::Api.new
|
35
|
+
|
36
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
37
|
+
# the configuration file or provide your own logger:
|
38
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
39
|
+
|
40
|
+
conversion_tracker_srv =
|
41
|
+
adwords.service(:ConversionTrackerService, API_VERSION)
|
42
|
+
conversion_feed_srv =
|
43
|
+
adwords.service(:OfflineConversionFeedService, API_VERSION)
|
44
|
+
|
45
|
+
# Create an upload conversion. Once created, this entry will be visible under
|
46
|
+
# Tools and Analysis->Conversion and will have Source = Import.
|
47
|
+
upload_conversion = {
|
48
|
+
:xsi_type => 'UploadConversion',
|
49
|
+
:category => 'PAGE_VIEW',
|
50
|
+
:name => conversion_name,
|
51
|
+
:viewthrough_lookback_window => 30,
|
52
|
+
:ctc_lookback_window => 90
|
53
|
+
}
|
54
|
+
return_conversions = conversion_tracker_srv.mutate([
|
55
|
+
{:operator => 'ADD', :operand => upload_conversion}])
|
56
|
+
return_conversions[:value].each do |tracker|
|
57
|
+
puts "Upload conversion tracker with name '%s' and ID %d was created." %
|
58
|
+
[tracker[:name], tracker[:id]]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Associate offline conversions with the upload conversion tracker we created.
|
62
|
+
feed = {
|
63
|
+
:conversion_name => conversion_name,
|
64
|
+
:google_click_id => google_click_id,
|
65
|
+
:conversion_time => conversion_time,
|
66
|
+
:conversion_value => conversion_value
|
67
|
+
}
|
68
|
+
return_feeds = conversion_feed_srv.mutate([
|
69
|
+
{:operator => 'ADD', :operand => feed}])
|
70
|
+
return_feeds[:value].each do |return_feed|
|
71
|
+
puts ("Uploaded offline conversion value %.2f for Google Click ID '%s', " +
|
72
|
+
'to %s') % [return_feed[:conversion_value],
|
73
|
+
return_feed[:google_click_id],
|
74
|
+
return_feed[:conversion_name]]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if __FILE__ == $0
|
79
|
+
API_VERSION = :v201402
|
80
|
+
|
81
|
+
begin
|
82
|
+
# Name of the upload conversion to be created.
|
83
|
+
conversion_name = 'INSERT_CONVERSION_NAME_HERE'
|
84
|
+
# Google Click ID of the click for which offline conversions are uploaded.
|
85
|
+
google_click_id = 'INSERT_GOOGLE_CLICK_ID_HERE'
|
86
|
+
# Conversion time in 'yyyymmdd hhmmss' format.
|
87
|
+
conversion_time = Time.new.strftime("%Y%m%d %H%M%S")
|
88
|
+
# Conversion value to be uploaded.
|
89
|
+
conversion_value = 'INSERT_CONVERSION_VALUE_HERE'.to_f
|
90
|
+
|
91
|
+
upload_offline_conversions(conversion_name, google_click_id,
|
92
|
+
conversion_time, conversion_value)
|
93
|
+
|
94
|
+
# Authorization error.
|
95
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
96
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
97
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
98
|
+
"to retrieve and store OAuth2 tokens."
|
99
|
+
puts "See this wiki page for more details:\n\n " +
|
100
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
101
|
+
|
102
|
+
# HTTP errors.
|
103
|
+
rescue AdsCommon::Errors::HttpError => e
|
104
|
+
puts "HTTP Error: %s" % e
|
105
|
+
|
106
|
+
# API errors.
|
107
|
+
rescue AdwordsApi::Errors::ApiException => e
|
108
|
+
puts "Message: %s" % e.message
|
109
|
+
puts 'Errors:'
|
110
|
+
e.errors.each_with_index do |error, index|
|
111
|
+
puts "\tError [%d]:" % (index + 1)
|
112
|
+
error.each do |field, value|
|
113
|
+
puts "\t\t%s: %s" % [field, value]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This example adds a Shared Bidding Strategy and uses it to construct a
|
22
|
+
# campaign.
|
23
|
+
#
|
24
|
+
# Tags: BiddingStrategyService.mutate, CampaignService.mutate
|
25
|
+
# Tags: BudgetService.mutate
|
26
|
+
|
27
|
+
require 'adwords_api'
|
28
|
+
require 'date'
|
29
|
+
|
30
|
+
def use_shared_bidding_strategy()
|
31
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
|
+
# when called without parameters.
|
33
|
+
adwords = AdwordsApi::Api.new
|
34
|
+
|
35
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
36
|
+
# the configuration file or provide your own logger:
|
37
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
38
|
+
|
39
|
+
budget_srv = adwords.service(:BudgetService, API_VERSION)
|
40
|
+
bidding_srv = adwords.service(:BiddingStrategyService, API_VERSION)
|
41
|
+
campaign_srv = adwords.service(:CampaignService, API_VERSION)
|
42
|
+
|
43
|
+
# Create a budget, which can be shared by multiple campaigns.
|
44
|
+
budget = {
|
45
|
+
:name => 'Interplanetary budget #%d' % (Time.new.to_f * 1000).to_i,
|
46
|
+
:amount => {:micro_amount => 50000000},
|
47
|
+
:delivery_method => 'STANDARD',
|
48
|
+
:period => 'DAILY',
|
49
|
+
:is_explicitly_shared => true
|
50
|
+
}
|
51
|
+
return_budget = budget_srv.mutate([
|
52
|
+
{:operator => 'ADD', :operand => budget}])
|
53
|
+
budget_id = return_budget[:value].first[:budget_id]
|
54
|
+
|
55
|
+
# Create a shared bidding strategy.
|
56
|
+
shared_bidding_strategy = {
|
57
|
+
:name => 'Maximize Clicks #%d' % (Time.new.to_f * 1000).to_i,
|
58
|
+
:bidding_scheme => {
|
59
|
+
:xsi_type => 'TargetSpendBiddingScheme',
|
60
|
+
# Optionally set additional bidding scheme parameters.
|
61
|
+
:bid_ceiling => {:micro_amount => 20000000},
|
62
|
+
:spend_target => {:micro_amount => 40000000}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return_strategy = bidding_srv.mutate([
|
66
|
+
{:operator => 'ADD', :operand => shared_bidding_strategy}])
|
67
|
+
|
68
|
+
bidding_strategy = return_strategy[:value].first
|
69
|
+
puts ("Shared bidding strategy with name '%s' and ID %d of type '%s' was " +
|
70
|
+
'created') %
|
71
|
+
[bidding_strategy[:name], bidding_strategy[:id], bidding_strategy[:type]]
|
72
|
+
|
73
|
+
# Create campaigns.
|
74
|
+
campaigns = [
|
75
|
+
{
|
76
|
+
:name => "Interplanetary Cruise #%d" % (Time.new.to_f * 1000).to_i,
|
77
|
+
:status => 'PAUSED',
|
78
|
+
:bidding_strategy_configuration => {
|
79
|
+
:bidding_strategy_id => bidding_strategy[:id]
|
80
|
+
},
|
81
|
+
# Budget (required) - note only the budget ID is required.
|
82
|
+
:budget => {:budget_id => budget_id},
|
83
|
+
# Set the campaign network options to Search, Content and Search Network.
|
84
|
+
:network_setting => {
|
85
|
+
:target_google_search => true,
|
86
|
+
:target_search_network => true,
|
87
|
+
:target_content_network => true
|
88
|
+
},
|
89
|
+
:settings => [
|
90
|
+
{
|
91
|
+
:xsi_type => 'KeywordMatchSetting',
|
92
|
+
:opt_in => true
|
93
|
+
}
|
94
|
+
]
|
95
|
+
},
|
96
|
+
{
|
97
|
+
:name => "Interplanetary Cruise banner #%d" % (Time.new.to_f * 1000).to_i,
|
98
|
+
:status => 'PAUSED',
|
99
|
+
:bidding_strategy_configuration => {
|
100
|
+
:bidding_strategy_id => bidding_strategy[:id]
|
101
|
+
},
|
102
|
+
:budget => {:budget_id => budget_id},
|
103
|
+
:settings => [
|
104
|
+
{
|
105
|
+
:xsi_type => 'KeywordMatchSetting',
|
106
|
+
:opt_in => true
|
107
|
+
}
|
108
|
+
],
|
109
|
+
:network_setting => {
|
110
|
+
:target_google_search => false,
|
111
|
+
:target_search_network => false,
|
112
|
+
:target_content_network => true
|
113
|
+
}
|
114
|
+
}
|
115
|
+
]
|
116
|
+
|
117
|
+
# Prepare for adding campaign.
|
118
|
+
operations = campaigns.map do |campaign|
|
119
|
+
{:operator => 'ADD', :operand => campaign}
|
120
|
+
end
|
121
|
+
|
122
|
+
# Add campaign.
|
123
|
+
response = campaign_srv.mutate(operations)
|
124
|
+
if response and response[:value]
|
125
|
+
response[:value].each do |campaign|
|
126
|
+
puts "Campaign with name '%s' and ID %d was added." %
|
127
|
+
[campaign[:name], campaign[:id]]
|
128
|
+
end
|
129
|
+
else
|
130
|
+
raise new StandardError, 'No campaigns were added.'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
if __FILE__ == $0
|
135
|
+
API_VERSION = :v201402
|
136
|
+
|
137
|
+
begin
|
138
|
+
use_shared_bidding_strategy()
|
139
|
+
|
140
|
+
# Authorization error.
|
141
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
142
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
143
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
144
|
+
"to retrieve and store OAuth2 tokens."
|
145
|
+
puts "See this wiki page for more details:\n\n " +
|
146
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
147
|
+
|
148
|
+
# HTTP errors.
|
149
|
+
rescue AdsCommon::Errors::HttpError => e
|
150
|
+
puts "HTTP Error: %s" % e
|
151
|
+
|
152
|
+
# API errors.
|
153
|
+
rescue AdwordsApi::Errors::ApiException => e
|
154
|
+
puts "Message: %s" % e.message
|
155
|
+
puts 'Errors:'
|
156
|
+
e.errors.each_with_index do |error, index|
|
157
|
+
puts "\tError [%d]:" % (index + 1)
|
158
|
+
error.each do |field, value|
|
159
|
+
puts "\t\t%s: %s" % [field, value]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This example illustrates how to create ad groups. To get a list of existing
|
22
|
+
# campaigns run get_campaigns.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_ad_groups(campaign_id)
|
29
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
30
|
+
# when called without parameters.
|
31
|
+
adwords = AdwordsApi::Api.new
|
32
|
+
|
33
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
34
|
+
# the configuration file or provide your own logger:
|
35
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
36
|
+
|
37
|
+
ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
|
38
|
+
|
39
|
+
ad_groups = [
|
40
|
+
{
|
41
|
+
:name => "Earth to Mars Cruises #%d" % (Time.new.to_f * 1000).to_i,
|
42
|
+
:status => 'ENABLED',
|
43
|
+
:campaign_id => campaign_id,
|
44
|
+
:bidding_strategy_configuration => {
|
45
|
+
:bids => [
|
46
|
+
{
|
47
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the
|
48
|
+
# object being created. It's only necessary when you must provide
|
49
|
+
# an explicit type that the client library can't infer.
|
50
|
+
:xsi_type => 'CpcBid',
|
51
|
+
:bid => {:micro_amount => 10000000}
|
52
|
+
}
|
53
|
+
]
|
54
|
+
},
|
55
|
+
:settings => [
|
56
|
+
# Targetting restriction settings - these setting only affect serving
|
57
|
+
# for the Display Network.
|
58
|
+
{
|
59
|
+
:xsi_type => 'TargetingSetting',
|
60
|
+
:details => [
|
61
|
+
# Restricting to serve ads that match your ad group placements.
|
62
|
+
{
|
63
|
+
:xsi_type => 'TargetingSettingDetail',
|
64
|
+
:criterion_type_group => 'PLACEMENT',
|
65
|
+
:target_all => true
|
66
|
+
},
|
67
|
+
# Using your ad group verticals only for bidding.
|
68
|
+
{
|
69
|
+
:xsi_type => 'TargetingSettingDetail',
|
70
|
+
:criterion_type_group => 'VERTICAL',
|
71
|
+
:target_all => false
|
72
|
+
}
|
73
|
+
]
|
74
|
+
}
|
75
|
+
]
|
76
|
+
},
|
77
|
+
{
|
78
|
+
:name => 'Earth to Pluto Cruises #%d' % (Time.new.to_f * 1000).to_i,
|
79
|
+
:status => 'ENABLED',
|
80
|
+
:campaign_id => campaign_id,
|
81
|
+
:bidding_strategy_configuration => {
|
82
|
+
:bids => [
|
83
|
+
{
|
84
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the
|
85
|
+
# object being created. It's only necessary when you must provide
|
86
|
+
# an explicit type that the client library can't infer.
|
87
|
+
:xsi_type => 'CpcBid',
|
88
|
+
:bid => {:micro_amount => 10000000}
|
89
|
+
}
|
90
|
+
]
|
91
|
+
}
|
92
|
+
}
|
93
|
+
]
|
94
|
+
|
95
|
+
# Prepare operations for adding ad groups.
|
96
|
+
operations = ad_groups.map do |ad_group|
|
97
|
+
{:operator => 'ADD', :operand => ad_group}
|
98
|
+
end
|
99
|
+
|
100
|
+
# Add ad groups.
|
101
|
+
response = ad_group_srv.mutate(operations)
|
102
|
+
if response and response[:value]
|
103
|
+
response[:value].each do |ad_group|
|
104
|
+
puts "Ad group ID %d was successfully added." % ad_group[:id]
|
105
|
+
end
|
106
|
+
else
|
107
|
+
raise StandardError, 'No ad group was added'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
if __FILE__ == $0
|
112
|
+
API_VERSION = :v201402
|
113
|
+
|
114
|
+
begin
|
115
|
+
# Campaign ID to add ad group to.
|
116
|
+
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
117
|
+
add_ad_groups(campaign_id)
|
118
|
+
|
119
|
+
# Authorization error.
|
120
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
121
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
122
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
123
|
+
"to retrieve and store OAuth2 tokens."
|
124
|
+
puts "See this wiki page for more details:\n\n " +
|
125
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
126
|
+
|
127
|
+
# HTTP errors.
|
128
|
+
rescue AdsCommon::Errors::HttpError => e
|
129
|
+
puts "HTTP Error: %s" % e
|
130
|
+
|
131
|
+
# API errors.
|
132
|
+
rescue AdwordsApi::Errors::ApiException => e
|
133
|
+
puts "Message: %s" % e.message
|
134
|
+
puts 'Errors:'
|
135
|
+
e.errors.each_with_index do |error, index|
|
136
|
+
puts "\tError [%d]:" % (index + 1)
|
137
|
+
error.each do |field, value|
|
138
|
+
puts "\t\t%s: %s" % [field, value]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This example illustrates how to create ad groups. To get a list of existing
|
22
|
+
# campaigns run get_campaigns.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_ad_groups(campaign_id)
|
29
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
30
|
+
# when called without parameters.
|
31
|
+
adwords = AdwordsApi::Api.new
|
32
|
+
|
33
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
34
|
+
# the configuration file or provide your own logger:
|
35
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
36
|
+
|
37
|
+
ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
|
38
|
+
|
39
|
+
ad_groups = [
|
40
|
+
{
|
41
|
+
:name => "Earth to Mars Cruises #%d" % (Time.new.to_f * 1000).to_i,
|
42
|
+
:status => 'ENABLED',
|
43
|
+
:campaign_id => campaign_id,
|
44
|
+
:bidding_strategy_configuration => {
|
45
|
+
:bids => [
|
46
|
+
{
|
47
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the
|
48
|
+
# object being created. It's only necessary when you must provide
|
49
|
+
# an explicit type that the client library can't infer.
|
50
|
+
:xsi_type => 'CpcBid',
|
51
|
+
<<<<<<< HEAD
|
52
|
+
:bid => {:micro_amount => 10000000}
|
53
|
+
=======
|
54
|
+
:bid => {:micro_amount => 10000000},
|
55
|
+
:content_bid => {:micro_amount => 2000000}
|
56
|
+
>>>>>>> 85fa7b7254957cb6ba598e7e308db3c24eb45845
|
57
|
+
}
|
58
|
+
]
|
59
|
+
},
|
60
|
+
:settings => [
|
61
|
+
# Targetting restriction settings - these setting only affect serving
|
62
|
+
# for the Display Network.
|
63
|
+
{
|
64
|
+
:xsi_type => 'TargetingSetting',
|
65
|
+
:details => [
|
66
|
+
# Restricting to serve ads that match your ad group placements.
|
67
|
+
{
|
68
|
+
:xsi_type => 'TargetingSettingDetail',
|
69
|
+
:criterion_type_group => 'PLACEMENT',
|
70
|
+
:target_all => true
|
71
|
+
},
|
72
|
+
# Using your ad group verticals only for bidding.
|
73
|
+
{
|
74
|
+
:xsi_type => 'TargetingSettingDetail',
|
75
|
+
:criterion_type_group => 'VERTICAL',
|
76
|
+
:target_all => false
|
77
|
+
}
|
78
|
+
]
|
79
|
+
}
|
80
|
+
]
|
81
|
+
},
|
82
|
+
{
|
83
|
+
:name => 'Earth to Pluto Cruises #%d' % (Time.new.to_f * 1000).to_i,
|
84
|
+
:status => 'ENABLED',
|
85
|
+
:campaign_id => campaign_id,
|
86
|
+
:bidding_strategy_configuration => {
|
87
|
+
:bids => [
|
88
|
+
{
|
89
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the
|
90
|
+
# object being created. It's only necessary when you must provide
|
91
|
+
# an explicit type that the client library can't infer.
|
92
|
+
:xsi_type => 'CpcBid',
|
93
|
+
:bid => {:micro_amount => 10000000}
|
94
|
+
}
|
95
|
+
]
|
96
|
+
}
|
97
|
+
}
|
98
|
+
]
|
99
|
+
|
100
|
+
# Prepare operations for adding ad groups.
|
101
|
+
operations = ad_groups.map do |ad_group|
|
102
|
+
{:operator => 'ADD', :operand => ad_group}
|
103
|
+
end
|
104
|
+
|
105
|
+
# Add ad groups.
|
106
|
+
response = ad_group_srv.mutate(operations)
|
107
|
+
if response and response[:value]
|
108
|
+
response[:value].each do |ad_group|
|
109
|
+
puts "Ad group ID %d was successfully added." % ad_group[:id]
|
110
|
+
end
|
111
|
+
else
|
112
|
+
raise StandardError, 'No ad group was added'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if __FILE__ == $0
|
117
|
+
API_VERSION = :v201402
|
118
|
+
|
119
|
+
begin
|
120
|
+
# Campaign ID to add ad group to.
|
121
|
+
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
122
|
+
add_ad_groups(campaign_id)
|
123
|
+
|
124
|
+
# Authorization error.
|
125
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
126
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
127
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
128
|
+
"to retrieve and store OAuth2 tokens."
|
129
|
+
puts "See this wiki page for more details:\n\n " +
|
130
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
131
|
+
|
132
|
+
# HTTP errors.
|
133
|
+
rescue AdsCommon::Errors::HttpError => e
|
134
|
+
puts "HTTP Error: %s" % e
|
135
|
+
|
136
|
+
# API errors.
|
137
|
+
rescue AdwordsApi::Errors::ApiException => e
|
138
|
+
puts "Message: %s" % e.message
|
139
|
+
puts 'Errors:'
|
140
|
+
e.errors.each_with_index do |error, index|
|
141
|
+
puts "\tError [%d]:" % (index + 1)
|
142
|
+
error.each do |field, value|
|
143
|
+
puts "\t\t%s: %s" % [field, value]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|