Google-Ads-AdWords-Client
view release on metacpan or search on metacpan
examples/v201809/advanced_operations/use_portfolio_bidding_strategy.pl view on Meta::CPAN
my $bidding_strategy_id = shift;
my $budget_id = shift;
my @operations = ();
# Create campaign.
my $campaign = Google::Ads::AdWords::v201809::Campaign->new({
name => 'Interplanetary Cruise #' . uniqid(),
budget =>
Google::Ads::AdWords::v201809::Budget->new({budgetId => $budget_id}),
# Set bidding strategy (required).
biddingStrategyConfiguration =>
Google::Ads::AdWords::v201809::BiddingStrategyConfiguration->new(
{biddingStrategyId => $bidding_strategy_id}
),
# Set advertising channel type (required).
advertisingChannelType => 'SEARCH',
# Network targeting (recommended).
networkSetting => Google::Ads::AdWords::v201809::NetworkSetting->new({
targetGoogleSearch => 1,
targetSearchNetwork => 1,
targetContentNetwork => 1
}),
# Recommendation: Set the campaign to PAUSED when creating it to stop
# the ads from immediately serving. Set to ENABLED once you've added
# targeting and the ads are ready to serve.
status => "PAUSED"
});
# Create operation.
my $operation = Google::Ads::AdWords::v201809::CampaignOperation->new({
operator => 'ADD',
operand => $campaign
});
push @operations, $operation;
my $result = $client->CampaignService()->mutate({operations => \@operations});
if ($result->get_value()) {
my $new_campaign = $result->get_value()->[0];
printf "Campaign with name \"%s\", ID %d and bidding strategy ID %d was " .
"created.\n", $new_campaign->get_name(), $new_campaign->get_id(),
$new_campaign->get_biddingStrategyConfiguration()
->get_biddingStrategyId();
return $new_campaign;
} else {
print "No campaigns were added.\n";
return 0;
}
}
# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
return 1;
}
# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging();
# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});
# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);
# Call the example
use_portfolio_bidding_strategy($client, $budget_id);
( run in 0.599 second using v1.01-cache-2.11-cpan-99c4e6809bf )