google-adx-buyer-api 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/README +39 -25
- data/examples/v201109/account_management/get_account_changes.rb +137 -0
- data/examples/{v201008 → v201109/basic_operations}/add_ad_group.rb +18 -28
- data/examples/{v201003 → v201109/basic_operations}/add_campaign.rb +28 -30
- data/examples/{v201008/add_ad_group_criteria.rb → v201109/basic_operations/add_placements.rb} +45 -46
- data/examples/v201109/basic_operations/add_thirdparty_redirect_ad.rb +105 -0
- data/examples/{v201008 → v201109/basic_operations}/delete_ad.rb +21 -35
- data/examples/{v201101 → v201109/basic_operations}/delete_ad_group.rb +18 -28
- data/examples/v201109/{delete_campaign.rb → basic_operations/delete_campaign.rb} +18 -28
- data/examples/{v201008/delete_ad_group_criterion.rb → v201109/basic_operations/delete_placement.rb} +24 -33
- data/examples/{v201101/get_all_ad_groups.rb → v201109/basic_operations/get_ad_groups.rb} +21 -35
- data/examples/{v201101/get_all_campaigns.rb → v201109/basic_operations/get_campaigns.rb} +14 -23
- data/examples/{v201008/get_all_ad_group_criteria.rb → v201109/basic_operations/get_placements.rb} +37 -36
- data/examples/v201109/{get_all_ads.rb → basic_operations/get_thirdparty_redirect_ads.rb} +37 -36
- data/examples/v201109/{get_client_customer_id.rb → basic_operations/pause_ad.rb} +27 -33
- data/examples/{v201003 → v201109/basic_operations}/update_ad_group.rb +18 -32
- data/examples/{v201101 → v201109/basic_operations}/update_campaign.rb +19 -33
- data/examples/{v201003/delete_ad_group_criterion.rb → v201109/basic_operations/update_placement.rb} +35 -36
- data/examples/v201109/{perform_mutate_job.rb → campaign_management/add_placements_in_bulk.rb} +11 -11
- data/examples/v201109/{get_all_disapproved_ads.rb → campaign_management/get_all_disapproved_ads.rb} +18 -28
- data/examples/v201109/error_handling/handle_captcha_challenge.rb +93 -0
- data/examples/v201109/error_handling/handle_partial_failures.rb +117 -0
- data/examples/v201109/error_handling/handle_policy_violation_error.rb +138 -0
- data/examples/v201109/error_handling/handle_two_factor_authorization_error.rb +87 -0
- data/examples/v201109/misc/get_all_images_and_videos.rb +101 -0
- data/examples/{v201101 → v201109/misc}/upload_image.rb +23 -33
- data/examples/v201109/{get_all_campaigns.rb → misc/use_oauth.rb} +42 -31
- data/examples/{v201003/get_related_placements.rb → v201109/optimization/get_placement_ideas.rb} +32 -37
- data/examples/{v201008/add_user_list.rb → v201109/remarketing/add_audience.rb} +49 -34
- data/examples/v201109/{add_conversion.rb → remarketing/add_conversion_tracker.rb} +31 -35
- data/examples/v201109/{download_adhoc_report.rb → reporting/download_criteria_report.rb} +24 -24
- data/examples/{v201008/download_report.rb → v201109/reporting/download_defined_report.rb} +20 -29
- data/examples/v201109/reporting/get_campaign_stats.rb +105 -0
- data/examples/{v201008/get_all_report_definitions.rb → v201109/reporting/get_defined_reports.rb} +18 -27
- data/examples/v201109/{get_all_carriers.rb → reporting/get_report_fields.rb} +18 -19
- data/examples/v201109/reporting/parallel_report_download.rb +159 -0
- data/examples/v201109/{add_campaign_targeting_criteria.rb → targeting/add_campaign_targeting_criteria.rb} +27 -19
- data/examples/v201109/targeting/get_campaign_targeting_criteria.rb +104 -0
- data/examples/v201109/{get_all_languages.rb → targeting/get_targetable_languages_and_carriers.rb} +18 -9
- data/examples/v201109/{get_location_criteria.rb → targeting/lookup_location.rb} +7 -7
- metadata +59 -191
- data/Rakefile +0 -50
- data/examples/v201003/add_ad_group.rb +0 -98
- data/examples/v201003/add_ad_group_criteria.rb +0 -100
- data/examples/v201003/add_ads.rb +0 -110
- data/examples/v201003/add_negative_campaign_criterion.rb +0 -95
- data/examples/v201003/add_placement_performance_report_definition.rb +0 -108
- data/examples/v201003/check_campaigns.rb +0 -132
- data/examples/v201003/delete_ad.rb +0 -94
- data/examples/v201003/delete_ad_group.rb +0 -86
- data/examples/v201003/delete_campaign.rb +0 -87
- data/examples/v201003/download_report.rb +0 -76
- data/examples/v201003/get_all_active_ad_group_criteria.rb +0 -93
- data/examples/v201003/get_all_ad_group_criteria.rb +0 -91
- data/examples/v201003/get_all_ad_groups.rb +0 -88
- data/examples/v201003/get_all_ads.rb +0 -91
- data/examples/v201003/get_all_campaign_targets.rb +0 -83
- data/examples/v201003/get_all_campaigns.rb +0 -83
- data/examples/v201003/get_all_disapproved_ads.rb +0 -94
- data/examples/v201003/get_all_images.rb +0 -88
- data/examples/v201003/get_all_paused_campaigns.rb +0 -86
- data/examples/v201003/get_all_report_definitions.rb +0 -84
- data/examples/v201003/get_criterion_bid_landscape.rb +0 -105
- data/examples/v201003/get_geo_location_info.rb +0 -108
- data/examples/v201003/get_report_fields.rb +0 -81
- data/examples/v201003/perform_bulk_mutate_job.rb +0 -222
- data/examples/v201003/set_campaign_targets.rb +0 -124
- data/examples/v201003/update_ad.rb +0 -95
- data/examples/v201003/update_ad_group_criterion.rb +0 -108
- data/examples/v201003/update_campaign.rb +0 -92
- data/examples/v201003/upload_image.rb +0 -97
- data/examples/v201008/add_ads.rb +0 -110
- data/examples/v201008/add_campaign.rb +0 -101
- data/examples/v201008/add_negative_campaign_criterion.rb +0 -95
- data/examples/v201008/add_placement_performance_report_definition.rb +0 -108
- data/examples/v201008/check_campaigns.rb +0 -132
- data/examples/v201008/delete_ad_group.rb +0 -86
- data/examples/v201008/delete_bulk_mutate_job.rb +0 -96
- data/examples/v201008/delete_campaign.rb +0 -87
- data/examples/v201008/delete_user_list.rb +0 -87
- data/examples/v201008/get_all_account_changes.rb +0 -144
- data/examples/v201008/get_all_active_ad_group_criteria.rb +0 -93
- data/examples/v201008/get_all_ad_groups.rb +0 -88
- data/examples/v201008/get_all_ads.rb +0 -91
- data/examples/v201008/get_all_campaign_targets.rb +0 -83
- data/examples/v201008/get_all_campaigns.rb +0 -83
- data/examples/v201008/get_all_disapproved_ads.rb +0 -94
- data/examples/v201008/get_all_images.rb +0 -88
- data/examples/v201008/get_all_paused_campaigns.rb +0 -86
- data/examples/v201008/get_all_user_lists.rb +0 -84
- data/examples/v201008/get_bulk_mutate_job.rb +0 -106
- data/examples/v201008/get_campaign_alerts.rb +0 -103
- data/examples/v201008/get_criterion_bid_landscape.rb +0 -105
- data/examples/v201008/get_geo_location_info.rb +0 -108
- data/examples/v201008/get_related_placements.rb +0 -114
- data/examples/v201008/get_report_fields.rb +0 -81
- data/examples/v201008/perform_bulk_mutate_job.rb +0 -222
- data/examples/v201008/set_campaign_targets.rb +0 -124
- data/examples/v201008/update_ad.rb +0 -95
- data/examples/v201008/update_ad_group.rb +0 -90
- data/examples/v201008/update_ad_group_criterion.rb +0 -108
- data/examples/v201008/update_campaign.rb +0 -93
- data/examples/v201008/update_user_list.rb +0 -91
- data/examples/v201008/upload_image.rb +0 -97
- data/examples/v201101/add_ad_group.rb +0 -98
- data/examples/v201101/add_ad_group_criteria.rb +0 -100
- data/examples/v201101/add_ads.rb +0 -110
- data/examples/v201101/add_campaign.rb +0 -108
- data/examples/v201101/add_conversion.rb +0 -97
- data/examples/v201101/add_negative_campaign_criterion.rb +0 -95
- data/examples/v201101/add_placement_performance_report_definition.rb +0 -108
- data/examples/v201101/add_rtb_campaign.rb +0 -113
- data/examples/v201101/add_user_list.rb +0 -122
- data/examples/v201101/check_campaigns.rb +0 -132
- data/examples/v201101/delete_ad.rb +0 -94
- data/examples/v201101/delete_ad_group_criterion.rb +0 -95
- data/examples/v201101/delete_bulk_mutate_job.rb +0 -96
- data/examples/v201101/delete_campaign.rb +0 -87
- data/examples/v201101/delete_user_list.rb +0 -87
- data/examples/v201101/download_report.rb +0 -76
- data/examples/v201101/get_ad_group_bid_landscape.rb +0 -103
- data/examples/v201101/get_all_account_changes.rb +0 -146
- data/examples/v201101/get_all_active_ad_group_criteria.rb +0 -106
- data/examples/v201101/get_all_ad_group_criteria.rb +0 -97
- data/examples/v201101/get_all_ads.rb +0 -99
- data/examples/v201101/get_all_campaign_targets.rb +0 -83
- data/examples/v201101/get_all_conversions.rb +0 -88
- data/examples/v201101/get_all_disapproved_ads.rb +0 -102
- data/examples/v201101/get_all_images.rb +0 -90
- data/examples/v201101/get_all_paused_campaigns.rb +0 -92
- data/examples/v201101/get_all_report_definitions.rb +0 -84
- data/examples/v201101/get_all_user_lists.rb +0 -87
- data/examples/v201101/get_bulk_mutate_job.rb +0 -106
- data/examples/v201101/get_campaign_alerts.rb +0 -103
- data/examples/v201101/get_criterion_bid_landscape.rb +0 -102
- data/examples/v201101/get_geo_location_info.rb +0 -108
- data/examples/v201101/get_related_placements.rb +0 -114
- data/examples/v201101/get_report_fields.rb +0 -81
- data/examples/v201101/perform_bulk_mutate_job.rb +0 -222
- data/examples/v201101/set_campaign_targets.rb +0 -111
- data/examples/v201101/update_ad.rb +0 -95
- data/examples/v201101/update_ad_group.rb +0 -90
- data/examples/v201101/update_ad_group_criterion.rb +0 -108
- data/examples/v201101/update_conversion.rb +0 -96
- data/examples/v201101/update_user_list.rb +0 -91
- data/examples/v201109/add_ad_group.rb +0 -98
- data/examples/v201109/add_ad_group_criteria.rb +0 -100
- data/examples/v201109/add_ads.rb +0 -110
- data/examples/v201109/add_campaign.rb +0 -108
- data/examples/v201109/add_negative_campaign_criterion.rb +0 -95
- data/examples/v201109/add_rtb_campaign.rb +0 -113
- data/examples/v201109/add_user_list.rb +0 -122
- data/examples/v201109/check_campaigns.rb +0 -132
- data/examples/v201109/delete_ad.rb +0 -94
- data/examples/v201109/delete_ad_group.rb +0 -86
- data/examples/v201109/delete_ad_group_criterion.rb +0 -95
- data/examples/v201109/delete_bulk_mutate_job.rb +0 -96
- data/examples/v201109/delete_user_list.rb +0 -87
- data/examples/v201109/download_report.rb +0 -76
- data/examples/v201109/get_ad_group_bid_landscape.rb +0 -103
- data/examples/v201109/get_all_account_changes.rb +0 -146
- data/examples/v201109/get_all_active_ad_group_criteria.rb +0 -106
- data/examples/v201109/get_all_ad_group_criteria.rb +0 -98
- data/examples/v201109/get_all_ad_groups.rb +0 -94
- data/examples/v201109/get_all_campaign_targets.rb +0 -83
- data/examples/v201109/get_all_conversions.rb +0 -88
- data/examples/v201109/get_all_images.rb +0 -90
- data/examples/v201109/get_all_paused_campaigns.rb +0 -92
- data/examples/v201109/get_all_report_definitions.rb +0 -84
- data/examples/v201109/get_all_user_lists.rb +0 -87
- data/examples/v201109/get_bulk_mutate_job.rb +0 -106
- data/examples/v201109/get_campaign_alerts.rb +0 -103
- data/examples/v201109/get_criterion_bid_landscape.rb +0 -102
- data/examples/v201109/get_geo_location_info.rb +0 -108
- data/examples/v201109/get_related_placements.rb +0 -114
- data/examples/v201109/get_report_fields.rb +0 -81
- data/examples/v201109/perform_bulk_mutate_job.rb +0 -222
- data/examples/v201109/update_ad.rb +0 -95
- data/examples/v201109/update_ad_group.rb +0 -90
- data/examples/v201109/update_ad_group_criterion.rb +0 -108
- data/examples/v201109/update_campaign.rb +0 -93
- data/examples/v201109/update_conversion.rb +0 -96
- data/examples/v201109/update_user_list.rb +0 -91
- data/examples/v201109/upload_image.rb +0 -97
@@ -1,6 +1,7 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
2
3
|
#
|
3
|
-
# Author:: api.
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
5
|
#
|
5
6
|
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
7
|
#
|
@@ -17,17 +18,13 @@
|
|
17
18
|
# See the License for the specific language governing permissions and
|
18
19
|
# limitations under the License.
|
19
20
|
#
|
20
|
-
# This example illustrates how to
|
21
|
+
# This example illustrates how to use OAuth authentication method.
|
21
22
|
#
|
22
23
|
# Tags: CampaignService.get
|
23
24
|
|
24
|
-
require 'rubygems'
|
25
|
-
gem 'google-adwords-api'
|
26
25
|
require 'adwords_api'
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
def get_all_campaigns()
|
27
|
+
def use_oauth()
|
31
28
|
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
29
|
# when called without parameters.
|
33
30
|
adwords = AdwordsApi::Api.new
|
@@ -41,45 +38,59 @@ def get_all_campaigns()
|
|
41
38
|
# Get all the campaigns for this account; empty selector.
|
42
39
|
selector = {
|
43
40
|
:fields => ['Id', 'Name', 'Status'],
|
44
|
-
:ordering => [
|
41
|
+
:ordering => [
|
42
|
+
{:field => 'Name', :sort_order => 'ASCENDING'}
|
43
|
+
]
|
45
44
|
}
|
46
|
-
|
45
|
+
|
46
|
+
retry_count = 0
|
47
|
+
|
48
|
+
begin
|
49
|
+
response = campaign_srv.get(selector)
|
50
|
+
rescue AdsCommon::Errors::OAuthVerificationRequired => e
|
51
|
+
if retry_count < MAX_RETRIES
|
52
|
+
puts "Hit Auth error, please navigate to URL:\n\t%s" % e.oauth_url
|
53
|
+
print 'log in and type the verification code: '
|
54
|
+
verification_code = gets.chomp
|
55
|
+
adwords.credential_handler.set_credential(
|
56
|
+
:oauth_verification_code, verification_code)
|
57
|
+
retry_count += 1
|
58
|
+
retry
|
59
|
+
else
|
60
|
+
raise AdsCommon::Errors::AuthError, 'Failed to authenticate.'
|
61
|
+
end
|
62
|
+
end
|
47
63
|
|
48
64
|
if response and response[:entries]
|
49
65
|
campaigns = response[:entries]
|
50
66
|
campaigns.each do |campaign|
|
51
|
-
puts "Campaign
|
52
|
-
|
67
|
+
puts "Campaign ID %d, name '%s' and status '%s'" %
|
68
|
+
[campaign[:id], campaign[:name], campaign[:status]]
|
53
69
|
end
|
54
70
|
else
|
55
|
-
puts
|
71
|
+
puts 'No campaigns were found.'
|
56
72
|
end
|
57
73
|
end
|
58
74
|
|
59
75
|
if __FILE__ == $0
|
76
|
+
API_VERSION = :v201109
|
77
|
+
MAX_RETRIES = 3
|
78
|
+
|
60
79
|
begin
|
61
|
-
|
80
|
+
use_oauth()
|
62
81
|
|
63
|
-
#
|
64
|
-
rescue
|
65
|
-
puts
|
66
|
-
puts 'Source: %s' % e.backtrace.first
|
82
|
+
# HTTP errors.
|
83
|
+
rescue AdsCommon::Errors::HttpError => e
|
84
|
+
puts "HTTP Error: %s" % e
|
67
85
|
|
68
|
-
# API
|
86
|
+
# API errors.
|
69
87
|
rescue AdwordsApi::Errors::ApiException => e
|
70
|
-
puts
|
71
|
-
puts 'Message: %s' % e.message
|
72
|
-
puts 'Code: %d' % e.code if e.code
|
73
|
-
puts 'Trigger: %s' % e.trigger if e.trigger
|
88
|
+
puts "Message: %s" % e.message
|
74
89
|
puts 'Errors:'
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
if field != :xsi_type
|
80
|
-
puts ' %s: %s' % [field, value]
|
81
|
-
end
|
82
|
-
end
|
90
|
+
e.errors.each_with_index do |error, index|
|
91
|
+
puts "\tError [%d]:" % (index + 1)
|
92
|
+
error.each do |field, value|
|
93
|
+
puts "\t\t%s: %s" % [field, value]
|
83
94
|
end
|
84
95
|
end
|
85
96
|
end
|
data/examples/{v201003/get_related_placements.rb → v201109/optimization/get_placement_ideas.rb}
RENAMED
@@ -1,4 +1,5 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
2
3
|
#
|
3
4
|
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
4
5
|
#
|
@@ -22,13 +23,10 @@
|
|
22
23
|
#
|
23
24
|
# Tags: TargetingIdeaService.get
|
24
25
|
|
25
|
-
require 'rubygems'
|
26
|
-
gem 'google-adwords-api'
|
27
26
|
require 'adwords_api'
|
27
|
+
require 'adwords_api/utils'
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
def get_related_placements()
|
29
|
+
def get_placement_ideas(url)
|
32
30
|
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
33
31
|
# when called without parameters.
|
34
32
|
adwords = AdwordsApi::Api.new
|
@@ -39,14 +37,11 @@ def get_related_placements()
|
|
39
37
|
|
40
38
|
targeting_idea_srv = adwords.service(:TargetingIdeaService, API_VERSION)
|
41
39
|
|
42
|
-
results_per_page = 10
|
43
|
-
url = 'mars.google.com'
|
44
|
-
|
45
40
|
# Construct selector.
|
46
41
|
selector = {
|
47
42
|
:idea_type => 'PLACEMENT',
|
48
43
|
:request_type => 'IDEAS',
|
49
|
-
:requested_attribute_types => ['
|
44
|
+
:requested_attribute_types => ['CRITERION'],
|
50
45
|
:search_parameters => [{
|
51
46
|
# The 'xsi_type' field allows you to specify the xsi:type of the object
|
52
47
|
# being created. It's only necessary when you must provide an explicit
|
@@ -57,54 +52,54 @@ def get_related_placements()
|
|
57
52
|
}],
|
58
53
|
:paging => {
|
59
54
|
:start_index => 0,
|
60
|
-
:number_results =>
|
55
|
+
:number_results => PAGE_SIZE
|
61
56
|
}
|
62
57
|
}
|
63
58
|
|
59
|
+
# Define initial values.
|
60
|
+
offset = 0
|
64
61
|
results = []
|
65
|
-
|
62
|
+
|
66
63
|
begin
|
67
|
-
selector[:paging][:start_index] = index
|
68
64
|
# Perform request.
|
69
65
|
page = targeting_idea_srv.get(selector)
|
70
66
|
results += page[:entries] if page and page[:entries]
|
71
|
-
|
72
|
-
|
67
|
+
|
68
|
+
# Prepare next page request.
|
69
|
+
offset += PAGE_SIZE
|
70
|
+
selector[:paging][:start_index] = offset
|
71
|
+
end while offset < page[:total_num_entries]
|
73
72
|
|
74
73
|
# Display results.
|
75
74
|
results.each do |result|
|
76
75
|
data = AdwordsApi::Utils.map(result[:data])
|
77
|
-
placement = data['
|
78
|
-
puts "Related
|
76
|
+
placement = data['CRITERION'][:value]
|
77
|
+
puts "Related placement found at URL [%s]" % placement[:url]
|
79
78
|
end
|
80
|
-
puts "Total
|
81
|
-
|
79
|
+
puts "Total URLs found with keywords related to keywords at [%s]: %d." %
|
80
|
+
[url, results.length]
|
82
81
|
end
|
83
82
|
|
84
83
|
if __FILE__ == $0
|
84
|
+
API_VERSION = :v201109
|
85
|
+
PAGE_SIZE = 100
|
86
|
+
|
85
87
|
begin
|
86
|
-
|
88
|
+
url = 'INSERT_PLACEMENT_URL_HERE'
|
89
|
+
get_placement_ideas(url)
|
87
90
|
|
88
|
-
#
|
89
|
-
rescue
|
90
|
-
puts
|
91
|
-
puts 'Source: %s' % e.backtrace.first
|
91
|
+
# HTTP errors.
|
92
|
+
rescue AdsCommon::Errors::HttpError => e
|
93
|
+
puts "HTTP Error: %s" % e
|
92
94
|
|
93
|
-
# API
|
95
|
+
# API errors.
|
94
96
|
rescue AdwordsApi::Errors::ApiException => e
|
95
|
-
puts
|
96
|
-
puts 'Message: %s' % e.message
|
97
|
-
puts 'Code: %d' % e.code if e.code
|
98
|
-
puts 'Trigger: %s' % e.trigger if e.trigger
|
97
|
+
puts "Message: %s" % e.message
|
99
98
|
puts 'Errors:'
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
if field != :xsi_type
|
105
|
-
puts ' %s: %s' % [field, value]
|
106
|
-
end
|
107
|
-
end
|
99
|
+
e.errors.each_with_index do |error, index|
|
100
|
+
puts "\tError [%d]:" % (index + 1)
|
101
|
+
error.each do |field, value|
|
102
|
+
puts "\t\t%s: %s" % [field, value]
|
108
103
|
end
|
109
104
|
end
|
110
105
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
2
3
|
#
|
3
4
|
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
4
5
|
#
|
@@ -17,17 +18,14 @@
|
|
17
18
|
# See the License for the specific language governing permissions and
|
18
19
|
# limitations under the License.
|
19
20
|
#
|
20
|
-
# This example illustrates how to create a user list.
|
21
|
+
# This example illustrates how to create a user list (a.k.a. Audience) and shows
|
22
|
+
# its associated conversion tracker code snippet.
|
21
23
|
#
|
22
|
-
# Tags: UserListService.mutate
|
24
|
+
# Tags: UserListService.mutate, ConversionTrackerService.get
|
23
25
|
|
24
|
-
require 'rubygems'
|
25
|
-
gem 'google-adwords-api'
|
26
26
|
require 'adwords_api'
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
def add_user_list()
|
28
|
+
def add_audience()
|
31
29
|
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
30
|
# when called without parameters.
|
33
31
|
adwords = AdwordsApi::Api.new
|
@@ -37,9 +35,10 @@ def add_user_list()
|
|
37
35
|
# adwords.logger = Logger.new('adwords_xml.log')
|
38
36
|
|
39
37
|
user_list_srv = adwords.service(:UserListService, API_VERSION)
|
38
|
+
conv_tracker_srv = adwords.service(:ConversionTrackerService, API_VERSION)
|
40
39
|
|
41
40
|
# Prepare for adding remarketing user list.
|
42
|
-
name =
|
41
|
+
name = "Mars cruise customers #%d" % (Time.new.to_f * 1000).to_i
|
43
42
|
operation = {
|
44
43
|
:operator => 'ADD',
|
45
44
|
:operand => {
|
@@ -51,45 +50,61 @@ def add_user_list()
|
|
51
50
|
:description => 'A list of mars cruise customers in the last year',
|
52
51
|
:status => 'OPEN',
|
53
52
|
:membership_life_span => 365,
|
54
|
-
:conversion_types => [{:name => name}]
|
53
|
+
:conversion_types => [{:name => name}],
|
54
|
+
# Optional field.
|
55
|
+
:status => 'OPEN'
|
55
56
|
}
|
56
57
|
}
|
57
58
|
|
58
59
|
# Add user list.
|
59
60
|
response = user_list_srv.mutate([operation])
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
user_list = response[:value].first
|
62
|
+
|
63
|
+
# Get conversion snippets.
|
64
|
+
if user_list and user_list[:conversion_types]
|
65
|
+
conversion_ids = user_list[:conversion_types].map {|type| type[:id]}
|
66
|
+
selector = {
|
67
|
+
# We're actually interested in the 'Snippet' field, which is returned
|
68
|
+
# automatically.
|
69
|
+
:fields => ['Id'],
|
70
|
+
:predicates => [
|
71
|
+
{:field => 'Id', :operator => 'IN', :values => conversion_ids}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
conv_tracker_response = conv_tracker_srv.get(selector)
|
75
|
+
if conv_tracker_response and conv_tracker_response[:entries]
|
76
|
+
conversions = conv_tracker_response[:entries]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
puts "User list with name '%s' and ID %d was added." %
|
80
|
+
[user_list[:name], user_list[:id]]
|
81
|
+
# Display user list associated conversion code snippets.
|
82
|
+
if conversions
|
83
|
+
conversions.each do |conversion|
|
84
|
+
puts "Conversion type code snipped associated to the list:\n\t\t%s\n" %
|
85
|
+
conversion[:snippet]
|
86
|
+
end
|
66
87
|
end
|
67
88
|
end
|
68
89
|
|
69
90
|
if __FILE__ == $0
|
91
|
+
API_VERSION = :v201109
|
92
|
+
|
70
93
|
begin
|
71
|
-
|
94
|
+
add_audience()
|
72
95
|
|
73
|
-
#
|
74
|
-
rescue
|
75
|
-
puts
|
76
|
-
puts 'Source: %s' % e.backtrace.first
|
96
|
+
# HTTP errors.
|
97
|
+
rescue AdsCommon::Errors::HttpError => e
|
98
|
+
puts "HTTP Error: %s" % e
|
77
99
|
|
78
|
-
# API
|
100
|
+
# API errors.
|
79
101
|
rescue AdwordsApi::Errors::ApiException => e
|
80
|
-
puts
|
81
|
-
puts 'Message: %s' % e.message
|
82
|
-
puts 'Code: %d' % e.code if e.code
|
83
|
-
puts 'Trigger: %s' % e.trigger if e.trigger
|
102
|
+
puts "Message: %s" % e.message
|
84
103
|
puts 'Errors:'
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if field != :xsi_type
|
90
|
-
puts ' %s: %s' % [field, value]
|
91
|
-
end
|
92
|
-
end
|
104
|
+
e.errors.each_with_index do |error, index|
|
105
|
+
puts "\tError [%d]:" % (index + 1)
|
106
|
+
error.each do |field, value|
|
107
|
+
puts "\t\t%s: %s" % [field, value]
|
93
108
|
end
|
94
109
|
end
|
95
110
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
2
3
|
#
|
3
4
|
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
4
5
|
#
|
@@ -17,17 +18,13 @@
|
|
17
18
|
# See the License for the specific language governing permissions and
|
18
19
|
# limitations under the License.
|
19
20
|
#
|
20
|
-
# This example illustrates how to add an AdWords conversion.
|
21
|
+
# This example illustrates how to add an AdWords conversion tracker.
|
21
22
|
#
|
22
23
|
# Tags: ConversionTrackerService.mutate
|
23
24
|
|
24
|
-
require 'rubygems'
|
25
|
-
gem 'google-adwords-api'
|
26
25
|
require 'adwords_api'
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
def add_conversion()
|
27
|
+
def add_conversion_tracker()
|
31
28
|
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
29
|
# when called without parameters.
|
33
30
|
adwords = AdwordsApi::Api.new
|
@@ -46,51 +43,50 @@ def add_conversion()
|
|
46
43
|
# being created. It's only necessary when you must provide an explicit
|
47
44
|
# type that the client library can't infer.
|
48
45
|
:xsi_type => 'AdWordsConversionTracker',
|
49
|
-
:name =>
|
46
|
+
:name => "Earth to Mars Cruises Conversion #%d" %
|
50
47
|
(Time.new.to_f * 1000).to_i,
|
51
48
|
:category => 'DEFAULT',
|
52
49
|
:markup_language => 'HTML',
|
53
50
|
:http_protocol => 'HTTP',
|
54
|
-
:text_format => 'HIDDEN'
|
51
|
+
:text_format => 'HIDDEN',
|
52
|
+
# Optional fields:
|
53
|
+
:status => 'ENABLED',
|
54
|
+
:viewthrough_lookback_window => 15,
|
55
|
+
:viewthrough_conversion_de_dup_search => true,
|
56
|
+
:is_product_ads_chargeable => true,
|
57
|
+
:product_ads_chargeable_conversion_window => 15,
|
58
|
+
:conversion_page_language => 'en',
|
59
|
+
:background_color => '#0000FF',
|
60
|
+
:user_revenue_value => 'someJavascriptVariable'
|
55
61
|
}
|
56
62
|
}
|
57
63
|
|
58
64
|
# Add conversion.
|
59
65
|
response = conv_tracker_srv.mutate([operation])
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
" category \"#{conversion[:category]}\" was added."
|
65
|
-
else
|
66
|
-
puts 'No conversions were added.'
|
67
|
-
end
|
66
|
+
conversion = response[:value].first
|
67
|
+
puts ("Conversion with ID %d, name '%s', status '%s' and category '%s'" +
|
68
|
+
" was added.") % [conversion[:id], conversion[:name],
|
69
|
+
conversion[:status], conversion[:category]]
|
68
70
|
end
|
69
71
|
|
70
72
|
if __FILE__ == $0
|
73
|
+
API_VERSION = :v201109
|
74
|
+
|
71
75
|
begin
|
72
|
-
|
76
|
+
add_conversion_tracker()
|
73
77
|
|
74
|
-
#
|
75
|
-
rescue
|
76
|
-
puts
|
77
|
-
puts 'Source: %s' % e.backtrace.first
|
78
|
+
# HTTP errors.
|
79
|
+
rescue AdsCommon::Errors::HttpError => e
|
80
|
+
puts "HTTP Error: %s" % e
|
78
81
|
|
79
|
-
# API
|
82
|
+
# API errors.
|
80
83
|
rescue AdwordsApi::Errors::ApiException => e
|
81
|
-
puts
|
82
|
-
puts 'Message: %s' % e.message
|
83
|
-
puts 'Code: %d' % e.code if e.code
|
84
|
-
puts 'Trigger: %s' % e.trigger if e.trigger
|
84
|
+
puts "Message: %s" % e.message
|
85
85
|
puts 'Errors:'
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
if field != :xsi_type
|
91
|
-
puts ' %s: %s' % [field, value]
|
92
|
-
end
|
93
|
-
end
|
86
|
+
e.errors.each_with_index do |error, index|
|
87
|
+
puts "\tError [%d]:" % (index + 1)
|
88
|
+
error.each do |field, value|
|
89
|
+
puts "\t\t%s: %s" % [field, value]
|
94
90
|
end
|
95
91
|
end
|
96
92
|
end
|