Create a campaign

A campaign groups insertion orders with a common business goal. Campaign resources do the following:

  • Control the ad serving of their child line items through the entity status.
  • Enforce a frequency cap across their insertion orders.
  • Enable reporting and goal tracking across all child resources.

If you are using an existing campaign, you can skip to Create a insertion order .

Choose configurations

Before creating a campaign, review and decide on these settings:

The Campaign resource also has many optional fields. Read the reference documentation for more information.

How to create a campaign

Here's how to create a campaign with the following settings:

  • A goal of raising brand awareness at a cost-per-view of one unit of currency.
  • A flight period starting on the provided date without a set end.

Java

 // Provide the ID of the parent advertiser. 
 String 
  
 advertiserId 
  
 = 
  
  advertiser 
 - 
 id 
 
 ; 
 // Provide the display name of the campaign. 
 String 
  
 displayName 
  
 = 
  
  display 
 - 
 name 
 
 ; 
 // Provide the campaign start date as a separate year, month, and day value. 
 int 
  
 year 
  
 = 
  
  start 
 - 
 date 
 - 
 year 
 
 ; 
 int 
  
 month 
  
 = 
  
  start 
 - 
 date 
 - 
 month 
 
 ; 
 int 
  
 day 
  
 = 
  
  start 
 - 
 date 
 - 
 day 
 
 ; 
 // Create the campaign structure. 
 Campaign 
  
 campaign 
  
 = 
  
 new 
  
 Campaign 
 (). 
 setDisplayName 
 ( 
 displayName 
 ). 
 setEntityStatus 
 ( 
 "ENTITY_STATUS_ACTIVE" 
 ); 
 // Create the campaign goal structure. 
 CampaignGoal 
  
 campaignGoal 
  
 = 
  
 new 
  
 CampaignGoal 
 (). 
 setCampaignGoalType 
 ( 
 "CAMPAIGN_GOAL_TYPE_BRAND_AWARENESS" 
 ); 
 // Create and add the performance goal to the campaign goal structure. 
 PerformanceGoal 
  
 performanceGoal 
  
 = 
  
 new 
  
 PerformanceGoal 
 () 
  
 . 
 setPerformanceGoalType 
 ( 
 "PERFORMANCE_GOAL_TYPE_CPV" 
 ) 
  
 . 
 setPerformanceGoalAmountMicros 
 ( 
 1_000_000L 
 ); 
 campaignGoal 
 . 
 setPerformanceGoal 
 ( 
 performanceGoal 
 ); 
 // Set the campaign goal. 
 campaign 
 . 
 setCampaignGoal 
 ( 
 campaignGoal 
 ); 
 // Create the campaign flight structure. 
 // This object details the planned spend and duration of the campaign. 
 CampaignFlight 
  
 campaignFlight 
  
 = 
  
 new 
  
 CampaignFlight 
 (). 
 setPlannedSpendAmountMicros 
 ( 
 1_000_000L 
 ); 
 // Assign to date range object. 
 DateRange 
  
 dateRange 
  
 = 
  
 new 
  
 DateRange 
 (). 
 setStartDate 
 ( 
 new 
  
 Date 
 (). 
 setYear 
 ( 
 year 
 ). 
 setMonth 
 ( 
 month 
 ). 
 setDay 
 ( 
 day 
 )); 
 // Add the planned date range to the campaign flight. 
 campaignFlight 
 . 
 setPlannedDates 
 ( 
 dateRange 
 ); 
 // Set the campaign flight. 
 campaign 
 . 
 setCampaignFlight 
 ( 
 campaignFlight 
 ); 
 // Create and set the frequency cap. 
 FrequencyCap 
  
 frequencyCap 
  
 = 
  
 new 
  
 FrequencyCap 
 (). 
 setUnlimited 
 ( 
 true 
 ); 
 campaign 
 . 
 setFrequencyCap 
 ( 
 frequencyCap 
 ); 
 // Configure the create request. 
 Campaigns 
 . 
 Create 
  
 request 
  
 = 
  
 service 
 . 
 advertisers 
 (). 
 campaigns 
 (). 
 create 
 ( 
 advertiserId 
 , 
  
 campaign 
 ); 
 // Create the campaign. 
 Campaign 
  
 response 
  
 = 
  
 request 
 . 
 execute 
 (); 
 // Display the new campaign ID. 
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Campaign %s was created." 
 , 
  
 response 
 . 
 getName 
 ()); 

Python

 # Provide the ID of the parent advertiser. 
 advertiser_id 
 = 
  advertiser 
 - 
 id 
 
 # Provide the display name of the campaign. 
 display_name 
 = 
  display 
 - 
 name 
 
 # Provide the year, month, and day of the start date of the campaign flight. 
 start_date_year 
 = 
  start 
 - 
 date 
 - 
 year 
 
 start_date_month 
 = 
  start 
 - 
 date 
 - 
 month 
 
 start_date_day 
 = 
  start 
 - 
 date 
 - 
 day 
 
 # Create the campaign object. 
 campaign_obj 
 = 
 { 
 "displayName" 
 : 
 display_name 
 , 
 "entityStatus" 
 : 
 "ENTITY_STATUS_ACTIVE" 
 , 
 "campaignGoal" 
 : 
 { 
 "campaignGoalType" 
 : 
 "CAMPAIGN_GOAL_TYPE_BRAND_AWARENESS" 
 , 
 "performanceGoal" 
 : 
 { 
 "performanceGoalType" 
 : 
 "PERFORMANCE_GOAL_TYPE_CPV" 
 , 
 "performanceGoalAmountMicros" 
 : 
 "1000000" 
 , 
 }, 
 }, 
 "campaignFlight" 
 : 
 { 
 "plannedDates" 
 : 
 { 
 "startDate" 
 : 
 { 
 "year" 
 : 
 start_date_year 
 , 
 "month" 
 : 
 start_date_month 
 , 
 "day" 
 : 
 start_date_day 
 , 
 } 
 } 
 }, 
 "frequencyCap" 
 : 
 { 
 "unlimited" 
 : 
 True 
 }, 
 } 
 # Build and execute request. 
 campaign_response 
 = 
 ( 
 service 
 . 
 advertisers 
 () 
 . 
 campaigns 
 () 
 . 
 create 
 ( 
 advertiserId 
 = 
 advertiser_id 
 , 
 body 
 = 
 campaign_obj 
 ) 
 . 
 execute 
 () 
 ) 
 # Print the new campaign. 
 print 
 ( 
 f 
 'Campaign 
 { 
 campaign_response 
 [ 
 "name" 
 ] 
 } 
 was created.' 
 ) 

PHP

 // Provide the ID of the parent advertiser. 
 $advertiserId = advertiser-id 
; 
 // Provide the display name of the campaign. 
 $displayName = display-name 
; 
 // Provide the year, month, and day of the start date of the campaign flight. 
 $year = start-date-year 
; 
 $month = start-date-month 
; 
 $day = start-date-day 
; 
 // Create the campaign structure. 
 $campaign = new Google_Service_DisplayVideo_Campaign(); 
 $campaign->setDisplayName($displayName); 
 $campaign->setEntityStatus('ENTITY_STATUS_ACTIVE'); 
 // Create and set the campaign goal. 
 $campaignGoal = new Google_Service_DisplayVideo_CampaignGoal(); 
 $campaignGoal->setCampaignGoalType( 
 'CAMPAIGN_GOAL_TYPE_BRAND_AWARENESS' 
 ); 
 $performanceGoal = new Google_Service_DisplayVideo_PerformanceGoal(); 
 $performanceGoal->setPerformanceGoalType('PERFORMANCE_GOAL_TYPE_CPV'); 
 $performanceGoal->setPerformanceGoalAmountMicros(1000000); 
 $campaignGoal->setPerformanceGoal($performanceGoal); 
 $campaign->setCampaignGoal($campaignGoal); 
 // Create and set the campaign flight. 
 $campaignFlight = new Google_Service_DisplayVideo_CampaignFlight(); 
 $campaignFlight->setPlannedSpendAmountMicros(1000000); 
 $dateRange = new Google_Service_DisplayVideo_DateRange(); 
 $startDate = new Google_Service_DisplayVideo_Date(); 
 $startDate->setYear($year); 
 $startDate->setMonth($month); 
 $startDate->setDay($day); 
 $dateRange->setStartDate($startDate); 
 $campaignFlight->setPlannedDates($dateRange); 
 $campaign->setCampaignFlight($campaignFlight); 
 // Create and set the frequency cap. 
 $frequencyCap = new Google_Service_DisplayVideo_FrequencyCap(); 
 $frequencyCap->setUnlimited(true); 
 $campaign->setFrequencyCap($frequencyCap); 
 // Call the API, creating the campaign under the given advertiser. 
 try { 
 $result = $this->service->advertisers_campaigns->create( 
 $advertiserId, 
 $campaign 
 ); 
 } catch (\Exception $e) { 
 $this->renderError($e); 
 return; 
 } 
 // Print the new campaign. 
 printf('<p>Campaign %s was created.</p>', $result['name']); 
Create a Mobile Website
View Site in Mobile | Classic
Share by: