Problem/Motivation
The ad slug (e.g. "Advertisement" / "Anzeige") is never shown reliably:
- 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. - The "Hide slug if no ad is served" option (
hide_slug) is enabled by default, and the template gates the slug onisSlugHidden == 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. - The
hide_slugcheckbox uses an unreliable#statescondition targeting a radios group.
Steps to reproduce
- Configure DFP with a network id and a global (or per-tag) slug, e.g. "Advertisement".
- Place a DFP ad block on a page.
- With default settings (
hide_slug = true) the slug never appears. - 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_slugis enabled, mark the slug withdata-dfp-slug-for="<slot element id>"and register a single GPTslotRenderEndedlistener in the head JavaScript, beforeenableServices(), that hides the matching slug for any slot that renders empty (event.isEmpty). This works independently ofcollapse_empty_divsand matches the option's label. - Remove the unreliable
#statescondition on thehide_slugcheckbox 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
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