Here's how to create a HTML5 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 ID of the uploaded HTML5 ZIP file. long html5ZipMediaId = html5 - zip - media - id ; // Provide the URL of the page that the creative redirects to and the name // of the click tag used in the exit event. String exitEventUrl = exit - event - url ; String exitEventName = exit - event - name ; // Create the creative structure. Creative creative = new Creative () . setDisplayName ( displayName ) . setEntityStatus ( "ENTITY_STATUS_ACTIVE" ) . setHostingSource ( "HOSTING_SOURCE_HOSTED" ) . setCreativeType ( "CREATIVE_TYPE_STANDARD" ); // Create and add the dimensions object. Dimensions dimensions = new Dimensions (). setHeightPixels ( heightPx ). setWidthPixels ( widthPx ); creative . setDimensions ( dimensions ); // Assign the HTML5 asset to a role. AssetAssociation assetAssociation = new AssetAssociation () . setAsset ( new Asset (). setMediaId ( html5ZipMediaId )) . setRole ( "ASSET_ROLE_MAIN" ); // Create and set the list of creative assets. creative . setAssets ( ImmutableList . of ( assetAssociation )); // Create an exit event. ExitEvent exitEvent = new ExitEvent () . setName ( exitEventName ) . setType ( "EXIT_EVENT_TYPE_DEFAULT" ) . setUrl ( exitEventUrl ); // 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 ID of the uploaded HTML5 ZIP file. html5_zip_media_id = html5 - zip - media - id # Provide the URL of the page that the creative redirects to and the name of the # click tag used in the exit event. exit_event_url = exit - event - url exit_event_name = exit - event - name # Build the creative object. creative_obj = { "displayName" : display_name , "entityStatus" : "ENTITY_STATUS_ACTIVE" , "hostingSource" : "HOSTING_SOURCE_HOSTED" , "creativeType" : "CREATIVE_TYPE_STANDARD" , "dimensions" : { "heightPixels" : height_pixels , "widthPixels" : width_pixels , }, "assets" : [{ "asset" : { "mediaId" : html5_zip_media_id }, "role" : "ASSET_ROLE_MAIN" , }], "exitEvents" : [{ "name" : exit_event_name , "type" : "EXIT_EVENT_TYPE_DEFAULT" , "url" : exit_event_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 ID of the uploaded HTML5 ZIP file. $htmlMediaId = html5-zip-media-id ; // Provide the URL of the page that the creative redirects to and the name // of the click tag used in the exit event. $exitEventName = exit-event-name ; $exitEventUrl = exit-event-url ; // Create the creative structure. $creative = new Google_Service_DisplayVideo_Creative(); $creative->setDisplayName($displayName); $creative->setEntityStatus('ENTITY_STATUS_ACTIVE'); $creative->setHostingSource('HOSTING_SOURCE_HOSTED'); $creative->setCreativeType('CREATIVE_TYPE_STANDARD'); // Create and add the dimensions object. $dimensions = new Google_Service_DisplayVideo_Dimensions(); $dimensions->setHeightPixels($creativeHeightPixels); $dimensions->setWidthPixels($creativeWidthPixels); $creative->setDimensions($dimensions); // Create an exit event. $exitEvent = new Google_Service_DisplayVideo_ExitEvent(); $exitEvent->setName($exitEventName); $exitEvent->setType('EXIT_EVENT_TYPE_DEFAULT'); $exitEvent->setUrl($exitEventUrl); $creative->setExitEvents(array($exitEvent)); // Create and set the list of creative assets. $assetAssociation = new Google_Service_DisplayVideo_AssetAssociation(); $asset = new Google_Service_DisplayVideo_Asset(); $asset->setMediaId($htmlMediaId); $assetAssociation->setAsset($asset); $assetAssociation->setRole('ASSET_ROLE_MAIN'); $creative->setAssets(array($assetAssociation)); // Create the creative. try { $result = $this->service->advertisers_creatives->create( $advertiserId, $creative ); } catch (\Exception $e) { $this->renderError($e); return; } // Print the resulting creative ID. printf('<p>Creative was created with ID %s.</p>', $result['creativeId']);

