Campaign budget
A Local campaign cannot use a shared campaign budget. Make sure the campaign
budget you specify has
explicitly_shared
set to false
.
Java
private String createCampaignBudget(GoogleAdsClient googleAdsClient, long customerId) { // Creates a CampaignBudget object. CampaignBudget budget = CampaignBudget.newBuilder() .setAmountMicros(50000000) .setName("Interplanetary Cruise Budget #" + getPrintableDateTime()) .setDeliveryMethod(BudgetDeliveryMethod.STANDARD) // A Local campaign cannot use a shared campaign budget. .setExplicitlyShared(false) .build(); // Creates an operation to add the campaign. CampaignBudgetOperation operation = CampaignBudgetOperation.newBuilder().setCreate(budget).build(); // Connects to the API. try (CampaignBudgetServiceClient campaignBudgetServiceClient = googleAdsClient.getLatestVersion().createCampaignBudgetServiceClient()) { // Issues the mutate request. MutateCampaignBudgetsResponse response = campaignBudgetServiceClient.mutateCampaignBudgets( String.valueOf(customerId), ImmutableList.of(operation)); // Prints some debugging information. String resourceName = response.getResults(0).getResourceName(); System.out.printf("Created campaign budget with resource name: '%s'.%n", resourceName); return resourceName; } }
C#
private string CreateCampaignBudget(GoogleAdsClient client, in long customerId) { // Get the CampaignBudgetService client. CampaignBudgetServiceClient campaignBudgetServiceClient = client.GetService(Services.V11.CampaignBudgetService); // Create a campaign budget object. CampaignBudget campaignBudget = new CampaignBudget { Name = $"Interplanetary Cruise Budget #{ExampleUtilities.GetRandomString()}", AmountMicros = 50000000, DeliveryMethod = BudgetDeliveryMethod.Standard, // A Local campaign cannot use a shared campaign budget. ExplicitlyShared = false }; // Create a campaign budget operation. CampaignBudgetOperation campaignBudgetOperation = new CampaignBudgetOperation { Create = campaignBudget }; // Issue a mutate request to add the campaign budget, then print and return the // resulting budget's resource name. MutateCampaignBudgetsResponse campaignBudgetsResponse = campaignBudgetServiceClient.MutateCampaignBudgets(customerId.ToString(), new[] { campaignBudgetOperation }); string campaignBudgetResourceName = campaignBudgetsResponse.Results.First().ResourceName; Console.WriteLine( $"Created campaign budget with resource name '{campaignBudgetResourceName}'."); return campaignBudgetResourceName; }
PHP
private static function createCampaignBudget( GoogleAdsClient $googleAdsClient, int $customerId ) { $campaignBudget = new CampaignBudget([ 'name' => 'Interplanetary Cruise Budget #' . Helper::getPrintableDatetime(), 'delivery_method' => BudgetDeliveryMethod::STANDARD, 'amount_micros' => 50000000, // A Local campaign cannot use a shared campaign budget. 'explicitly_shared' => false ]); // Creates a campaign budget operation. $campaignBudgetOperation = new CampaignBudgetOperation(); $campaignBudgetOperation->setCreate($campaignBudget); // Issues a mutate request to add campaign budget. $campaignBudgetServiceClient = $googleAdsClient->getCampaignBudgetServiceClient(); /** @var MutateCampaignBudgetsResponse $campaignBudgetResponse */ $campaignBudgetResponse = $campaignBudgetServiceClient->mutateCampaignBudgets( $customerId, [$campaignBudgetOperation] ); $campaignBudgetResourceName = $campaignBudgetResponse->getResults()[0]->getResourceName(); printf( "Created campaign budget with resource name: '%s'.%s", $campaignBudgetResourceName, PHP_EOL ); return $campaignBudgetResourceName; }
Python
def create_campaign_budget(client, customer_id): """Adds a campaign budget to the given client account. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID str. Returns: A str of the resource name for the newly created campaign budget. """ # Create a CampaignBudgetOperation. campaign_budget_operation = client.get_type("CampaignBudgetOperation") campaign_budget = campaign_budget_operation.create campaign_budget.name = f"Interplanetary Cruise Budget #{uuid4()}" campaign_budget.amount_micros = 50000000 campaign_budget.delivery_method = ( client.enums.BudgetDeliveryMethodEnum.STANDARD ) # A Local campaign cannot use a shared campaign budget. campaign_budget.explicitly_shared = False # Issue a mutate request to add the campaign budget. campaign_budget_service = client.get_service("CampaignBudgetService") response = campaign_budget_service.mutate_campaign_budgets( customer_id=customer_id, operations=[campaign_budget_operation] ) resource_name = response.results[0].resource_name print(f"Created campaign budget with resource name: '{resource_name}'") return resource_name
Ruby
def create_campaign_budget(client, customer_id) # Creates a campaign budget operation. operation = client.operation.create_resource.campaign_budget do |cb| cb.name = "Interplanetary Cruise Budget ##{(Time.new.to_f * 1000).to_i}" cb.delivery_method = :STANDARD cb.amount_micros = 50_000_000 # A Local campaign cannot use a shared campaign budget. cb.explicitly_shared = false end # Issues a mutate request to add campaign budget. response = client.service.campaign_budget.mutate_campaign_budgets( customer_id: customer_id, operations: [operation], ) budget_resource_name = response.results.first.resource_name puts "Created campaign budget with resource name: '#{budget_resource_name}'." budget_resource_name end
Perl
sub create_campaign_budget { my ($api_client, $customer_id) = @_; # Create a campaign budget. my $campaign_budget = Google::Ads::GoogleAds::V11::Resources::CampaignBudget->new({ name => "Interplanetary Cruise Budget #" . uniqid(), amountMicros => 50000000, deliveryMethod => STANDARD, # A Local campaign cannot use a shared campaign budget. explicitlyShared => "false" }); # Create a campaign budget operation. my $campaign_budget_operation = Google::Ads::GoogleAds::V11::Services::CampaignBudgetService::CampaignBudgetOperation ->new({ create => $campaign_budget }); # Issue a mutate request to add the campaign budget. my $campaign_budgets_response = $api_client->CampaignBudgetService()->mutate({ customerId => $customer_id, operations => [$campaign_budget_operation]}); my $campaign_budget_resource_name = $campaign_budgets_response->{results}[0]{resourceName}; printf "Created campaign budget with resource name: '%s'.\n", $campaign_budget_resource_name; return $campaign_budget_resource_name; }
Local campaign
To create a Local campaign, follow the steps in our code example with these specifics:
Set the
advertising_channel_type
toLOCAL
.Set the
advertising_channel_sub_type
toLOCAL_CAMPAIGN
.Set the
campaign_budget
to the resource name of the newly created campaign budget as above.Set the
maximize_conversion_value
to a newly createdMaximizeConversionValue
object. A ROAS target can be optionally set on thetarget_roas
field onMaximizeConversionValue
.Set the
local_campaign_setting
to anLocalCampaignSetting
object with:location_source_type
set to eitherGOOGLE_MY_BUSINESS
to use the locations in your linked Business Profile, orAFFILIATE
to use the affiliate location extensions in your Google Ads account.
optimization_goal_setting
is required for Local campaigns. Select DRIVING_DIRECTIONS and/or CALL_CLICKS to optimize the actions in your campaign.
Java
private String createLocalCampaign( GoogleAdsClient googleAdsClient, long customerId, String budgetResourceName) { // Creates a Campaign object. Campaign campaign = Campaign.newBuilder() .setName("Interplanetary Cruise Budget #" + getPrintableDateTime()) .setCampaignBudget(budgetResourceName) // Recommendation: Set the campaign to PAUSED when creating it to prevent the ads from // immediately serving. Set to ENABLED once you've added targeting and the ads are ready // to serve. .setStatus(CampaignStatus.PAUSED) // Sets the advertisingChannelType to LOCAL and advertisingChannelSubType to // LOCAL_CAMPAIGN. .setAdvertisingChannelType(AdvertisingChannelType.LOCAL) .setAdvertisingChannelSubType(AdvertisingChannelSubType.LOCAL_CAMPAIGN) // Sets the bidding strategy. Note that this must be set directly on the campaign. // - Setting a portfolio bidding strategy by resource name is not supported. // - Maximize conversion value is the only strategy supported for Local // campaigns. // - An optional ROAS (Return on Advertising Spend) can be set for // MaximizeConversionValue. // - Specify the ROAS value must as a ratio. It is calculated by // dividing "total value" by "total spend". For example, to target 350% ROAS, set // targetRoas=3.5. // - For more information on maximize conversion value, see the support article: // http://support.google.com/google-ads/answer/7684216. .setMaximizeConversionValue( MaximizeConversionValue.newBuilder().setTargetRoas(3.5).build()) // Configures the Local campaign setting. .setLocalCampaignSetting( LocalCampaignSetting.newBuilder() // Use the locations associated with the customer's linked Business Profile // account. .setLocationSourceType(LocationSourceType.GOOGLE_MY_BUSINESS)) .setOptimizationGoalSetting( OptimizationGoalSetting.newBuilder() // Optimization goal setting is mandatory for Local campaigns. This example // selects driving directions and call clicks as goals. .addOptimizationGoalTypes(OptimizationGoalType.CALL_CLICKS) .addOptimizationGoalTypes(OptimizationGoalType.DRIVING_DIRECTIONS) .build()) .build(); // Creates a operation to add the campaign. CampaignOperation operation = CampaignOperation.newBuilder().setCreate(campaign).build(); // Connects to the API. try (CampaignServiceClient client = googleAdsClient.getLatestVersion().createCampaignServiceClient()) { // Sends the mutate request. MutateCampaignsResponse response = client.mutateCampaigns(String.valueOf(customerId), ImmutableList.of(operation)); // Prints some debugging information. String resourceName = response.getResults(0).getResourceName(); System.out.printf("Created Local campaign with resource name: '%s'.%n", resourceName); return resourceName; } }
C#
private string CreateCampaign(GoogleAdsClient client, long customerId, string budgetResourceName) { // Get the CampaignService client. CampaignServiceClient campaignServiceClient = client.GetService(Services.V11.CampaignService); // Create a campaign object. Campaign campaign = new Campaign { Name = $"Interplanetary Cruise Local #{ExampleUtilities.GetRandomString()}", CampaignBudget = budgetResourceName, // Recommendation: Set the campaign to PAUSED when creating it to prevent the ads // from immediately serving. Set to ENABLED once you've added targeting and the ads // are ready to serve. Status = CampaignStatus.Paused, // All Local campaigns have an advertisingChannelType of LOCAL and // advertisingChannelSubtype of LOCAL_CAMPAIGN. AdvertisingChannelType = AdvertisingChannelType.Local, AdvertisingChannelSubType = AdvertisingChannelSubType.LocalCampaign, // Bidding strategy must be set directly on the campaign.Setting a portfolio bidding // strategy by resource name is not supported. Maximize conversion value is the only // strategy supported for Local campaigns. An optional ROAS (Return on Advertising // Spend) can be set for MaximizeConversionValue. The ROAS value must be specified // as a ratio in the API. It is calculated by dividing "total value" by // "total spend". For more information on maximize conversion value, see the support // article: http://support.google.com/google-ads/answer/7684216. MaximizeConversionValue = new MaximizeConversionValue { TargetRoas = 3.5 }, // Configure the Local campaign setting. LocalCampaignSetting = new Campaign.Types.LocalCampaignSetting { LocationSourceType = LocationSourceType.GoogleMyBusiness }, // Optimization goal setting is mandatory for Local campaigns. This example selects // driving directions and call clicks as goals. OptimizationGoalSetting = new Campaign.Types.OptimizationGoalSetting { OptimizationGoalTypes = { OptimizationGoalType.CallClicks, OptimizationGoalType.DrivingDirections } } }; // Create a campaign operation. CampaignOperation campaignOperation = new CampaignOperation { Create = campaign }; // Issue a mutate request to add the campaign, then print and return the resulting // campaign's resource name. MutateCampaignsResponse campaignResponse = campaignServiceClient.MutateCampaigns(customerId.ToString(), new[] { campaignOperation }); string campaignResourceName = campaignResponse.Results.First().ResourceName; Console.WriteLine("Created Local campaign with resource name " + $"'{campaignResourceName}'."); return campaignResourceName; }
PHP
private static function createCampaign( GoogleAdsClient $googleAdsClient, int $customerId, string $campaignBudgetResourceName ) { $campaign = new Campaign([ 'name' => 'Interplanetary Cruise Local #' . Helper::getPrintableDatetime(), 'campaign_budget' => $campaignBudgetResourceName, // Recommendation: Set the campaign to PAUSED when creating it to prevent the ads // from immediately serving. Set to ENABLED once you've added targeting and the ads // are ready to serve. 'status' => CampaignStatus::PAUSED, // All Local campaigns have an advertisingChannelType of LOCAL and // advertisingChannelSubType of LOCAL_CAMPAIGN. 'advertising_channel_type' => AdvertisingChannelType::LOCAL, 'advertising_channel_sub_type' => AdvertisingChannelSubType::LOCAL_CAMPAIGN, // Bidding strategy must be set directly on the campaign. // Setting a portfolio bidding strategy by resource name is not supported. // Maximize conversion value is the only strategy supported for Local campaigns. An // optional ROAS (Return on Advertising Spend) can be set for // MaximizeConversionValue. The ROAS value must be specified as a ratio in the API. It // is calculated by dividing "total value" by "total spend". // For more information on maximize conversion value, see the support article: // http://support.google.com/google-ads/answer/7684216. 'maximize_conversion_value' => new MaximizeConversionValue(['target_roas' => 3.5]), // Configures the Local campaign setting. 'local_campaign_setting' => new LocalCampaignSetting([ // Use the locations associated with the customer's linked Business Profile account. 'location_source_type' => LocationSourceType::GOOGLE_MY_BUSINESS ]), // Optimization goal setting is mandatory for Local campaigns. This example selects // driving directions and call clicks as goals. 'optimization_goal_setting' => new OptimizationGoalSetting([ 'optimization_goal_types' => [ OptimizationGoalType::CALL_CLICKS, OptimizationGoalType::DRIVING_DIRECTIONS ] ]) ]); // Creates a campaign operation. $campaignOperation = new CampaignOperation(); $campaignOperation->setCreate($campaign); // Issues a mutate request to add campaign. $campaignServiceClient = $googleAdsClient->getCampaignServiceClient(); /** @var MutateCampaignsResponse $campaignResponse */ $campaignResponse = $campaignServiceClient->mutateCampaigns( $customerId, [$campaignOperation] ); $campaignResourceName = $campaignResponse->getResults()[0]->getResourceName(); printf( "Created Local campaign with resource name: '%s'.%s", $campaignResourceName, PHP_EOL ); return $campaignResourceName; }
Python
def create_campaign(client, customer_id, budget_resource_name): """Adds a Local campaign to the given client account using the given budget. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID str. budget_resource_name: the resource name str for a campaign budget. Returns: A str of the resource name for the newly created campaign. """ # Create a CampaignOperation. campaign_operation = client.get_type("CampaignOperation") # Create a Campaign. campaign = campaign_operation.create campaign.name = f"Interplanetary Cruise Local #{uuid4()}" campaign.campaign_budget = budget_resource_name # Recommendation: Set the campaign to PAUSED when creating it to prevent # the ads from immediately serving. Set to ENABLED once you've added # targeting and the ads are ready to serve. campaign.status = client.enums.CampaignStatusEnum.PAUSED # All Local campaigns have an advertising_channel_type of LOCAL and # advertising_channel_sub_type of LOCAL_CAMPAIGN. campaign.advertising_channel_type = ( client.enums.AdvertisingChannelTypeEnum.LOCAL ) campaign.advertising_channel_sub_type = ( client.enums.AdvertisingChannelSubTypeEnum.LOCAL_CAMPAIGN ) # Bidding strategy must be set directly on the campaign. # Setting a portfolio bidding strategy by resource name is not supported. # Maximize conversion value is the only strategy supported for Local # campaigns. An optional ROAS (Return on Advertising Spend) can be set for # maximize_conversion_value. The ROAS value must be specified as a ratio in # the API. It is calculated by dividing "total value" by "total spend". # For more information on maximize conversion value, see the support # article: http://support.google.com/google-ads/answer/7684216. # A target_roas of 3.5 corresponds to a 350% return on ad spend. campaign.maximize_conversion_value.target_roas = 3.5 # Configure the Local campaign setting. Use the locations associated with # the customer's linked Business Profile account. campaign.local_campaign_setting.location_source_type = ( client.enums.LocationSourceTypeEnum.GOOGLE_MY_BUSINESS ) # Optimization goal setting is mandatory for Local campaigns. This example # selects driving directions and call clicks as goals. optimization_goal_type_enum = client.enums.OptimizationGoalTypeEnum campaign.optimization_goal_setting.optimization_goal_types.extend( [ optimization_goal_type_enum.CALL_CLICKS, optimization_goal_type_enum.DRIVING_DIRECTIONS, ] ) campaign_service = client.get_service("CampaignService") response = campaign_service.mutate_campaigns( customer_id=customer_id, operations=[campaign_operation] ) resource_name = response.results[0].resource_name print(f"Created Local Campaign with resource name: '{resource_name}'") return resource_name
Ruby
def create_campaign(client, customer_id, budget_resource_name) # Creates a campaign operation. operation = client.operation.create_resource.campaign do |c| c.name = "Interplanetary Cruise Local ##{(Time.new.to_f * 1000).to_i}" c.campaign_budget = budget_resource_name # Recommendation: Set the campaign to PAUSED when creating it to prevent # the ads from immediately serving. Set to ENABLED once you've added # targeting and the ads are ready to serve. c.status = :PAUSED # All Local campaigns have an advertisingChannelType of LOCAL and # advertisingChannelSubType of LOCAL_CAMPAIGN. c.advertising_channel_type = :LOCAL c.advertising_channel_sub_type = :LOCAL_CAMPAIGN # Bidding strategy must be set directly on the campaign. # Setting a portfolio bidding strategy by resource name is not supported. # Maximize conversion value is the only strategy supported for Local # campaigns. An optional ROAS (Return on Advertising Spend) can be set for # maximize_conversion_value. The ROAS value must be specified as a ratio in # the API. It is calculated by dividing "total value" by "total spend". # For more information on maximize conversion value, see the support article: # http://support.google.com/google-ads/answer/7684216. c.maximize_conversion_value = client.resource.maximize_conversion_value do |mcv| mcv.target_roas = 3.5 end # Configures the Local campaign setting. c.local_campaign_setting = client.resource.local_campaign_setting do |lcs| # Use the locations associated with the customer's linked # Business Profile account. lcs.location_source_type = :GOOGLE_MY_BUSINESS end # Optimization goal setting is mandatory for Local campaigns. This example # selects driving directions and call clicks as goals. c.optimization_goal_setting = client.resource.optimization_goal_setting do |ogs| ogs.optimization_goal_types += [:CALL_CLICKS, :DRIVING_DIRECTIONS] end end # Issues a mutate request to add campaign. response = client.service.campaign.mutate_campaigns( customer_id: customer_id, operations: [operation], ) campaign_resource_name = response.results.first.resource_name puts "Created Local campaign with resource name: '#{campaign_resource_name}'." campaign_resource_name end
Perl
sub create_campaign { my ($api_client, $customer_id, $budget_resource_name) = @_; # Create a campaign. my $campaign = Google::Ads::GoogleAds::V11::Resources::Campaign->new({ name => "Interplanetary Cruise Local #" . uniqid(), campaignBudget => $budget_resource_name, # Recommendation: Set the campaign to PAUSED when creating it to prevent # the ads from immediately serving. Set to ENABLED once you've added # targeting and the ads are ready to serve. status => PAUSED, # All Local campaigns have an advertisingChannelType of LOCAL and # advertisingChannelSubType of LOCAL_CAMPAIGN. advertisingChannelType => LOCAL, advertisingChannelSubType => LOCAL_CAMPAIGN, # Bidding strategy must be set directly on the campaign. # Setting a portfolio bidding strategy by resource name is not supported. # Maximize conversion value is the only strategy supported for Local # campaigns. An optional ROAS (Return on Advertising Spend) can be set for # MaximizeConversionValue. The ROAS value must be specified as a ratio in the # API. It is calculated by dividing "total value" by "total spend". # For more information on maximize conversion value, see the support article: # http://support.google.com/google-ads/answer/7684216. maximizeConversionValue => Google::Ads::GoogleAds::V11::Common::MaximizeConversionValue->new( {targetRoas => 3.5} ), # Configure the Local campaign setting. localCampaignSetting => Google::Ads::GoogleAds::V11::Resources::LocalCampaignSetting->new({ # Use the locations associated with the customer's linked Business Profile # account. locationSourceType => GOOGLE_MY_BUSINESS } ), # Optimization goal setting is mandatory for Local campaigns. This example # selects driving directions and call clicks as goals. optimizationGoalSetting => Google::Ads::GoogleAds::V11::Resources::OptimizationGoalSetting->new({ optimizationGoalTypes => [CALL_CLICKS, DRIVING_DIRECTIONS]})}); # Create a campaign operation. my $campaign_operation = Google::Ads::GoogleAds::V11::Services::CampaignService::CampaignOperation-> new({ create => $campaign }); # Issue a mutate request to add the campaign. my $campaigns_response = $api_client->CampaignService()->mutate({ customerId => $customer_id, operations => [$campaign_operation]}); my $campaign_resource_name = $campaigns_response->{results}[0]{resourceName}; printf "Created Local campaign with resource name: '%s'.\n", $campaign_resource_name; return $campaign_resource_name; }