Duplicate starting slash in front of network ID or wrong description leads to broken targeting

Created on 13 March 2024, 9 months ago

Problem/Motivation

On the global DFP settings page (/admin/structure/dfp/settings) the network ID has the following description:

The Network ID to use on all tags. According to Google this value should begin with a /.

So I understand you should enter a value like "/23456789" (with a leading slash).

Coming from Drupal 7 with this value, we were now wondering in Drupal 8, why the DFP debug console outputs all ads with a starting double-slash: "//23456789/ad..."

Which seems to break our targeting? Ads appear that should not appear with the targeting attributes set. These are all equal to Drupal 7 where it worked well!

Looking at the code, I think the reason is a wrong implementation or a wrong documentation!

Here's the current code from src/View/TagView.php:

 /**
   * Gets the ad unit.
   *
   * @return string
   *   The ad unit.
   */
  public function getAdUnit() {
    if (is_null($this->adUnit)) {
      $adunit = $this->tag->adunit();
      if (empty($adunit)) {
        $adunit = $this->globalSettings->get('adunit_pattern');
      }
      $this->adUnit = '/' . $this->globalSettings->get('network_id') . '/' . $this->token->replace($adunit, $this, ['clear' => TRUE]);
    }
    return $this->adUnit;
  }

Possibly related:
Also in this issue 🐛 Issue with targeting ads on specific pages Active I also found a strange token implementation (which might be the authors fault or also related:
"/[network:code]/[network:code]/GOW_300x100" that will also lead to a double-slash!
The author also reports issues with targeting.

Steps to reproduce

  1. Enter a network ID with starting "/" as documented
  2. Enable the DFP debug console and see "//..." which is definitely wrong

Proposed resolution

  • We need to fix the implementation or the documentation
  • We need a validation on the form to either ensure the leading slash is present (if we want it) or not to be present (if we don't want it) so there can be no confusion on this. Entering it wrong should lead to a form error.
  • Also this should be checked in an update hook to ensure the value is correct afterwards, also if it was entered wrong before.

Remaining tasks

Define if the value should be entered with or without leading slash ("/")
Fix the issue as described above
Write tests to ensure this doesn't happen again

User interface changes

API changes

None

Data model changes

None

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024