Google-Ads-GoogleAds-Client
view release on metacpan or search on metacpan
examples/assets/add_call.pl view on Meta::CPAN
# Set the start hour to 9am.
startHour => 9,
# Set the end hour to 5pm.
endHour => 17,
# Set the start and end minute of zero, for example: 9:00 and 5:00.
startMinute => ZERO,
endMinute => ZERO
})]});
# Set the conversion action ID to the one provided if any.
if (defined $conversion_action_id) {
$call_asset->{callConversionAction} =
Google::Ads::GoogleAds::V24::Utils::ResourceNames::conversion_action(
$customer_id, $conversion_action_id);
$call_asset->{callConversionReportingState} =
USE_RESOURCE_LEVEL_CALL_CONVERSION_ACTION;
}
# Create an asset operation wrapping the call asset in an asset.
my $asset_operation =
Google::Ads::GoogleAds::V24::Services::AssetService::AssetOperation->new({
create => Google::Ads::GoogleAds::V24::Resources::Asset->new({
callAsset => $call_asset
})});
# Issue a mutate request to add the asset and print its information.
my $response = $api_client->AssetService()->mutate({
customerId => $customer_id,
operations => [$asset_operation]});
my $resource_name = $response->{results}[0]{resourceName};
printf "Created a call asset with resource name: '%s'.\n", $resource_name;
return $resource_name;
}
# Links the call asset at the account level to serve in all eligible campaigns.
sub link_asset_to_account {
my ($api_client, $customer_id, $asset_resource_name) = @_;
# Create a customer asset operation wrapping the call asset in a customer asset.
my $customer_asset_operation =
Google::Ads::GoogleAds::V24::Services::CustomerAssetService::CustomerAssetOperation
->new({
create => Google::Ads::GoogleAds::V24::Resources::CustomerAsset->new({
asset => $asset_resource_name,
fieldType => CALL
})});
# Issue a mutate request to add the customer asset and print its information.
my $response = $api_client->CustomerAssetService()->mutate({
customerId => $customer_id,
operations => [$customer_asset_operation]});
printf "Created a customer asset with resource name: '%s'.\n",
$response->{results}[0]{resourceName};
}
# 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,
"phone_country=s" => \$phone_country,
"phone_number=s" => \$phone_number,
"conversion_action_id=i" => \$conversion_action_id
);
# 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, $phone_country, $phone_number);
# Call the example.
add_call($api_client, $customer_id =~ s/-//gr,
$phone_country, $phone_number, $conversion_action_id);
=pod
=head1 NAME
add_call
=head1 DESCRIPTION
This example adds a call asset to a specific account.
=head1 SYNOPSIS
add_call.pl [options]
-help Show the help message.
-customer_id The Google Ads customer ID.
-phone_country [optional] The phone country (2-letter code).
-phone_number The raw phone number, e.g. "(800) 555-0100".
-conversion_action_id [optional] The conversion action ID to attribute conversions to.
=cut
( run in 1.444 second using v1.01-cache-2.11-cpan-f56aa216473 )