Create Native Display creative

Here's how to create a Native Display creative :

Java

 // Provide the parent advertiser ID to create the creative under. 
 long 
  
 advertiserId 
  
 = 
  
  advertiser 
 - 
 id 
 
 ; 
 // Provide the display name of the creative. 
 String 
  
 displayName 
  
 = 
  
  display 
 - 
 name 
 
 ; 
 // Provide the dimensions of the creative in pixels. 
 int 
  
 heightPx 
  
 = 
  
  height 
 - 
 pixels 
 
 ; 
 int 
  
 widthPx 
  
 = 
  
  width 
 - 
 pixels 
 
 ; 
 // Provide the media IDs, text values, and URLs used as assets by the creative. 
 long 
  
 imgMediaId 
  
 = 
  
  image 
 - 
 media 
 - 
 id 
 
 ; 
 long 
  
 logoMediaId 
  
 = 
  
  logo 
 - 
 media 
 - 
 id 
 
 ; 
 String 
  
 advertiserNameText 
  
 = 
  
  advertiser 
 - 
 name 
 - 
 text 
 
 ; 
 String 
  
 headlineText 
  
 = 
  
  headline 
 - 
 text 
 
 ; 
 String 
  
 bodyText 
  
 = 
  
  body 
 - 
 text 
 
 ; 
 String 
  
 captionUrl 
  
 = 
  
  caption 
 - 
 url 
 
 ; 
 String 
  
 callToActionText 
  
 = 
  
  call 
 - 
 to 
 - 
 action 
 - 
 text 
 
 ; 
 // Provide the URL of the page that the creative redirects to. 
 String 
  
 landingPageUrl 
  
 = 
  
  landing 
 - 
 page 
 - 
 url 
 
 ; 
 // Create a creative object. 
 Creative 
  
 creative 
  
 = 
  
 new 
  
 Creative 
 () 
  
 . 
 setDisplayName 
 ( 
 displayName 
 ) 
  
 . 
 setEntityStatus 
 ( 
 "ENTITY_STATUS_ACTIVE" 
 ) 
  
 . 
 setHostingSource 
 ( 
 "HOSTING_SOURCE_HOSTED" 
 ) 
  
 . 
 setCreativeType 
 ( 
 "CREATIVE_TYPE_NATIVE" 
 ); 
 // Create and add the dimensions object. 
 Dimensions 
  
 dimensions 
  
 = 
  
 new 
  
 Dimensions 
 (). 
 setHeightPixels 
 ( 
 heightPx 
 ). 
 setWidthPixels 
 ( 
 widthPx 
 ); 
 creative 
 . 
 setDimensions 
 ( 
 dimensions 
 ); 
 // Create the list of associated assets. 
 List<AssetAssociation 
 > 
  
 assetAssociations 
  
 = 
  
 new 
  
 ArrayList 
