Skip to content

Commit 7a151be

Browse files
authored
Changes for release v0_3. (#2)
1 parent 8f48b88 commit 7a151be

File tree

121 files changed

+10706
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+10706
-418
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
* 0.2.0:
2+
- Google Ads v0_3 release.
3+
14
* 0.1.0:
25
- Initial release with support for Google Ads API v0.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""This demonstrates how to add an ad group bid modifier for mobile devices.
15+
16+
To get ad group bid modifiers, run get_ad_group_bid_modifiers.py
17+
"""
18+
19+
from __future__ import absolute_import
20+
21+
import argparse
22+
import six
23+
import sys
24+
25+
import google.ads.google_ads.client
26+
27+
28+
def main(client, customer_id, ad_group_id, bid_modifier_value):
29+
ad_group_service = client.get_service('AdGroupService')
30+
ad_group_bm_service = client.get_service('AdGroupBidModifierService')
31+
32+
# Create ad group bid modifier for mobile devices with the specified ad
33+
# group ID and bid modifier value.
34+
ad_group_bid_modifier_operation = client.get_type(
35+
'AdGroupBidModifierOperation')
36+
ad_group_bid_modifier = ad_group_bid_modifier_operation.create
37+
38+
# Set the ad group.
39+
ad_group_bid_modifier.ad_group.value = ad_group_service.ad_group_path(
40+
customer_id, ad_group_id)
41+
42+
# Set the bid modifier.
43+
ad_group_bid_modifier.bid_modifier.value = bid_modifier_value
44+
45+
# Sets the device.
46+
ad_group_bid_modifier.device.type = client.get_type('DeviceEnum').MOBILE
47+
48+
# Add the ad group bid modifier.
49+
try:
50+
ad_group_bm_response = (
51+
ad_group_bm_service.mutate_ad_group_bid_modifiers(
52+
customer_id, [ad_group_bid_modifier_operation]))
53+
except google.ads.google_ads.errors.GoogleAdsException as ex:
54+
print('Request with ID "%s" failed with status "%s" and includes the '
55+
'following errors:' % (ex.request_id, ex.error.code().name))
56+
for error in ex.failure.errors:
57+
print('\tError with message "%s".' % error.message)
58+
if error.location:
59+
for field_path_element in error.location.field_path_elements:
60+
print('\t\tOn field: %s' % field_path_element.field_name)
61+
sys.exit(1)
62+
63+
print('Created ad group bid modifier: %s.'
64+
% ad_group_bm_response.results[0].resource_name)
65+
66+
67+
if __name__ == '__main__':
68+
# GoogleAdsClient will read a google-ads.yaml configuration file in the
69+
# home directory if none is specified.
70+
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
71+
.load_from_storage())
72+
73+
parser = argparse.ArgumentParser(
74+
description=('Adds an ad group bid modifier to the specified ad group '
75+
'ID, for the given customer ID.'))
76+
# The following argument(s) should be provided to run the example.
77+
parser.add_argument('-c', '--customer_id', type=six.text_type,
78+
required=True, help='The AdWords customer ID.')
79+
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
80+
required=True, help='The ad group ID.')
81+
parser.add_argument('-b', '--bid_modifier_value', type=float,
82+
required=False, default=1.5,
83+
help='The bid modifier value.')
84+
args = parser.parse_args()
85+
86+
main(google_ads_client, args.customer_id, args.ad_group_id,
87+
args.bid_modifier_value)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Demonstrates how to create a shared list of negative broad match keywords.
15+
16+
Note that the keywords will be attached to the specified campaign.
17+
"""
18+
19+
from __future__ import absolute_import
20+
21+
import argparse
22+
import six
23+
import sys
24+
import uuid
25+
26+
import google.ads.google_ads.client
27+
28+
29+
def main(client, customer_id, campaign_id):
30+
campaign_service = client.get_service('CampaignService')
31+
shared_set_service = client.get_service('SharedSetService')
32+
shared_criterion_service = client.get_service('SharedCriterionService')
33+
campaign_shared_set_service = client.get_service('CampaignSharedSetService')
34+
35+
# Create shared negative keyword set.
36+
shared_set_operation = client.get_type('SharedSetOperation')
37+
shared_set = shared_set_operation.create
38+
shared_set.name.value = 'API Negative keyword list - %s' % uuid.uuid4()
39+
shared_set.type = client.get_type('SharedSetTypeEnum').NEGATIVE_KEYWORDS
40+
41+
try:
42+
shared_set_resource_name = shared_set_service.mutate_shared_sets(
43+
customer_id, [shared_set_operation]).results[0].resource_name
44+
except google.ads.google_ads.errors.GoogleAdsException as ex:
45+
print('Request with ID "%s" failed with status "%s" and includes the '
46+
'following errors:' % (ex.request_id, ex.error.code().name))
47+
for error in ex.failure.errors:
48+
print('\tError with message "%s".' % error.message)
49+
if error.location:
50+
for field_path_element in error.location.field_path_elements:
51+
print('\t\tOn field: %s' % field_path_element.field_name)
52+
sys.exit(1)
53+
54+
print('Created shared set "%s".' % shared_set_resource_name)
55+
56+
# Keywords to create a shared set of.
57+
keywords = ['mars cruise', 'mars hotels']
58+
59+
shared_criteria_operations = []
60+
for keyword in keywords:
61+
shared_criterion_operation = client.get_type('SharedCriterionOperation')
62+
shared_criterion = shared_criterion_operation.create
63+
keyword_info = shared_criterion.keyword
64+
keyword_info.text.value = keyword
65+
keyword_info.match_type = client.get_type('KeywordMatchTypeEnum').BROAD
66+
shared_criterion.shared_set.value = shared_set_resource_name
67+
shared_criteria_operations.append(shared_criterion_operation)
68+
69+
try:
70+
response = shared_criterion_service.mutate_shared_criteria(
71+
customer_id, shared_criteria_operations)
72+
except google.ads.google_ads.errors.GoogleAdsException as ex:
73+
print('Request with ID "%s" failed with status "%s" and includes the '
74+
'following errors:' % (ex.request_id, ex.error.code().name))
75+
for error in ex.failure.errors:
76+
print('\tError with message "%s".' % error.message)
77+
if error.location:
78+
for field_path_element in error.location.field_path_elements:
79+
print('\t\tOn field: %s' % field_path_element.field_name)
80+
sys.exit(1)
81+
82+
for shared_criterion in response.results:
83+
print('Created shared criterion "%s".' % shared_criterion.resource_name)
84+
85+
campaign_set_operation = client.get_type('CampaignSharedSetOperation')
86+
campaign_set = campaign_set_operation.create
87+
campaign_set.campaign.value = campaign_service.campaign_path(
88+
customer_id, campaign_id)
89+
campaign_set.shared_set.value = shared_set_resource_name
90+
91+
try:
92+
campaign_shared_set_resource_name = (
93+
campaign_shared_set_service.mutate_campaign_shared_sets(
94+
customer_id, [campaign_set_operation]).results[0].resource_name)
95+
except google.ads.google_ads.errors.GoogleAdsException as ex:
96+
print('Request with ID "%s" failed with status "%s" and includes the '
97+
'following errors:' % (ex.request_id, ex.error.code().name))
98+
for error in ex.failure.errors:
99+
print('\tError with message "%s".' % error.message)
100+
if error.location:
101+
for field_path_element in error.location.field_path_elements:
102+
print('\t\tOn field: %s' % field_path_element.field_name)
103+
sys.exit(1)
104+
105+
print('Created campaign shared set "%s".'
106+
% campaign_shared_set_resource_name)
107+
108+
109+
if __name__ == '__main__':
110+
# GoogleAdsClient will read a google-ads.yaml configuration file in the
111+
# home directory if none is specified.
112+
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
113+
.load_from_storage())
114+
115+
parser = argparse.ArgumentParser(
116+
description=('Adds a list of negative broad match keywords to the '
117+
'provided campaign, for the specified customer.'))
118+
# The following argument(s) should be provided to run the example.
119+
parser.add_argument('-c', '--customer_id', type=six.text_type,
120+
required=True, help='The AdWords customer ID.')
121+
parser.add_argument('-i', '--campaign_id', type=six.text_type,
122+
required=True, help='The campaign ID.')
123+
args = parser.parse_args()
124+
125+
main(google_ads_client, args.customer_id, args.campaign_id)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Demonstrates how to find and remove shared sets, and shared set criteria."""
15+
16+
from __future__ import absolute_import
17+
18+
import argparse
19+
import six
20+
import sys
21+
22+
import google.ads.google_ads.client
23+
24+
25+
_DEFAULT_PAGE_SIZE = 1000
26+
27+
28+
def main(client, customer_id, page_size, campaign_id):
29+
ga_service = client.get_service('GoogleAdsService')
30+
shared_criterion_service = client.get_service('SharedCriterionService')
31+
32+
# First, retrieve all shared sets associated with the campaign.
33+
shared_sets_query = (
34+
'SELECT shared_set.id, shared_set.name FROM campaign_shared_set '
35+
'WHERE campaign.id = %s' % campaign_id)
36+
37+
try:
38+
shared_set_response = ga_service.search(
39+
customer_id, query=shared_sets_query, page_size=page_size)
40+
except google.ads.google_ads.errors.GoogleAdsException as ex:
41+
print('Request with ID "%s" failed with status "%s" and includes the '
42+
'following errors:' % (ex.request_id, ex.error.code().name))
43+
for error in ex.failure.errors:
44+
print('\tError with message "%s".' % error.message)
45+
if error.location:
46+
for field_path_element in error.location.field_path_elements:
47+
print('\t\tOn field: %s' % field_path_element.field_name)
48+
sys.exit(1)
49+
50+
shared_set_ids = []
51+
for row in shared_set_response:
52+
shared_set = row.shared_set
53+
shared_set_id = str(shared_set.id.value)
54+
shared_set_ids.append(shared_set_id)
55+
print('Campaign shared set ID "%s" and name "%s" was found.'
56+
% (shared_set_id, shared_set.name.value))
57+
58+
# Next, retrieve shared criteria for all found shared sets.
59+
shared_criteria_query = (
60+
'SELECT shared_criterion.type, shared_criterion.keyword.text, '
61+
'shared_criterion.keyword.match_type, shared_set.id '
62+
'FROM shared_criterion WHERE shared_set.id IN (%s)'
63+
% ', '.join(shared_set_ids))
64+
65+
try:
66+
shared_criteria_response = ga_service.search(
67+
customer_id, query=shared_criteria_query, page_size=page_size)
68+
except google.ads.google_ads.errors.GoogleAdsException as ex:
69+
print('Request with ID "%s" failed with status "%s" and includes the '
70+
'following errors:' % (ex.request_id, ex.error.code().name))
71+
for error in ex.failure.errors:
72+
print('\tError with message "%s".' % error.message)
73+
if error.location:
74+
for field_path_element in error.location.field_path_elements:
75+
print('\t\tOn field: %s' % field_path_element.field_name)
76+
sys.exit(1)
77+
78+
# Use the enum type to determine the enum name from the value.
79+
keyword_match_type_enum = (
80+
client.get_type('KeywordMatchTypeEnum').KeywordMatchType)
81+
82+
criterion_ids = []
83+
for row in shared_criteria_response:
84+
shared_criterion = row.shared_criterion
85+
shared_criterion_resource_name = shared_criterion.resource_name
86+
if (shared_criterion.type ==
87+
client.get_type('CriterionTypeEnum').KEYWORD):
88+
keyword = shared_criterion.keyword
89+
print('Shared criterion with resource name "%s" for negative '
90+
'keyword with text "%s" and match type "%s" was found.'
91+
% (shared_criterion_resource_name, keyword.text.value,
92+
keyword_match_type_enum.Name(keyword.match_type)))
93+
criterion_ids.append(shared_criterion_resource_name)
94+
95+
operations = []
96+
97+
# Finally, remove the criteria.
98+
for criteria_id in criterion_ids:
99+
shared_criterion_operation = client.get_type('SharedCriterionOperation')
100+
shared_criterion_operation.remove = criteria_id
101+
operations.append(shared_criterion_operation)
102+
103+
try:
104+
response = shared_criterion_service.mutate_shared_criteria(
105+
customer_id, operations)
106+
except google.ads.google_ads.errors.GoogleAdsException as ex:
107+
print('Request with ID "%s" failed with status "%s" and includes the '
108+
'following errors:' % (ex.request_id, ex.error.code().name))
109+
for error in ex.failure.errors:
110+
print('\tError with message "%s".' % error.message)
111+
if error.location:
112+
for field_path_element in error.location.field_path_elements:
113+
print('\t\tOn field: %s' % field_path_element.field_name)
114+
sys.exit(1)
115+
116+
for result in response.results:
117+
print('Removed shared criterion "%s".' % result.resource_name)
118+
119+
120+
if __name__ == '__main__':
121+
# GoogleAdsClient will read a google-ads.yaml configuration file in the
122+
# home directory if none is specified.
123+
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
124+
.load_from_storage())
125+
126+
parser = argparse.ArgumentParser(
127+
description=('Finds shared sets, then finds and removes shared set '
128+
'criteria under them.'))
129+
# The following argument(s) should be provided to run the example.
130+
parser.add_argument('-c', '--customer_id', type=six.text_type,
131+
required=True, help='The AdWords customer ID.')
132+
parser.add_argument('-i', '--campaign_id', type=six.text_type,
133+
required=True, help='The campaign ID.')
134+
args = parser.parse_args()
135+
136+
main(google_ads_client, args.customer_id, _DEFAULT_PAGE_SIZE,
137+
args.campaign_id)

0 commit comments

Comments
 (0)