Last month, we announced the ability to create both custom and template creatives using the DFP API. Today we’ll show you can use these premium-only features to create richer creatives with custom HTML.
Custom or template
The difference between custom and template creatives is that custom creatives have their HTML snippet set within them, while template creatives are instantiated from system or user defined HTML snippets. Deciding which one to use depends on your network’s needs. If your network deals primarily with traffickers using the DFP UI, it may be beneficial for them to use creative templates in their workflow. The API could be used to retrieve these templates and report on them, but your traffickers would most likely want to create the creatives from templates in the UI.
However, if you are developing a platform in which traffickers spend most of their day, it may scale better to template the HTML yourself within your content management system (CMS) and use custom creatives for the advertisements. You could store custom HTML snippets and prompt the user for assets to insert. In essence, you would be creating your own templates, but without the overhead of template creatives.
Creating custom creatives
To create a custom creative, you first have to define your HTML snippet:
String htmlSnippet = "<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>"
+ "<img src='%%FILE:IMAGE_ASSET%%'/></a><br>Click for great deals!");
CustomCreative customCreative = new CustomCreative();
customCreative.setHtmlSnippet(htmlSnippet);
Notice here that the CLICK_URL_UNESC, DEST_URL, and FILE macros are used to customize the creative at serving time. CLICK_URL_UNESC will insert the clickthrough URL while DEST_URL inserts the URL that the ad points to. The FILE macro will reference any attached assets to the creative, in this case one named IMAGE_ASSET.
// Set the custom creative image asset.
CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
customCreativeAsset.setMacroName("IMAGE_ASSET");
customCreativeAsset.setAssetByteArray(/* Byte array from image. */);
customCreativeAsset.setFileName(
String.format("image%s.jpg", System.currentTimeMillis()));
customCreative.setCustomCreativeAssets(
new CustomCreativeAsset[] {customCreativeAsset});
You would then call CreativeService.createCreative on customCreative to instantiate on the server. After creating the creative, you can then review it using the creative’s previewUrl attribute or the newly added getPreviewUrl method. When updating custom creatives, you don’t need to pass the asset byte array each time. Instead, you can leave it null with assetId set to what it was assigned to when created. The full example can be found on the Java client library page, as well as in our other libraries .
As a final note, custom creatives can be used for many other purposes beyond the simple image ad above. Including a SWF file as an asset, for example, is a common way of creating flash banner ads. You can even include a Google+ +1 button and customize the +1’s destination URL with the DEST_URL macro.
We have a few more posts lined up for the Discover DFP API v201111 series , but if there’s any other topics you’d like to see, please let us know on the forum .
- Adam Rogal , DFP API Team