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

The Google Publisher Tag

Set targeting and sizes with GPT


Specifying an ad unit in GPT

For each ad slot, you can specify an ad unit so that line items targeted to that ad unit--or to placements containing that ad unit--will be eligible to serve to that tag. You can see examples of this here.


Passing custom (key-value) targeting with GPT

You can use key-values to target ads more granularly than ad units. Learn more about key/value targeting here.

For each ad call, you can use the setTargeting() function to pass one or more keys, each with one or more values. You can see examples of this here.

For each ad call, you can either use slot-level or page-level customized targeting parameters based on your network’s needs, as below:

  • Slot-level customized targeting: You can set custom targeting attributes for individual ad slots on your page. Use .setTargeting to utilize slot-level targeting, as in the examples here.

    Typically, we recommend using slot-level implementation for customized targeting, as it covers all targeting scenarios (both when the custom targeting is the same throughout the page, and when it varies by individual slots).

  • Page-level customized targeting: You can use this to set custom attributes across all ad slots on your page. Use googletag.pubads().setTargeting to utilize page-level targeting, as in the examples here.

    Page-level targeting allows clients to use less code in their tags and ensures that all ad slots have the same set of custom targeting attributes. For example, clients could set the key-value pair gender=m on all ad slots using page-level customized targeting.

Passing custom targeting into a tag allows line items targeted to that key/value pair to serve to that tag. If, for instance, you pass the custom key-value gender=male-- written as .setTargeting('gender', 'male'); -- into a tag, line items targeted to gender=male will be eligible to serve, assuming all other criteria matches.

There’s no limit to the number of key-values you can include, though the request URL has an overall limit of 2,000 characters.

Rules and limitations around key-values in GPT ad tags

Keep the following guidelines in mind when inserting key-values into GPT ad tags:

  • The key must not begin with a number.

  • The values of key-values cannot contain any of the following special characters: # " " , * . ( ) = + < > [ ]

  • Unsafe characters must be escaped in GPT ad tags. Learn how to escape unsafe characters.

  • Spaces are allowed in key-values. For example: .setTargeting('region',['middle east','southeast asia']);

  • There's no limit to the number of key-values you can include in an ad tag.

Characters can be unsafe for a number of reasons, some of which are mentioned below:

  • The characters ? : @ have a special purpose in HTTP URLs and will break the ad request if you include them in custom targeting

  • The characters ; / and & are reserved for special meanings within DFP ad tags and can be used only for those purposes.

  • A quotation mark (") is used to delimit URLs.

  • The character # is used to delimit a URL from a fragment/anchor identifier that might follow it.

  • The character % is used for encodings of other characters.

  • Other characters such as { } | ^ ~ [ ] and \ are unsafe because when they are sent in URLs via the web, gateways and other transport agents sometimes modify such characters.

  • The value of a key-value cannot be empty (for example, cat= or cat=" " or cat=' '). However, where there are instances where the value is intentionally blank, populate the value with null or some other value indicating a blank (for example, cat=null).

  • Key-values are not case sensitive: there is no distinction between words entered in lowercase and uppercase.


Define ad sizes in Google Publisher Tags

You must specify in your tags which creative sizes can serve to each ad slot. For single-size ad slots, you also have the option of defining the size of the <div> element where the creative will render; this prevents other elements on your page from shifting if the creative renders asynchronously, after elements following the <div> element have loaded. If you don't specify a size in the <div> tag in sychronous mode, then the slot will expand or contract automatically based on the size of the creative and the page layout will be shifted to make room.

Specifying creative size in your ad tags

Specify creative sizes in the googletag.defineSlot() function. To allow multiple sizes to serve to the ad slot, you can use a comma-separated list. You can see examples of this here. There’s no limit to the number of sizes you can include, though the request URL has an overall limit of 2,000 characters.

Define <div> size to prevent elements from shifting when a creative renders

To define sizes, you should use the "style" attribute in the <div> elements that will hold the ads. You can see examples of this here.

We recommend that this only be used for single-size ad requests. If you’re creating a multi-size ad request, you should set the height to the tallest creative and width to the widest creative in order to avoid creatives being inadvertently cropped.

Define an out-of-page slot

To specify an out-of-page ad slot, check the Out-of-page unit checkbox in the 'Generate tags' window.