defcreate_smart_campaign_operation(client:GoogleAdsClient,customer_id:str)-> MutateOperation:"""Creates a MutateOperation that creates a new Smart campaign. A temporary ID will be assigned to this campaign so that it can be referenced by other objects being created in the same Mutate request. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. Returns: a MutateOperation that creates a campaign. """mutate_operation:MutateOperation=client.get_type("MutateOperation")campaign_operation:CampaignOperation=mutate_operation.campaign_operationcampaign:Campaign=campaign_operation.createcampaign.name=f"Smart campaign #{uuid4()}"# Set the campaign status as PAUSED. The campaign is the only entity in# the mutate request that should have its' status set.campaign.status=client.enums.CampaignStatusEnum.PAUSED# Campaign.AdvertisingChannelType is required to be SMART.campaign.advertising_channel_type=(client.enums.AdvertisingChannelTypeEnum.SMART)# Campaign.AdvertisingChannelSubType is required to be SMART_CAMPAIGN.campaign.advertising_channel_sub_type=(client.enums.AdvertisingChannelSubTypeEnum.SMART_CAMPAIGN)# Assign the resource name with a temporary ID.campaign.resource_name=client.get_service("CampaignService").campaign_path(customer_id,_SMART_CAMPAIGN_TEMPORARY_ID)# Set the budget using the given budget resource name.campaign.campaign_budget=client.get_service("CampaignBudgetService").campaign_budget_path(customer_id,_BUDGET_TEMPORARY_ID)# Declare whether or not this campaign serves political ads targeting the# EU. Valid values are:# CONTAINS_EU_POLITICAL_ADVERTISING# DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISINGcampaign.contains_eu_political_advertising=(client.enums.EuPoliticalAdvertisingStatusEnum.DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING)returnmutate_operation
# Creates a mutate_operation that creates a new Smart campaign.# A temporary ID will be assigned to this campaign so that it can# be referenced by other objects being created in the same mutate request.defcreate_smart_campaign_operation(client,customer_id)mutate_operation=client.operation.mutatedo|m|m.campaign_operation=client.operation.create_resource.campaigndo|c|c.name="Smart campaign ##{(Time.new.to_f*1000).to_i}"# Sets the campaign status as PAUSED. The campaign is the only entity in# the mutate request that should have its' status set.c.status=:PAUSED# campaign.advertising_channel_type is required to be SMART.c.advertising_channel_type=:SMART# campaign.advertising_channel_sub_type is required to be SMART_CAMPAIGN.c.advertising_channel_sub_type=:SMART_CAMPAIGN# Assigns the resource name with a temporary ID.c.resource_name=client.path.campaign(customer_id,SMART_CAMPAIGN_TEMPORARY_ID)c.campaign_budget=client.path.campaign_budget(customer_id,BUDGET_TEMPORARY_ID)# Declare whether or not this campaign serves political ads targeting the EU.# Valid values are CONTAINS_EU_POLITICAL_ADVERTISING and# DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING.c.contains_eu_political_advertising=:DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISINGendendmutate_operationend
# Creates a MutateOperation that creates a new Smart campaign.# A temporary ID will be assigned to this campaign so that it can be referenced# by other objects being created in the same Mutate request.sub_create_smart_campaign_operation{my($customer_id)=@_;returnGoogle::Ads::GoogleAds::V22::Services::GoogleAdsService::MutateOperation->
new({campaignOperation=>
Google::Ads::GoogleAds::V22::Services::CampaignService::CampaignOperation->new({create=>Google::Ads::GoogleAds::V22::Resources::Campaign->new({name=>"Smart campaign #".uniqid(),# Set the campaign status as PAUSED. The campaign is the only# entity in the mutate request that should have its status set.status=>PAUSED,# AdvertisingChannelType must be SMART.advertisingChannelType=>SMART,# AdvertisingChannelSubType must be SMART_CAMPAIGN.advertisingChannelSubType=>
Google::Ads::GoogleAds::V22::Enums::AdvertisingChannelSubTypeEnum::SMART_CAMPAIGN,# Assign the resource name with a temporary ID.resourceName=>
Google::Ads::GoogleAds::V22::Utils::ResourceNames::campaign($customer_id,SMART_CAMPAIGN_TEMPORARY_ID),# Declare whether or not this campaign serves political ads targeting the EU.# Valid values are CONTAINS_EU_POLITICAL_ADVERTISING and# DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING.containsEuPoliticalAdvertising=>
DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING,# Set the budget using the given budget resource name.campaignBudget=>
Google::Ads::GoogleAds::V22::Utils::ResourceNames::campaign_budget($customer_id,BUDGET_TEMPORARY_ID)})})});}
defcreate_smart_campaign_setting_operation(client:GoogleAdsClient,customer_id:str,business_profile_location:Optional[str],business_name:Optional[str],)-> MutateOperation:"""Creates a MutateOperation to create a new SmartCampaignSetting. SmartCampaignSettings are unique in that they only support UPDATE operations, which are used to update and create them. Below we will use a temporary ID in the resource name to associate it with the campaign created in the previous step. Args: client: an initialized GoogleAdsClient instance. customer_id: a client customer ID. business_profile_location: the resource name of a Business Profile location. business_name: the name of a Business Profile. Returns: a MutateOperation that creates a SmartCampaignSetting. """mutate_operation:MutateOperation=client.get_type("MutateOperation")smart_campaign_setting_operation:SmartCampaignSettingOperation=(mutate_operation.smart_campaign_setting_operation)smart_campaign_setting:SmartCampaignSetting=(smart_campaign_setting_operation.update)# Set a temporary ID in the campaign setting's resource name to associate it# with the campaign created in the previous step.smart_campaign_setting.resource_name=client.get_service("SmartCampaignSettingService").smart_campaign_setting_path(customer_id,_SMART_CAMPAIGN_TEMPORARY_ID)# Below we configure the SmartCampaignSetting using many of the same# details used to generate a budget suggestion.smart_campaign_setting.phone_number.country_code=_COUNTRY_CODEsmart_campaign_setting.phone_number.phone_number=_PHONE_NUMBERsmart_campaign_setting.final_url=_LANDING_PAGE_URLsmart_campaign_setting.advertising_language_code=_LANGUAGE_CODE# Set either of the business_profile_location or business_name, depending on# whichever is provided.ifbusiness_profile_location:smart_campaign_setting.business_profile_location=(business_profile_location)else:smart_campaign_setting.business_name=business_name# Set the update mask on the operation. This is required since the smart# campaign setting is created in an UPDATE operation. Here the update# mask will be a list of all the fields that were set on the# SmartCampaignSetting.client.copy_from(smart_campaign_setting_operation.update_mask,protobuf_helpers.field_mask(None,smart_campaign_setting._pb),)returnmutate_operation
# Creates a mutate_operation to create a new smart_campaign_setting.# smart_campaign_settings are unique in that they only support UPDATE# operations, which are used to update and create them. Below we will# use a temporary ID in the resource name to associate it with the# campaign created in the previous step.defcreate_smart_campaign_setting_operation(client,customer_id,business_profile_location,business_name)mutate_operation=client.operation.mutatedo|m|m.smart_campaign_setting_operation=client.operation.update_resource.smart_campaign_setting(# Sets a temporary ID in the campaign setting's resource name to# associate it with the campaign created in the previous step.client.path.smart_campaign_setting(customer_id,SMART_CAMPAIGN_TEMPORARY_ID))do|scs|# Below we configure the smart_campaign_setting using many of the same# details used to generate a budget suggestion.scs.phone_number=client.resource.phone_numberdo|p|p.country_code=COUNTRY_CODEp.phone_number=PHONE_NUMBERendscs.final_url=LANDING_PAGE_URLscs.advertising_language_code=LANGUAGE_CODE# It's required that either a business location ID or a business name is# added to the smart_campaign_setting.ifbusiness_profile_locationscs.business_profile_location=business_profile_locationelsescs.business_name=business_nameendendendmutate_operationend
# Creates a MutateOperation to create a new SmartCampaignSetting.# SmartCampaignSettings are unique in that they only support UPDATE operations,# which are used to update and create them. Below we will use a temporary ID in# the resource name to associate it with the campaign created in the previous step.sub_create_smart_campaign_setting_operation{my($customer_id,$business_profile_location,$business_name)=@_;my$smart_campaign_setting=Google::Ads::GoogleAds::V22::Resources::SmartCampaignSetting->new({# Set a temporary ID in the campaign setting's resource name to associate it# with the campaign created in the previous step.resourceName=>
Google::Ads::GoogleAds::V22::Utils::ResourceNames::smart_campaign_setting($customer_id,SMART_CAMPAIGN_TEMPORARY_ID),# Below we configure the SmartCampaignSetting using many of the same# details used to generate a budget suggestion.phoneNumber=>Google::Ads::GoogleAds::V22::Resources::PhoneNumber->new({countryCode=>COUNTRY_CODE,phoneNumber=>PHONE_NUMBER}),finalUrl=>LANDING_PAGE_URL,advertisingLanguageCode=>LANGUAGE_CODE});# It's required that either a business profile location or a business name is# added to the SmartCampaignSetting.if(defined$business_profile_location){$smart_campaign_setting->{businessProfileLocation}=$business_profile_location;}else{$smart_campaign_setting->{businessName}=$business_name;}returnGoogle::Ads::GoogleAds::V22::Services::GoogleAdsService::MutateOperation->
new({smartCampaignSettingOperation=>
Google::Ads::GoogleAds::V22::Services::SmartCampaignSettingService::SmartCampaignSettingOperation->new({update=>$smart_campaign_setting,# Set the update mask on the operation. This is required since the# smart campaign setting is created in an UPDATE operation. Here the# update mask will be a list of all the fields that were set on the# SmartCampaignSetting.updateMask=>all_set_fields_of($smart_campaign_setting)})});}
SmartCampaignSettingsmartCampaignSetting=SmartCampaignSetting.newBuilder().setBusinessProfileLocation(businessProfileLocation)// Sets the ad optimized business profile setting to an empty// instance of AdOptimizedBusinessProfileSetting..setAdOptimizedBusinessProfileSetting(AdOptimizedBusinessProfileSetting.newBuilder().build()).build();
C#
SmartCampaignSettingsmartCampaignSetting=newSmartCampaignSetting(){BusinessProfileLocation=businessProfileLocation,/// Sets the ad optimized business profile setting to an empty/// instance of AdOptimizedBusinessProfileSetting.AdOptimizedBusinessProfileSetting=newSmartCampaignSetting.Types.AdOptimizedBusinessProfileSetting()};
PHP
$smartCampaignSetting = new SmartCampaignSetting([ 'business_profile_location' => business_profile_location, // Sets the ad optimized business profile setting to an empty instance // of AdOptimizedBusinessProfileSetting. 'ad_optimized_business_profile_setting' => new AdOptimizedBusinessProfileSetting(),]);
Python
smart_campaign_setting=client.get_type("SmartCampaignSetting")smart_campaign_setting.business_profile_location=business_profile_location# Sets the ad optimized business profile setting to an empty instance of# AdOptimizedBusinessProfileSetting.client.copy_from(smart_campaign_setting.ad_optimized_business_profile_setting,client.get_type("AdOptimizedBusinessProfileSetting"))
Ruby
smart_campaign_setting=client.resource.smart_campaign_settingdo|s|s.business_profile_location=business_profile_location# Sets the ad optimized business profile setting to an empty instance of# AdOptimizedBusinessProfileSetting.s.ad_optimized_business_profile_setting=client.resource.ad_optimized_business_profile_settingend
Perl
my$campaign=Google::Ads::GoogleAds::V22::Resources::Campaign->new({businessProfileLocation=>$business_profile_location,# Sets the ad optimized business profile setting to an empty instance of# AdOptimizedBusinessProfileSetting.adOptimizedBusinessProfileSetting=>
Google::Ads::GoogleAds::V22::Common::AdOptimizedBusinessProfileSetting->new()});
SmartCampaignSettingsmartCampaignSetting=SmartCampaignSetting.newBuilder().setBusinessProfileLocation(businessProfileLocation)// Sets the AdOptimizedBusinessProfileSetting.include_lead_form field to true..setAdOptimizedBusinessProfileSetting(AdOptimizedBusinessProfileSetting.newBuilder().setIncludeLeadForm(true).build()).build();
C#
SmartCampaignSettingsmartCampaignSetting=newSmartCampaignSetting(){BusinessProfileLocation=businessProfileLocation,/// Sets the AdOptimizedBusinessProfileSetting.include_lead_form/// field to true.AdOptimizedBusinessProfileSetting=newSmartCampaignSetting.Types.AdOptimizedBusinessProfileSetting{IncludeLeadForm=true}};
PHP
$smartCampaignSetting = new SmartCampaignSetting([ 'business_profile_location' => business_profile_location, // Sets the AdOptimizedBusinessProfileSetting.include_lead_form field // to true. 'ad_optimized_business_profile_setting' => new AdOptimizedBusinessProfileSetting([ 'include_lead_form' => true ]),]);
Python
smart_campaign_setting=client.get_type("SmartCampaignSetting")smart_campaign_setting.business_profile_location=business_profile_location# Sets the AdOptimizedBusinessProfileSetting.include_lead_form field to# true.smart_campaign_setting.ad_optimized_business_profile_setting.include_lead_form=True
Ruby
smart_campaign_setting=client.resource.smart_campaign_settingdo|s|s.business_profile_location=business_profile_location# Sets the AdOptimizedBusinessProfileSetting.include_lead_form field to# true.s.ad_optimized_business_profile_setting=client.resource.ad_optimized_business_profile_settingdo|a|a.include_lead_form=trueendend
Perl
my$campaign=Google::Ads::GoogleAds::V22::Resources::Campaign->new({businessProfileLocation=>$business_profile_location,# Sets the AdOptimizedBusinessProfileSetting.include_lead_form field to# true.adOptimizedBusinessProfileSetting=>
Google::Ads::GoogleAds::V22::Common::AdOptimizedBusinessProfileSetting->new({includeLeadForm=>"true"})});