/
add_bidding_data_exclusion.pl
146 lines (120 loc) · 5.18 KB
/
add_bidding_data_exclusion.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl -w
#
# Copyright 2021, Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Adds a customer-level data exclusion that excludes conversions from being used
# by Smart Bidding for the time interval specified.
#
# For more information on using data exclusions, see:
# https://developers.google.com/google-ads/api/docs/campaigns/bidding/data-exclusions.
use strict;
use warnings;
use utf8;
use FindBin qw($Bin);
use lib "$Bin/../../lib";
use Google::Ads::GoogleAds::Client;
use Google::Ads::GoogleAds::Utils::GoogleAdsHelper;
use Google::Ads::GoogleAds::V16::Resources::BiddingDataExclusion;
use Google::Ads::GoogleAds::V16::Enums::SeasonalityEventScopeEnum qw(CHANNEL);
use Google::Ads::GoogleAds::V16::Enums::AdvertisingChannelTypeEnum qw(SEARCH);
use
Google::Ads::GoogleAds::V16::Services::BiddingDataExclusionService::BiddingDataExclusionOperation;
use Getopt::Long qw(:config auto_help);
use Pod::Usage;
use Cwd qw(abs_path);
use Data::Uniqid qw(uniqid);
# The following parameter(s) should be provided to run the example. You can
# either specify these by changing the INSERT_XXX_ID_HERE values below, or on
# the command line.
#
# Parameters passed on the command line will override any parameters set in
# code.
#
# Running the example with -h will print the command line usage.
my $customer_id = "INSERT_CUSTOMER_ID_HERE";
my $start_date_time = "INSERT_START_DATE_TIME_HERE";
my $end_date_time = "INSERT_END_DATE_TIME_HERE";
# Adds a "CUSTOMER" scoped data exclusion for the client customer ID and dates specified.
sub add_bidding_data_exclusion {
my ($api_client, $customer_id, $start_date_time, $end_date_time) = @_;
# [START add_bidding_data_exclusion]
my $data_exclusion =
Google::Ads::GoogleAds::V16::Resources::BiddingDataExclusion->new({
# A unique name is required for every data exclusion.
name => "Data exclusion #" . uniqid(),
# The CHANNEL scope applies the data exclusion to all campaigns of specific
# advertising channel types. In this example, the exclusion will only apply
# to Search campaigns. Use the CAMPAIGN scope to instead limit the scope to
# specific campaigns.
scope => CHANNEL,
advertisingChannelTypes => [SEARCH],
# If setting scope CAMPAIGN, add individual campaign resource name(s)
# according to the commented out line below.
# campaigns => ["INSERT_CAMPAIGN_RESOURCE_NAME_HERE"],
startDateTime => $start_date_time,
endDateTime => $end_date_time
});
my $operation =
Google::Ads::GoogleAds::V16::Services::BiddingDataExclusionService::BiddingDataExclusionOperation
->new({
create => $data_exclusion
});
my $response = $api_client->BiddingDataExclusionService()->mutate({
customerId => $customer_id,
operations => [$operation]});
printf "Added data exclusion with resource name: '%s'.\n",
$response->{results}[0]{resourceName};
# [END add_bidding_data_exclusion]
return 1;
}
# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
return 1;
}
# Get Google Ads Client, credentials will be read from ~/googleads.properties.
my $api_client = Google::Ads::GoogleAds::Client->new();
# By default examples are set to die on any server returned fault.
$api_client->set_die_on_faults(1);
# Parameters passed on the command line will override any parameters set in code.
GetOptions(
"customer_id=s" => \$customer_id,
"start_date_time=s" => \$start_date_time,
"end_date_time=s" => \$end_date_time
);
# Print the help message if the parameters are not initialized in the code nor
# in the command line.
pod2usage(2)
if not check_params($customer_id, $start_date_time, $end_date_time);
# Call the example.
add_bidding_data_exclusion($api_client, $customer_id =~ s/-//gr,
$start_date_time, $end_date_time);
=pod
=head1 NAME
add_bidding_data_exclusion
=head1 DESCRIPTION
Adds a customer-level data exclusion that excludes conversions from being used
by Smart Bidding for the time interval specified.
For more information on using data exclusions, see:
https://developers.google.com/google-ads/api/docs/campaigns/bidding/data-exclusions.
=head1 SYNOPSIS
add_bidding_data_exclusion.pl [options]
-help Show the help message.
-customer_id The client customer ID of the Google Ads account
that the data exclusion will be added to.
-start_date_time The start date time in yyyy-MM-dd HH:mm:ss format
of the data exclusion period.
-end_date_time The end date time in yyyy-MM-dd HH:mm:ss format
of the data exclusion period.
=cut