Google-Ads-GoogleAds-Client

 view release on metacpan or  search on metacpan

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

  my $responsive_search_ad_info =
    Google::Ads::GoogleAds::V24::Common::ResponsiveSearchAdInfo->new({
      headlines => [
        Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
            text =>
              "Luxury cruise to {CUSTOMIZER.$string_customizer_name:Venus}",
            pinnedField => HEADLINE_1
          }
        ),
        Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
            text => "Only {CUSTOMIZER.$price_customizer_name:10.0€}",
          }
        ),
        Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
            text =>
"Cruise to {CUSTOMIZER.$string_customizer_name:Venus} for {CUSTOMIZER.$price_customizer_name:10.0€}",
          })
      ],
      descriptions => [
        Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
            text =>
              "Tickets are only {CUSTOMIZER.$price_customizer_name:10.0€}!",
          }
        ),
        Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
            text =>
"Buy your tickets to {CUSTOMIZER.$string_customizer_name:Venus} now!"
          })]});

  my $ad = Google::Ads::GoogleAds::V24::Resources::Ad->new({
      responsiveSearchAd => $responsive_search_ad_info,
      finalUrls          => ["https://www.example.com"]});

  my $ad_group_ad = Google::Ads::GoogleAds::V24::Resources::AdGroupAd->new({
      ad      => $ad,
      adGroup => Google::Ads::GoogleAds::V24::Utils::ResourceNames::ad_group(
        $customer_id, $ad_group_id
      )});

  my $ad_group_ad_operation =
    Google::Ads::GoogleAds::V24::Services::AdGroupAdService::AdGroupAdOperation
    ->new({
      create => $ad_group_ad
    });

  # Issue a mutate request to add the ads.
  my $response = $api_client->AdGroupAdService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_ad_operation]});

  my $ad_group_ad_resource_name = $response->{results}[0]{resourceName};
  printf "Added an ad with resource name '%s'.\n", $ad_group_ad_resource_name;
}
# [END add_ad_customizer_3]

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

my $customer_id = undef;
my $ad_group_id = undef;

# Parameters passed on the command line will override any parameters set in code.
GetOptions(
  "customer_id=s" => \$customer_id,
  "ad_group_id=i" => \$ad_group_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, $ad_group_id);

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

=pod

=head1 NAME

add_ad_customizer

=head1 DESCRIPTION

This code example adds two ad customizer attributes and associates them with the ad group.
Then it adds an ad that uses the ad customizer attributes to populate dynamic data.

=head1 SYNOPSIS

add_ad_customizer.pl [options]

    -help                       Show the help message.
    -customer_id                The Google Ads customer ID.
    -ad_group_id                The ad group ID to add the ad customizers to.

=cut



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