Google Publisher Tag Setup Guide and Mapping

This article describes how to set up the Google Publisher tag in your Tealium iQ Tag Management account.

The Google Publisher tag, primarily an ad tag, allows you to define ad slots and the criteria or audience you’d like to target through the ad. You may enable this tag to display a single ad or multiple ads by suitably configuring the tag.


  • DFP Account
  • Network Code
  • Ad unit
  • Ad slot creative size

Tag configuration

Navigate to the Tag Marketplace to add a new tag. Read the Tag Overview article for general instructions on how to add a tag.

When adding the tag, configure the following settings:

  • Title: Enter a descriptive title to identify the Tag instance. Or you can choose the default “Google Publisher Tag(GPT)”.
  • NC+TAU: Enter the Network Code (NC) and the Targeted Ad Unit (TAU) of the ad slot. These values are available in your DFP account.
    “<em>Example </em>:” /1234/travel/asia/food
    NC = 1234 and Targeted Ad Unit = /travel/asia/food
  • Enter the Width and Height of the ad slot.
  • Div ID: Enter the ID of the <div> container for the ad slot. The general format is “div-gpt-ad-#########-#”. For example:“div-gpt-ad-123456789-0”
  • Collapse Empty Div’s: Choose whether or not you want the slot to collapse in the event it is not filled by an ad. The default value is set to “Yes”. Toggling to “No” will display empty slots.
  • Library: Select where you want the gpt.js library code to load from:
    • Google (default): Loads the library code from Google’s servers.
    • Tealium (RECOMMENDED): Loads the library code via Tealium’s code on your webpage. This setting is recommended since it reduces the number of network requests leading to faster page load.

You have the option to configure these settings from the Mapping Toolbox.

Load rules

Load the tag on all pages or set conditions for when your tag will load. For more information about load rules, see the Load Rules documentation.

Best Practice: Load this Tag on any page that contains the target ad slot.

Data mappings

Mapping is the simple process of sending data from a data source, in your Data Layer, to the matching destination variable of the vendor Tag. The destination variables for this Tag are available in the Data Mapping toolbox.

For instructions on how to map to a Tag destination, see Mapping Data Sources.

Destination Name Destination Variable Description
Network Code networkcode This code is available in the Admin tab of your DFP account
Targeted Ad Unit adunit This is the target Ad Unit
Height height Height of the ad slot
Width weight Width of the ad slot
Set Slot-level Targeting setTargeting_slot Sets the “key:value” parameters for the target ad slot
Example: .setTargeting("interests", "sports");
Set Page-level targeting myvar Sets the “key:value” parameters of all ad slots on a page
NOTE: Replace “myvar” with your custom targeting parameter name.
Example: googletag.pubads().setTargeting("topic","sports");
Multiple Slot Configs gptSlots Define an array of slots for a single page (more details below)
NOTE: Make sure the data source being mapped from contains an array
Collapse Empty DIVs collapseEmptyDivs Collapses ad slots that do not get filled
NOTE: Make sure the data source value contains either “true” or “false”

Configuring the Tag for multiple ad slots

Adding and configuring the GPT for a single ad slot is very simple and straightforward. Employing the same process to configure multiple ad slots becomes tedious as you would have to to add an instance of GPT for all the ads you wish to display. The quick alternative is to store all slot configurations in an array then map the array to the ‘Multiple Slot Configs’ destination in the GPT instance. To create such an array, you can use the JavaScript Code Extension. Make sure to define the slot configs for every ad in this order:

Network Code + Targeted Ad Unit, Eligible Creative Size(s), Ad Container DIV ID, Slot-Level Targeting Name/Value Pairs

Using the JavaScript code extension

Write a JavaScript code that uses the ‘googletag.cmd.push’ function to define an array of slot configurations for all the ads you wish to display on a page.

  1. Navigate to the Extensions tab and add the “JavaScript Code Extension” from the Extensions marketplace.
  2. Scope the Extension to “Google Publisher Tag(GPT)”.
  3. Write the JavaScript code as you would in any editor. Do not include the <script> tags around the code.

Here’s a sample code for configuring 3 ad slots using a single GPT:

googletag.cmd.push(function() {
   googletag.defineSlot("/111/", [700, 200], "div-gpt-ad-987654321-0").addService(googletag.pubads()).setTargeting("slot_var", "tv");
   googletag.defineSlot("/222/", [250, 170], "div-gpt-ad-987654321-1").addService(googletag.pubads()).setTargeting("slot_var", "dvd player");
   googletag.defineSlot("/333/", [300, 100], "div-gpt-ad-987654321-2").addService(googletag.pubads()).setTargeting("slot_var", "smartphone");

You may choose to use the “u.gptSlots.push()” method instead of “googletag.cmd.push” and reference the NC+TAU value from a data source.
Example: u.gptSlots.push([b.GPT_SlotID, [[728, 90]], 'div-gpt-ad-987654321-0', {"place":"london","theme":"sports"}]);

Vendor documentation

Was this page helpful?

This page was last updated: April 7, 2016