Problem/Motivation

The ad slug (e.g. "Advertisement" / "Anzeige") is never shown reliably:

  1. The slug is rendered inside the same <div> that Google Publisher Tags (GPT) uses as the ad render target (tag.placeholderId). When an ad is served, GPT replaces that div's content with the ad iframe and wipes out the slug. As a result the slug only appears when no ad is served — the opposite of what is intended.
  2. The "Hide slug if no ad is served" option (hide_slug) is enabled by default, and the template gates the slug on isSlugHidden == false. So with the default configuration the slug is never rendered at all, regardless of the per-tag or global slug. There is no JavaScript implementing the documented "hide only if no ad is served" behaviour.
  3. The hide_slug checkbox uses an unreliable #states condition targeting a radios group.

Steps to reproduce

  1. Configure DFP with a network id and a global (or per-tag) slug, e.g. "Advertisement".
  2. Place a DFP ad block on a page.
  3. With default settings (hide_slug = true) the slug never appears.
  4. Set hide_slug = false: the slug only shows while the slot is empty and disappears as soon as an ad is served.

Proposed resolution

  • Render the slug in a sibling <div class="dfp-slug"> before the slot div, so GPT no longer overwrites it.
  • Always render the slug when configured. When hide_slug is enabled, mark the slug with data-dfp-slug-for="<slot element id>" and register a single GPT slotRenderEnded listener in the head JavaScript, before enableServices(), that hides the matching slug for any slot that renders empty (event.isEmpty). This works independently of collapse_empty_divs and matches the option's label.
  • Remove the unreliable #states condition on the hide_slug checkbox and add a description.
  • Update the slug display test accordingly.

Remaining tasks

Review the merge request.

User interface changes

The "Hide slug if no ad is served" checkbox is no longer conditionally hidden and gains a description.

API changes

None.

Data model changes

None.

Issue fork dfp-3611778

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

krisjahn created an issue.