Google-Ads-GoogleAds-Client

 view release on metacpan or  search on metacpan

examples/advanced_operations/add_dynamic_search_ads.pl  view on Meta::CPAN

      customerId => $customer_id,
      operations => [$ad_group_ad_operation]});

  my $ad_group_ad_resource_name =
    $ad_group_ads_response->{results}[0]{resourceName};

  printf "Created ad group ad '%s'.\n", $ad_group_ad_resource_name;

  return $ad_group_ad_resource_name;
}
# [END add_dynamic_search_ads_2]

# Creates a webpage targeting criterion for the DSA.
sub add_web_page_criterion {
  my ($api_client, $customer_id, $ad_group_resource_name) = @_;

  # Create an ad group criterion.
  my $ad_group_criterion =
    Google::Ads::GoogleAds::V24::Resources::AdGroupCriterion->new({
      adGroup => $ad_group_resource_name,
      status  =>
        Google::Ads::GoogleAds::V24::Enums::AdGroupCriterionStatusEnum::PAUSED,
      cpcBidMicros => 10000000,
      webpage      => Google::Ads::GoogleAds::V24::Common::WebpageInfo->new({
          criterionName => "Special Offers",
          conditions    => [
            Google::Ads::GoogleAds::V24::Common::WebpageConditionInfo->new({
                operand  => URL,
                argument => "/specialoffers"

              }
            ),
            Google::Ads::GoogleAds::V24::Common::WebpageConditionInfo->new({
                operand  => PAGE_TITLE,
                argument => "Special Offers"
              })]})});

  # Create an ad group criterion operation.
  my $ad_group_criterion_operation =
    Google::Ads::GoogleAds::V24::Services::AdGroupCriterionService::AdGroupCriterionOperation
    ->new({create => $ad_group_criterion});

  # Add the ad group criterion.
  my $ad_group_criteria_response =
    $api_client->AdGroupCriterionService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_criterion_operation]});

  my $ad_group_criterion_resource_name =
    $ad_group_criteria_response->{results}[0]{resourceName};

  printf "Created ad group criterion '%s'.\n",
    $ad_group_criterion_resource_name;
}

# 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);

# 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);

# Call the example.
add_dynamic_search_ads($api_client, $customer_id =~ s/-//gr);

=pod

=head1 NAME

add_dynamic_search_ads

=head1 DESCRIPTION

This example adds a new dynamic search ad (DSA) and a webpage targeting criterion
for the DSA.

=head1 SYNOPSIS

add_dynamic_search_ads.pl [options]

    -help                       Show the help message.
    -customer_id                The Google Ads customer ID.

=cut



( run in 0.678 second using v1.01-cache-2.11-cpan-f56aa216473 )