Skip to content

Commit 5079490

Browse files
authored
Release version 14.0.1 (#508)
1 parent 868bf36 commit 5079490

31 files changed

+360
-75
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* 14.0.1
2+
- Pin protobuf to < 3.18.0
3+
- Add examples add_bidding_data_exclusion, add_bidding_seasonality_adjustment
4+
- Style updates for examples that use search_stream
5+
- Fix hardcoded URLs for media in various examples
6+
17
* 14.0.0
28
- New required configuration value to specify protobuf message types, see:
39
https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages

examples/account_management/get_pending_invitations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def main(client, customer_id):
4444
FROM customer_user_access_invitation
4545
WHERE customer_user_access_invitation.invitation_status = PENDING"""
4646

47-
response = googleads_service.search_stream(
47+
stream = googleads_service.search_stream(
4848
customer_id=customer_id, query=query
4949
)
50-
for batch in response:
50+
for batch in stream:
5151
for row in batch.results:
5252
invite = row.customer_user_access_invitation
5353
print(
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env python
2+
# Copyright 2021 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
"""Adds a channel-level data exclusion for Smart Bidding.
16+
17+
The exclusion specifically excludes conversions from being used by Smart Bidding
18+
for the time interval specified.
19+
20+
For more information on using data exclusions, see:
21+
https://developers.google.com/google-ads/api/docs/campaigns/bidding/data-exclusions
22+
"""
23+
24+
25+
import argparse
26+
import sys
27+
from uuid import uuid4
28+
29+
from google.ads.googleads.client import GoogleAdsClient
30+
from google.ads.googleads.errors import GoogleAdsException
31+
32+
33+
def main(client, customer_id, start_date_time, end_date_time):
34+
"""The main method that creates all necessary entities for the example.
35+
36+
Args:
37+
client: an initialized GoogleAdsClient instance.
38+
customer_id: a client customer ID.
39+
start_date_time: a str of the start date for the exclusion period.
40+
end_date_time: a str of the end date for the exclusion period.
41+
"""
42+
# [START add_bidding_data_exclusion]
43+
bidding_data_exclusion_service = client.get_service(
44+
"BiddingDataExclusionService"
45+
)
46+
operation = client.get_type("BiddingDataExclusionOperation")
47+
bidding_data_exclusion = operation.create
48+
# A unique name is required for every data exclusion
49+
bidding_data_exclusion.name = f"Data exclusion #{uuid4()}"
50+
# The CHANNEL scope applies the data exclusion to all campaigns of specific
51+
# advertising channel types. In this example, the exclusion will only
52+
# apply to Search campaigns. Use the CAMPAIGN scope to instead limit the
53+
# scope to specific campaigns.
54+
bidding_data_exclusion.scope = (
55+
client.enums.SeasonalityEventScopeEnum.CHANNEL
56+
)
57+
bidding_data_exclusion.advertising_channel_types.append(
58+
client.enums.AdvertisingChannelTypeEnum.SEARCH
59+
)
60+
# If setting scope CAMPAIGN, add individual campaign resource name(s)
61+
# according to the commented out line below.
62+
#
63+
# bidding_data_exclusion.campaigns.append(
64+
# "INSERT_CAMPAIGN_RESOURCE_NAME_HERE"
65+
# )
66+
67+
bidding_data_exclusion.start_date_time = start_date_time
68+
bidding_data_exclusion.end_date_time = end_date_time
69+
70+
response = bidding_data_exclusion_service.mutate_bidding_data_exclusions(
71+
customer_id=customer_id, operations=[operation]
72+
)
73+
74+
resource_name = response.results[0].resource_name
75+
76+
print(f"Added data exclusion with resource name: '{resource_name}'")
77+
# [END add_bidding_data_exclusion]
78+
79+
80+
if __name__ == "__main__":
81+
# GoogleAdsClient will read the google-ads.yaml configuration file in the
82+
# home directory if none is specified.
83+
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
84+
85+
parser = argparse.ArgumentParser(
86+
description="Adds a data exclusion for conversions in Smart Bidding "
87+
"for the given time interval."
88+
)
89+
# The following argument(s) should be provided to run the example.
90+
parser.add_argument(
91+
"-c",
92+
"--customer_id",
93+
type=str,
94+
required=True,
95+
help="The Google Ads customer ID.",
96+
)
97+
parser.add_argument(
98+
"-s",
99+
"--start_date_time",
100+
type=str,
101+
required=True,
102+
help="The start date for the exclusion period, must be in the format: "
103+
"'yyyy-MM-dd HH:mm:ss'.",
104+
)
105+
parser.add_argument(
106+
"-e",
107+
"--end_date_time",
108+
type=str,
109+
required=True,
110+
help="The end date for the exclusion period, must be in the format: "
111+
"'yyyy-MM-dd HH:mm:ss'.",
112+
)
113+
114+
args = parser.parse_args()
115+
116+
try:
117+
main(
118+
googleads_client,
119+
args.customer_id,
120+
args.start_date_time,
121+
args.end_date_time,
122+
)
123+
except GoogleAdsException as ex:
124+
print(
125+
f'Request with ID "{ex.request_id}" failed with status '
126+
f'"{ex.error.code().name}" and includes the following errors:'
127+
)
128+
for error in ex.failure.errors:
129+
print(f'Error with message "{error.message}".')
130+
if error.location:
131+
for field_path_element in error.location.field_path_elements:
132+
print(f"\t\tOn field: {field_path_element.field_name}")
133+
sys.exit(1)
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env python
2+
# Copyright 2021 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
"""Adds a channel-level seasonality adjustment for Smart Bidding.
16+
17+
The adjustment changes Smart Bidding behavior by the expected change in
18+
conversion rate for the given future time interval.
19+
20+
For more information on using seasonality adjustments, see:
21+
https://developers.google.com/google-ads/api/docs/campaigns/bidding/seasonality-adjustments
22+
"""
23+
24+
25+
import argparse
26+
import sys
27+
from uuid import uuid4
28+
29+
from google.ads.googleads.client import GoogleAdsClient
30+
from google.ads.googleads.errors import GoogleAdsException
31+
32+
33+
def main(
34+
client,
35+
customer_id,
36+
start_date_time,
37+
end_date_time,
38+
conversion_rate_modifier,
39+
):
40+
"""The main method that creates all necessary entities for the example.
41+
42+
Args:
43+
client: an initialized GoogleAdsClient instance.
44+
customer_id: a client customer ID.
45+
start_date_time: a str of the start date for the exclusion period.
46+
end_date_time: a str of the end date for the exclusion period.
47+
conversion_rate_modifier: the modifier to apply to conversions during
48+
the given time period.
49+
"""
50+
# [START add_bidding_seasonality_adjustment]
51+
bidding_seasonality_adjustment_service = client.get_service(
52+
"BiddingSeasonalityAdjustmentService"
53+
)
54+
operation = client.get_type("BiddingSeasonalityAdjustmentOperation")
55+
bidding_seasonality_adjustment = operation.create
56+
# A unique name is required for every seasonality adjustment.
57+
bidding_seasonality_adjustment.name = f"Seasonality adjustment #{uuid4()}"
58+
# The CHANNEL scope applies the conversion_rate_modifier to all campaigns of
59+
# specific advertising channel types. In this example, the
60+
# conversion_rate_modifier will only apply to Search campaigns. Use the
61+
# CAMPAIGN scope to instead limit the scope to specific campaigns.
62+
bidding_seasonality_adjustment.scope = (
63+
client.enums.SeasonalityEventScopeEnum.CHANNEL
64+
)
65+
bidding_seasonality_adjustment.advertising_channel_types.append(
66+
client.enums.AdvertisingChannelTypeEnum.SEARCH
67+
)
68+
# If setting scope CAMPAIGN, add individual campaign resource name(s)
69+
# according to the commented out line below.
70+
#
71+
# bidding_seasonality_adjustment.campaigns.append(
72+
# "INSERT_CAMPAIGN_RESOURCE_NAME_HERE"
73+
# )
74+
75+
bidding_seasonality_adjustment.start_date_time = start_date_time
76+
bidding_seasonality_adjustment.end_date_time = end_date_time
77+
# The conversion_rate_modifier is the expected future conversion rate
78+
# change. When this field is unset or set to 1.0, no adjustment will be
79+
# applied to traffic. The allowed range is 0.1 to 10.0.
80+
bidding_seasonality_adjustment.conversion_rate_modifier = (
81+
conversion_rate_modifier
82+
)
83+
84+
response = bidding_seasonality_adjustment_service.mutate_bidding_seasonality_adjustments(
85+
customer_id=customer_id, operations=[operation]
86+
)
87+
88+
resource_name = response.results[0].resource_name
89+
90+
print(f"Added seasonality adjustment with resource name: '{resource_name}'")
91+
# [END add_bidding_seasonality_adjustment]
92+
93+
94+
if __name__ == "__main__":
95+
# GoogleAdsClient will read the google-ads.yaml configuration file in the
96+
# home directory if none is specified.
97+
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
98+
99+
parser = argparse.ArgumentParser(
100+
description="Adds a seasonality adjustment for conversions in Smart "
101+
"Bidding for the given time interval."
102+
)
103+
# The following argument(s) should be provided to run the example.
104+
parser.add_argument(
105+
"-c",
106+
"--customer_id",
107+
type=str,
108+
required=True,
109+
help="The Google Ads customer ID.",
110+
)
111+
parser.add_argument(
112+
"-s",
113+
"--start_date_time",
114+
type=str,
115+
required=True,
116+
help="The start date for the adjustment period, must be in the format: "
117+
"'yyyy-MM-dd HH:mm:ss'.",
118+
)
119+
parser.add_argument(
120+
"-e",
121+
"--end_date_time",
122+
type=str,
123+
required=True,
124+
help="The end date for the adjustment period, must be in the format: "
125+
"'yyyy-MM-dd HH:mm:ss'.",
126+
)
127+
parser.add_argument(
128+
"-m",
129+
"--conversion_rate_modifier",
130+
type=float,
131+
required=True,
132+
help="The conversion rate modifier that will be applied during the "
133+
"adjustment period. This value must be in the range 0.1 to 10.0.",
134+
)
135+
136+
args = parser.parse_args()
137+
138+
try:
139+
main(
140+
googleads_client,
141+
args.customer_id,
142+
args.start_date_time,
143+
args.end_date_time,
144+
args.conversion_rate_modifier,
145+
)
146+
except GoogleAdsException as ex:
147+
print(
148+
f'Request with ID "{ex.request_id}" failed with status '
149+
f'"{ex.error.code().name}" and includes the following errors:'
150+
)
151+
for error in ex.failure.errors:
152+
print(f'Error with message "{error.message}".')
153+
if error.location:
154+
for field_path_element in error.location.field_path_elements:
155+
print(f"\t\tOn field: {field_path_element.field_name}")
156+
sys.exit(1)

examples/advanced_operations/add_display_upload_ad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from google.ads.googleads.errors import GoogleAdsException
2828

2929

30-
BUNDLE_URL = "https://goo.gl/9Y7qI2"
30+
BUNDLE_URL = "https://gaagl.page.link/ib87"
3131

3232

3333
def main(client, customer_id, ad_group_id):

examples/advanced_operations/add_local_campaign.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
from google.ads.googleads.errors import GoogleAdsException
3232

3333

34-
_MARKETING_IMAGE_URL = "https://goo.gl/3b9Wfh"
35-
_LOGO_IMAGE_URL = "https://goo.gl/mtt54n"
34+
_MARKETING_IMAGE_URL = "https://gaagl.page.link/Eit5"
35+
_LOGO_IMAGE_URL = "https://gaagl.page.link/bjYi"
3636
_YOUTUBE_VIDEO_ID = "ECpDzH9gXh8"
3737

3838

examples/advanced_operations/add_smart_display_ad.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040

4141

4242
_DATE_FORMAT = "%Y%m%d"
43-
_MARKETING_IMAGE_URL = "https://goo.gl/3b9Wfh"
43+
_MARKETING_IMAGE_URL = "https://gaagl.page.link/Eit5"
4444
_MARKETING_IMAGE_WIDTH = 600
4545
_MARKETING_IMAGE_HEIGHT = 315
46-
_SQUARE_MARKETING_IMAGE_URL = "https://goo.gl/mtt54n"
46+
_SQUARE_MARKETING_IMAGE_URL = "https://gaagl.page.link/bjYi"
4747
_SQUARE_MARKETING_IMAGE_SIZE = 512
4848

4949

examples/basic_operations/get_campaigns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def main(client, customer_id):
3636
ORDER BY campaign.id"""
3737

3838
# Issues a search request using streaming.
39-
response = ga_service.search_stream(customer_id=customer_id, query=query)
39+
stream = ga_service.search_stream(customer_id=customer_id, query=query)
4040

41-
for batch in response:
41+
for batch in stream:
4242
for row in batch.results:
4343
print(
4444
f"Campaign with ID {row.campaign.id} and name "

examples/basic_operations/get_expanded_text_ads.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def main(client, customer_id, ad_group_id=None):
3838
if ad_group_id:
3939
query += f" AND ad_group.id = {ad_group_id}"
4040

41-
response = ga_service.search_stream(customer_id=customer_id, query=query)
41+
stream = ga_service.search_stream(customer_id=customer_id, query=query)
4242

43-
for batch in response:
43+
for batch in stream:
4444
for row in batch.results:
4545
ad = row.ad_group_ad.ad
4646

examples/billing/add_billing_setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ def _set_billing_setup_date_times(client, customer_id, billing_setup):
135135
LIMIT 1"""
136136

137137
ga_service = client.get_service("GoogleAdsService")
138-
response = ga_service.search_stream(customer_id=customer_id, query=query)
138+
stream = ga_service.search_stream(customer_id=customer_id, query=query)
139139
# Coercing the response iterator to a list causes the stream to be fully
140140
# consumed so that we can easily access the last row in the request.
141-
batches = list(response)
141+
batches = list(stream)
142142
# Checks if any results were included in the response.
143143
if batches:
144144
# Retrieves the ending_date_time of the last BillingSetup.

0 commit comments

Comments
 (0)