What Is an Ad Tag?

An ad tag is a snippet of HTML or JavaScript code on a web page, or a URL in a video player, that calls an ad server to fetch an ad for one placement. The server chooses the ad and returns it to the page, and the request itself lets the server count the impression.

Read the guideTalk to an expert

What happens when an ad tag loads

Every ad tag turns an empty slot into a request an ad server can answer:

  1. The browser reads the tag. The publisher's snippet retrieves an ad from the ad server.
  2. The tag builds a request. It packages the slot's ad unit code, ad size and any custom targeting.
  3. The ad server picks an ad. It serves the appropriate advertisement and measures what it served. When programmatic demand competes, the server may also send a bid request to buyers.
  4. The ad renders. The tag places the creative in the container reserved for it.

Each served ad counts as an ad impression. A slot the tag never calls stays empty, and that ad inventory goes unsold.

Anatomy of a Google Publisher Tag, line by line

The Google Publisher Tag (GPT) is the ad tagging library for Google Ad Manager. Google's sample tag for one banner, trimmed:

<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js" crossorigin="anonymous"></script>
<script>
 window.googletag = window.googletag || { cmd: [] };
 googletag.cmd.push(() => {
 googletag.defineSlot("/6355419/Travel/Europe/France/Paris", [300, 250], "banner-ad")
.addService(googletag.pubads());
 googletag.enableServices();
 });
</script>
<div id="banner-ad" style="width: 300px; height: 250px"></div>
<script>googletag.cmd.push(() => { googletag.display("banner-ad"); });</script>

What each part does:

  1. async src=".../gpt.js" loads the library in parallel with the rest of the page, so the page keeps rendering.
  2. window.googletag =... creates the googletag object and its command queue.
  3. cmd.push(...) queues the setup to run once the library has loaded.
  4. defineSlot(path, size, id) names the slot: /6355419 is the publisher's network code, /Travel/Europe/France/Paris the ad unit path, [300, 250] the size in pixels and "banner-ad" the element that holds the ad.
  5. addService(googletag.pubads()) attaches the slot to the publisher ads service.
  6. enableServices() switches the ad services on.
  7. <div id="banner-ad"> is the container; its ID and size must match the slot.
  8. display("banner-ad") sends the request and renders the ad in that container.

Reading a VAST video ad tag URL

A video player calls a tag URL and receives an XML response in VAST, the IAB Tech Lab's universal schema for serving ads to digital video players, whose newest core version is 4.3 (2022). In Google Ad Manager the URL starts with https://pubads.g.doubleclick.net/gampad/ads? and carries the slot as parameters:

Parameter Example What it tells the ad server
iu iu=/6062/videodemo The ad unit
sz sz=400x300 The video slot size
env env=vp The request comes from a video player
output output=xml_vast4 Return the ad as VAST 4
unviewed_position_start unviewed_position_start=1 The impression may be delayed
url url=https%3A%2F%2Fwww.example.com%2Fvideo.html The page the request came from
description_url description_url=...golf.html A page describing the video

The url parameter is required for programmatic monetization and description_url for Ad Exchange or AdSense demand, so a stripped-down video tag quietly loses paying buyers. See in-stream video for formats.

Ad tags, tracking pixels and the rest of the tag stack

"Tag" covers several kinds of page code, and searchers often mix them up. An ad tag requests and delivers an ad. A tracking pixel reports what a shopper did afterward, such as a purchase, back to an ad platform. Both often sit on the same site.

Advertisers have tags too. A third-party ad server such as Campaign Manager 360 issues placement tags, which call URLs on the doubleclick domain. The publisher traffics that placement tag as the creative: the publisher's tag calls the publisher's ad server, which returns the advertiser's tag, which serves and counts the advertiser's creative in the advertiser's own system. For measurement that leaves the browser entirely, see server-side tracking.

Where ad tags sit in retail media campaigns

Sponsored product ads on a retailer's own site and app are built in the network's console, and the retailer serves them inside its own pages. Offsite campaigns work like the rest of programmatic: a brand uses a retailer's audiences to buy display or video on other sites. There, a publisher's tag retrieves the ad from an ad server.

That offsite path runs through a demand-side platform on the buy side and a supply-side platform on the publisher side, as laid out in onsite vs offsite advertising. For a brand, a broken tag on a publisher page shows up as lost offsite delivery. Each network's formats are profiled on the retail media networks hub.

When an ad tag fails to fire

If a tag doesn't fire, it can't track or return creative content as intended. The common faults follow from the anatomy above:

  • Mismatched IDs. The slot's element ID differs from the <div> ID, so the ad has nowhere to render.
  • Edited tags. Someone trimmed or retyped the code; compare the implemented tag against the tag as it exports.
  • Blocking scripts. A library loaded without async holds up the page until it finishes loading.
  • Missing parameters. A video tag without url or description_url cuts out programmatic buyers.

Chrome Developer Tools shows each case: the Elements tab for the container, and the Network and Console tabs for the request and any errors it threw. Recheck the live page after every template change.

Frequently asked questions

What is an HTML ad tag?

An HTML ad tag is the block of HTML and JavaScript a publisher places where an ad should appear. It loads an ad library, defines the slot's ad unit and size, and reserves a <div> container. On page load, the returned ad renders in that container.

What does an asynchronous ad tag do?

An asynchronous ad tag loads its library in parallel with the page. With the async keyword on its script, the browser keeps rendering content while the ad library downloads, and queued commands run once it is ready. A slow ad server then delays only the ad.

Is an ad tag the same as a tracking pixel?

No. An ad tag asks an ad server for an ad and displays it in a slot. A tracking pixel reports an event, such as a page view or purchase, back to an ad platform for measurement and audience building. People group both as advertising tags.

Who creates the ad tag, the publisher or the advertiser?

The publisher's ad server generates the tag that sits in the page and defines the slot. An advertiser with its own ad server issues a placement tag, which the publisher traffics as the creative. That tag returns the advertiser's creative and tracks delivery in the advertiser's own system.

What is a VAST tag?

A VAST tag is the video version of an ad tag: a URL that a video player calls to request an ad. The ad server replies with XML in the IAB Tech Lab's VAST format, which describes how the player should handle the ad.

How RMIQ helps

How RMIQ can help with ad tags

An ad tag decides whether an offsite placement turns into a served impression, so it sits under every display and video campaign a brand buys beyond the retailer's own site. RMIQ works on the part a brand controls: which products, keywords and budgets go into each network's campaigns.

  • Bids set per product

    The Network Optimization Agent recommends SKU-level keywords and bids for each network, so every placement you pay for carries the right product.

  • Spend follows delivery

    The Budget Allocation Agent recommends budget adjustments from campaign performance, and our experts move spend toward the placements that deliver.

  • One view of every network

    The Cross-Network Learning Agent surfaces insights and growth opportunities across Walmart, Instacart, Amazon and Target, and our experts handle the rest.

AI agents surface the opportunities. Our experts handle the rest.

Partners

Our current partners

We are already helping leading retailers and platforms grow their retail media businesses, including:

Become a partner

Contact RMIQ

Talk to a retail media expert

Book 30 minutes with Petr, or send the team a message. A person on the team reads both.

Petr Misek

Book a call with Petr

Petr Misek, Retail Media Expert

Bring the brands you sell and the networks you buy on. Petr will show you where RMIQ fits and what it would change.

Petr MisekJim GraceJacek Chodźko

Send us a message

Petr, Jim or Jacek will reply

Pricing, partnerships, press, or a question that doesn't need a call.