< > 
 (); 
 // Assign the image asset to a role. 
 AssetAssociation 
  
 mainImageAssetAssociation 
  
 = 
  
 new 
  
 AssetAssociation 
 () 
  
 . 
 setAsset 
 ( 
 new 
  
 Asset 
 (). 
 setMediaId 
 ( 
 imgMediaId 
 )) 
  
 . 
 setRole 
 ( 
 "ASSET_ROLE_MAIN" 
 ); 
 assetAssociations 
 . 
 add 
 ( 
 mainImageAssetAssociation 
 ); 
 // Assign the logo asset to a role. 
 AssetAssociation 
  
 iconAssetAssociation 
  
 = 
  
 new 
  
 AssetAssociation 
 () 
  
 . 
 setAsset 
 ( 
 new 
  
 Asset 
 (). 
 setMediaId 
 ( 
 logoMediaId 
 )) 
  
 . 
 setRole 
 ( 
 "ASSET_ROLE_ICON" 
 ); 
 assetAssociations 
 . 
 add 
 ( 
 iconAssetAssociation 
 ); 
 // Create and assign advertiser name asset. 
 Asset 
  
 advertiserNameAsset 
  
 = 
  
 new 
  
 Asset 
 (). 
 setContent 
 ( 
 advertiserNameText 
 ); 
 AssetAssociation 
  
 advertiserNameAssetAssociation 
  
 = 
  
 new 
  
 AssetAssociation 
 (). 
 setAsset 
 ( 
 advertiserNameAsset 
 ). 
 setRole 
 ( 
 "ASSET_ROLE_ADVERTISER_NAME" 
 ); 
 assetAssociations 
 . 
 add 
 ( 
 advertiserNameAssetAssociation 
 ); 
 // Create and assign headline asset. 
 Asset 
  
 headlineAsset 
  
 = 
  
 new 
  
 Asset 
 (). 
 setContent 
 ( 
 headlineText 
 ); 
 AssetAssociation 
  
 headlineAssetAssociation 
  
 = 
  
 new 
  
 AssetAssociation 
 (). 
 setAsset 
 ( 
 headlineAsset 
 ). 
 setRole 
 ( 
 "ASSET_ROLE_HEADLINE" 
 ); 
 assetAssociations 
 . 
 add 
 ( 
 headlineAssetAssociation 
 ); 
 // Create and assign body text asset. 
 Asset 
  
 bodyTextAsset 
  
 = 
  
 new 
  
 Asset 
 (). 
 setContent 
 ( 
 bodyText 
 ); 
 AssetAssociation 
  
 bodyTextAssetAssociation 
  
 = 
  
 new 
  
 AssetAssociation 
 (). 
 setAsset 
 ( 
 bodyTextAsset 
 ). 
 setRole 
 ( 
 "ASSET_ROLE_BODY" 
 ); 
 assetAssociations 
 . 
 add 
 ( 
 bodyTextAssetAssociation 
 ); 
 // Create and assign caption URL asset. 
 Asset 
  
 captionUrlAsset 
  
 = 
  
 new 
  
 Asset 
 (). 
 setContent 
 ( 
 captionUrl 
 ); 
 AssetAssociation 
  
 captionUrlAssetAssociation 
  
 = 
  
 new 
  
 AssetAssociation 
 (). 
 setAsset 
 ( 
 captionUrlAsset 
 ). 
 setRole 
 ( 
 "ASSET_ROLE_CAPTION_URL" 
 ); 
 assetAssociations 
 . 
 add 
 ( 
 captionUrlAssetAssociation 
 ); 
 // Create and assign call to action asset. 
 Asset 
  
 callToActionAsset 
  
 = 
  
 new 
  
 Asset 
 (). 
 setContent 
 ( 
 callToActionText 
 ); 
 AssetAssociation 
  
 callToActionAssetAssociation 
  
 = 
  
 new 
  
 AssetAssociation 
 (). 
 setAsset 
 ( 
 callToActionAsset 
 ). 
 setRole 
 ( 
 "ASSET_ROLE_CALL_TO_ACTION" 
 ); 
 assetAssociations 
 . 
 add 
 ( 
 callToActionAssetAssociation 
 ); 
 // Set the list of creative assets. 
 creative 
 . 
 setAssets 
 ( 
 assetAssociations 
 ); 
 // Create an exit event. 
 ExitEvent 
  
 exitEvent 
  
 = 
  
 new 
  
 ExitEvent 
 (). 
 setType 
 ( 
 "EXIT_EVENT_TYPE_DEFAULT" 
 ). 
 setUrl 
 ( 
 landingPageUrl 
 ); 
 // Create and set the list of exit events for the creative. 
 creative 
 . 
 setExitEvents 
 ( 
 ImmutableList 
 . 
 of 
 ( 
 exitEvent 
 )); 
 // Configure the create request. 
 Creatives 
 . 
 Create 
  
 request 
  
 = 
  
 service 
 . 
 advertisers 
 (). 
 creatives 
 (). 
 create 
 ( 
 advertiserId 
 , 
  
 creative 
 ); 
 // Send the request. 
 Creative 
  
 response 
  
 = 
  
 request 
 . 
 execute 
 (); 
 // Display ID of the new creative. 
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Creative was created with ID %s." 
 , 
  
 response 
 . 
 getCreativeId 
 ()); 

