building an ad platform with dfp

Targeting Ads

One of the most powerful aspects of DFP is its ability to "target" ads at certain groups of people. For example, if you're running a hyperlocal news site, you might want to display ads for local businesses only to visitors coming from your region - why waste all those impressions by putting them in front of people that will never become customers of those businesses? Or you might want to show a beer and pizza deal only to students from local universities and campuses.

Similarly, you might have high-bandwidth, rich-media ads that should only be shown to visitors coming in with a broadband connection. You might want to prevent Internet Explorer users from seeing ads crafted in HTML5. If you want to get really fancy about it, you might want to make sure certain ads are only shown to male or to female visitors. All of this is possible with DFP's ad targeting system.

Targeting parameters are attached to Line Items, and can be set either while placing ad ad or added on later. Let's return to one of the line items we've already created and set some targeting criteria. Click on Orders, then My Orders. Click on an order name, then click one of the line items within it. Finally, click the Settings tab within that Line Item.

At the bottom of the Settings panel, you'll find an Add Targeting section.

Along the left side of the Target section, you'll see a list of targeting categories: Inventory, Custom, Geography, Browsing, and User Domains. The box on the left lets you sort and filter for various criteria, and provides small "add" links.

Clicking on one of these links causes that criteria to appear as a list in the box on the right.

This is your list of final serving criteria for the line item. Click the small "x" to remove a criterion from the list.

In most cases, you'll want to start with the Inventory selector, and define an Ad Unit in which the Line Item should run (otherwise it is possible the item could appear in other ad units on your site for which its eligible for other reasons.)

Let's skip Custom Criteria for now, and move on to Geography. Try typing in a zip code or city name, then click Find. DFP will locate the region on Google Maps and let you check one or more boxes to select an area. Click the "add" link and that regional criteria will appear in the right-hand Selected Criteria box.

Note also the "Matches" drop-down near the top. This is present in all of the selectors, and can be changed to "Does not match." If you want to serve one ad in a line item to users in your geographical area and another to everyone else, just create two line items, then use the Matches / Does Not Match picker to select which ads are shown to whom.

The Browsing selector works similarly, but lets you precisely target your ads to particular web browsers, such as Firefox, Internet Explorer, Safari or Chrome. You can even drill down to specific browser versions if you happen to use an ad technology that doesn't work in certain browsers (Internet Explorer 6 is particularly problematic for modern web technologies, for example).

The User Domains selector works exactly as advertised - it lets you target ads to users visiting from specific domains. This is particularly useful for targeting university students (just enter "berkeley.edu" for example).

Click Save, wait a while, and your targeting will kick in. If you want to test targeting for yourself, a good way is to target one line item at Firefox users and another at all other browsers. Then try visiting your pages with Firefox and with another browser - you should see different ads.

Custom Criteria

Web browsers don't know the gender or age of users, but if a user is currently logged into your site, your CMS may well know these things. By passing this value to DFP through a semi-hidden parameter, DFP can become aware of any sort of custom criteria you define. Let's try a simple gender matching key.

Before you can use custom criteria, you'll need to define them. Leave the Line Item settings and go to the DFP Inventory tab, then click Custom Criteria.

Click "New Key" and enter the name "Gender." Select "Users will select from predefined targeting values." Enter the words "male" and "female" into the values field (one per line) and click Save.

Now the question is how to pass gender information to DFP in a format it can recognize. This is done by adding a small bit of Javascript to the page.

But since this has to happen in real time on a per-visitor basis, you'll need to program your content management system to write this bit of Javascript for you - your web developer will know how to do this. This line should be inserted before any ad slots are defined in the page.

See DFP's FAQs Define custom criteria and Pass custom targeting criteria into ad tags for more info.

Once your custom criteria have been defined, return to the Line Item settings, choose Custom Criteria, and select your custom key from the list.