Google-Ads-GoogleAds-Client

 view release on metacpan or  search on metacpan

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

    push @{$smart_campaign_ad->{descriptions}}, $asset
      if defined $asset->{text};
  }
  # If there are fewer descriptions than are required, we manually add
  # additional descriptions to make up for the difference.
  my $num_missing_descriptions =
    REQUIRED_NUM_DESCRIPTIONS - scalar @{$smart_campaign_ad->{descriptions}};
  for (my $i = 0 ; $i < $num_missing_descriptions ; $i++) {
    push @{$smart_campaign_ad->{descriptions}},
      Google::Ads::GoogleAds::V24::Common::AdTextAsset->new({
        text => "placeholder description " . $i
      });
  }

  return $mutate_operation;
}
# [END add_smart_campaign_6]

# Prints the details of a MutateGoogleAdsResponse.
sub _print_response_details {
  my ($response) = @_;

  my $mutate_operation_responses = $response->{mutateOperationResponses};

  foreach my $operation_response (@$mutate_operation_responses) {
    my $resource_name = "<not found>";
    my $entity_name   = "unknown";

    if ($operation_response->{adGroupResult}) {
      $entity_name   = "AdGroup";
      $resource_name = $operation_response->{adGroupResult}{resourceName};
    } elsif ($operation_response->{adGroupAdResult}) {
      $entity_name   = "AdGroupAd";
      $resource_name = $operation_response->{adGroupAdResult}{resourceName};
    } elsif ($operation_response->{campaignResult}) {
      $entity_name   = "Campaign";
      $resource_name = $operation_response->{campaignResult}{resourceName};
    } elsif ($operation_response->{campaignBudgetResult}) {
      $entity_name = "CampaignBudget";
      $resource_name =
        $operation_response->{campaignBudgetResult}{resourceName};
    } elsif ($operation_response->{campaignCriterionResult}) {
      $entity_name = "CampaignCriterion";
      $resource_name =
        $operation_response->{campaignCriterionResult}{resourceName};
    } elsif ($operation_response->{smartCampaignSettingResult}) {
      $entity_name = "SmartCampaignSetting";
      $resource_name =
        $operation_response->{smartCampaignSettingResult}{resourceName};
    }

    printf "Created a(n) $entity_name with resource name '$resource_name'.\n";
  }
}

# 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,
  "keyword_text=s"              => \$keyword_text,
  "free_form_keyword_text=s"    => \$free_form_keyword_text,
  "business_profile_location=i" => \$business_profile_location,
  "business_name=s"             => \$business_name
);

# 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_smart_campaign($api_client, $customer_id =~ s/-//gr,
  $keyword_text, $free_form_keyword_text, $business_profile_location,
  $business_name);

=pod

=head1 NAME

add_smart_campaign

=head1 DESCRIPTION

This example shows how to create a Smart campaign.

More details on Smart campaigns can be found here:
https://support.google.com/google-ads/answer/7652860

=head1 SYNOPSIS

add_smart_campaign.pl [options]

    -help                       Show the help message.
    -customer_id                The Google Ads customer ID.
    -keyword_text               [optional] A keyword text used to retrieve keyword theme constant
                                suggestions from the KeywordThemeConstantService. These keyword
                                theme suggestions are generated using auto-completion data for the
                                given text and may help improve the performance of the Smart campaign.
    -free_form_keyword_text      [optional] A keyword text used to create a free-form keyword theme,
                                which is entirely user-specified and not derived from any suggestion
                                service. Using free-form keyword themes is typically not recommended
                                because they are less effective than suggested keyword themes, however
                                they are useful in situations where a very specific term needs to be targeted.
    -business_profile_location  [optional] The resource name of a Business Profile location.
                                This is required if a business name is not provided.
                                This ID can be retrieved using the Business Profile API, for details see:
                                https://developers.google.com/my-business/reference/businessinformation/rest/v1/accounts.locations
                                or from the Business Profile UI (https://support.google.com/business/answer/10737668).
    -business_name              [optional] The name of a business in Business Profile.
                                This is required if a business profile location is not provided.

=cut



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