Python

 # Provide the parent advertiser ID to create the creative under. 
 advertiser_id 
 = 
  advertiser 
 - 
 id 
 
 # Provide the display name of the creative. 
 display_name 
 = 
  display 
 - 
 name 
 
 # Provide the dimensions of the creative in pixels. 
 height_pixels 
 = 
  height 
 - 
 pixels 
 
 width_pixels 
 = 
  width 
 - 
 pixels 
 
 # Provide the media IDs, text values, and URLs used as assets by the creative. 
 image_media_id 
 = 
  image 
 - 
 media 
 - 
 id 
 
 logo_media_id 
 = 
  logo 
 - 
 media 
 - 
 id 
 
 advertiser_name_text 
 = 
  advertiser 
 - 
 name 
 
 headline_text 
 = 
  headline 
 
 body_text 
 = 
  body 
 - 
 text 
 
 caption_url 
 = 
  caption 
 - 
 url 
 
 call_to_action_text 
 = 
  call 
 - 
 to 
 - 
 action 
 - 
 text 
 
 # Provide the URL of the page that the creative redirects to. 
 landing_page_url 
 = 
  landing 
 - 
 page 
 - 
 url 
 
 # Build the creative object. 
 creative_obj 
 = 
 { 
 "displayName" 
 : 
 display_name 
 , 
 "entityStatus" 
 : 
 "ENTITY_STATUS_ACTIVE" 
 , 
 "hostingSource" 
 : 
 "HOSTING_SOURCE_HOSTED" 
 , 
 "creativeType" 
 : 
 "CREATIVE_TYPE_NATIVE" 
 , 
 "dimensions" 
 : 
 { 
 "heightPixels" 
 : 
 height_pixels 
 , 
 "widthPixels" 
 : 
 width_pixels 
 , 
 }, 
 "assets" 
 : 
 [ 
 { 
 "asset" 
 : 
 { 
 "mediaId" 
 : 
 image_media_id 
 }, 
 "role" 
 : 
 "ASSET_ROLE_MAIN" 
 , 
 }, 
 { 
 "asset" 
 : 
 { 
 "mediaId" 
 : 
 logo_media_id 
 }, 
 "role" 
 : 
 "ASSET_ROLE_ICON" 
 , 
 }, 
 { 
 "asset" 
 : 
 { 
 "content" 
 : 
 advertiser_name_text 
 }, 
 "role" 
 : 
 "ASSET_ROLE_ADVERTISER_NAME" 
 , 
 }, 
 { 
 "asset" 
 : 
 { 
 "content" 
 : 
 headline_text 
 }, 
 "role" 
 : 
 "ASSET_ROLE_HEADLINE" 
 , 
 }, 
 { 
 "asset" 
 : 
 { 
 "content" 
 : 
 body_text 
 }, 
 "role" 
 : 
 "ASSET_ROLE_BODY" 
 , 
 }, 
 { 
 "asset" 
 : 
 { 
 "content" 
 : 
 caption_url 
 }, 
 "role" 
 : 
 "ASSET_ROLE_CAPTION_URL" 
 , 
 }, 
 { 
 "asset" 
 : 
 { 
 "content" 
 : 
 call_to_action_text 
 }, 
 "role" 
 : 
 "ASSET_ROLE_CALL_TO_ACTION" 
 , 
 }, 
 ], 
 "exitEvents" 
 : 
 [{ 
 "type" 
 : 
 "EXIT_EVENT_TYPE_DEFAULT" 
 , 
 "url" 
 : 
 landing_page_url 
 , 
 }], 
 } 
 # Create the creative. 
 creative_response 
 = 
 ( 
 service 
 . 
 advertisers 
 () 
 . 
 creatives 
 () 
 . 
 create 
 ( 
 advertiserId 
 = 
 advertiser_id 
 , 
 body 
 = 
 creative_obj 
 ) 
 . 
 execute 
 () 
 ) 
 # Print the resulting creative ID. 
 print 
 ( 
 f 
 'Creative was created with ID 
 { 
 creative_response 
 [ 
 "creativeId" 
 ] 
 } 
 .' 
 ) 

PHP

 // Provide the parent advertiser ID to create the creative under. 
 $advertiserId = advertiser-id 
; 
 // Provide the display name of the creative. 
 $displayName = display-name 
; 
 // Provide the dimensions of the creative in pixels. 
 $creativeHeightPixels = height-pixels 
; 
 $creativeWidthPixels = width-pixels 
; 
 // Provide the media IDs, text values, and URLs used as assets by the creative. 
 $imageMediaId = image-media-id 
; 
 $logoMediaId = logo-media-id 
; 
 $advertiserName = advertiser-name 
; 
 $headline = headline 
; 
 $bodyText = body-text 
; 
 $captionUrl = caption-url 
; 
 $callToAction = call-to-action 
; 
 // Provide the URL of the page that the creative redirects to. 
 $landingPageUrl = landing-page-url 
