Search Images Maps Play YouTube News Gmail Drive More »
Sign in

Inventory and tagging

Generate a mobile ad tag in DFP

The DFP Small Business tag generator can automatically generate the HTML and JavaScript necessary to integrate one or more ad units on a page or application. Using the ad tag generator is optional, but generally easier and less error prone than manually rewriting code.

A mobile ad tag contains all the information required for a mobile ad request that you can insert onto your webpage or application.

  1. On the Inventory tab, click Generate tags in the side panel, or navigate down to the Settings tab of an ad unit and click Generate tags under the ad unit name at the top of the display.

  2. From the Target Platform drop down, select Mobile.

  3. Select ad units for which you want to generate ad tags by clicking include next to each one.

  4. Click Generate tags.

  5. Copy and paste the snippets from the resulting dialog.

    • Application ad units: Copy the ad unit ID and ad unit size into your application code.

    • Site ad units: Copy the header and document body code snippets into the <head> and <body> sections of your webpage, respectively.

Additional tagging guidelines

  • You can use the same ad unit multiple times on the same page, as long as you generate multiple tags, with different div IDs. You can't copy the same tagging snippet into the same page multiple times.

  • If you want to use iframe tags, please contact support.

  • The best way to debug a mobile tag is to use a developer tool like Firebug (in Firefox) to see if the ad slots are getting properly filled with creatives.

Generate tags for multiple ad units using individual tag generation dialog box

When generating tags using the individual tag generation dialog box (located on the ad unit page instead of the left side panel), you can copy and paste these units together to target multiple ad units on the same page.

Sample tag for ad unit 1

 

Sample tag for ad unit 2

 

Final tag: Paste a portion of tag 2 (highlighted) into tag 1

 
Add custom targeting to a mobile ad tag (application)

For information about custom targeting, refer to our documentation for Android and for iOS.

Add custom targeting to a mobile ad tag (website)

After you've defined the custom criteria in your network, you can target line items to key-values. You have to specify key-values in your ad tags if you want them available for targeting.

There are two ways to include custom key-values in your ad tags:

  • Hard-code the key-value in the ad tags so that the tag always includes that key-value. In this case, the tags are static and don't change dynamically.

  • Pass the key-values dynamically to the ad tags. Let's say that you maintain registration data for your users, so that when they sign up to use your site they provide you with their age and gender. Your webmaster can set it up so that when a user is signed in to your website, the information about their age and gender is passed dynamically to the ad tags, and then any line items that are targeted to their age or gender will serve to them.

Here are examples of how to hard-code 'Gender=Female' and 'Age=25' into your ad tag:

googletag.pubads().setTargeting('Gender','Female');
googletag.pubads().setTargeting('Age','25');

All values must be passed as a string in the tag even if they're defined as integers in the UI. For example, '25' in the tag vs. 25 in the UI.

To define custom targeting for multiple ad units, declare a variable for each ad unit and assign custom targeting that is specific to that ad unit.

For example, to target ads to two ad units (sizes 300x50 and 250x250), define ad units and their properties as follows:

Make sure that custom targeting is defined before the line that says 'googletag.enableServices();'.

Add AdSense settings to a mobile ad tag

Here's an example of how to specify AdSense channel IDs in your mobile ad tag:

googletag.pubads().set("adsense_channel_ids", "27182820");