; 
 // Create a creative object. 
 $creative = new Google_Service_DisplayVideo_Creative(); 
 $creative->setDisplayName($displayName); 
 $creative->setEntityStatus('ENTITY_STATUS_ACTIVE'); 
 $creative->setHostingSource('HOSTING_SOURCE_HOSTED'); 
 $creative->setCreativeType('CREATIVE_TYPE_NATIVE'); 
 // Create and add the dimensions object. 
 $dimensions = new Google_Service_DisplayVideo_Dimensions(); 
 $dimensions->setHeightPixels($creativeHeightPixels); 
 $dimensions->setWidthPixels($creativeWidthPixels); 
 $creative->setDimensions($dimensions); 
 // Create and set the list of exit events. 
 $exitEvent = new Google_Service_DisplayVideo_ExitEvent(); 
 $exitEvent->setType('EXIT_EVENT_TYPE_DEFAULT'); 
 $exitEvent->setUrl($landingPageUrl); 
 $creative->setExitEvents(array($exitEvent)); 
 // Create the list of associated assets. 
 $assetAssociations = array(); 
 // Assign the image asset to a role. 
 $imageAssetAssoc = new Google_Service_DisplayVideo_AssetAssociation(); 
 $imageAsset = new Google_Service_DisplayVideo_Asset(); 
 $imageAsset->setMediaId($imageMediaId); 
 $imageAssetAssoc->setAsset($imageAsset); 
 $imageAssetAssoc->setRole('ASSET_ROLE_MAIN'); 
 $assetAssociations[] = $imageAssetAssoc; 
 // Assign the logo asset to a role. 
 $logoAssetAssoc = new Google_Service_DisplayVideo_AssetAssociation(); 
 $logoAsset = new Google_Service_DisplayVideo_Asset(); 
 $logoAsset->setMediaId($logoMediaId); 
 $logoAssetAssoc->setAsset($logoAsset); 
 $logoAssetAssoc->setRole('ASSET_ROLE_ICON'); 
 $assetAssociations[] = $logoAssetAssoc; 
 // Create and assign advertiser name asset. 
 $AdvAssetAssoc = new Google_Service_DisplayVideo_AssetAssociation(); 
 $AdvAsset = new Google_Service_DisplayVideo_Asset(); 
 $AdvAsset->setContent($advertiserName); 
 $AdvAssetAssoc->setAsset($AvdAsset); 
 $AdvAssetAssoc->setRole('ASSET_ROLE_ADVERTISER_NAME'); 
 $assetAssociations[] = $AdvAssetAssoc; 
 // Create and assign headline asset. 
 $headlineAssetAssoc = new Google_Service_DisplayVideo_AssetAssociation(); 
 $headlineAsset = new Google_Service_DisplayVideo_Asset(); 
 $headlineAsset->setContent($headline); 
 $headlineAssetAssoc->setAsset($headlineAsset); 
 $headlineAssetAssoc->setRole('ASSET_ROLE_HEADLINE'); 
 $assetAssociations[] = $headlineAssetAssoc; 
 // Create and assign body text asset. 
 $bodyAssetAssoc = new Google_Service_DisplayVideo_AssetAssociation(); 
 $bodyAsset = new Google_Service_DisplayVideo_Asset(); 
 $bodyAsset->setContent($bodyText); 
 $bodyAssetAssoc->setAsset($bodyAsset); 
 $bodyAssetAssoc->setRole('ASSET_ROLE_BODY'); 
 $assetAssociations[] = $bodyAssetAssoc; 
 // Create and assign caption URL asset. 
 $captionAssetAssoc = new Google_Service_DisplayVideo_AssetAssociation(); 
 $captionAsset = new Google_Service_DisplayVideo_Asset(); 
 $captionAsset->setContent($captionUrl); 
 $captionAssetAssoc->setAsset($captionAsset); 
 $captionAssetAssoc->setRole('ASSET_ROLE_CAPTION_URL'); 
 $assetAssociations[] = $captionAssetAssoc; 
 // Create and assign call to action asset. 
 $callToActionAssetAssoc = new Google_Service_DisplayVideo_AssetAssociation(); 
 $callToActionAsset = new Google_Service_DisplayVideo_Asset(); 
 $callToActionAsset->setContent($callToAction); 
 $callToActionAssetAssoc->setAsset($callToActionAsset); 
 $callToActionAssetAssoc->setRole('ASSET_ROLE_CALL_TO_ACTION'); 
 $assetAssociations[] = $callToActionAssetAssoc; 
 // Set the list of creative assets. 
 $creative->setAssets($assetAssociations); 
 // Create the native site creative under the given advertiser. 
 try { 
 $result = $this->service->advertisers_creatives->create( 
 $advertiserId, 
 $creative 
 ); 
 } catch (\Exception $e) { 
 $this->renderError($e); 
 return; 
 } 
 // Display ID of the new creative. 
 printf('<p>Creative was created with ID %s.</p>', $result['creativeId']); 
Create a Mobile Website
View Site in Mobile | Classic
Share by: