Closed (fixed)
Project:
Doubleclick for Publishers (DFP)
Version:
3.0.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Jun 2021 at 09:19 UTC
Updated:
11 Nov 2025 at 15:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dinesh18 commentedComment #3
vladimirausReviewing
Comment #4
dinesh18 commentedI didn't see we are invoking any hooks.
\Drupal::moduleHandler()->invokeAll().Checked for this, didn't get anything. I see one file called dfp.api.php , seems to be incomplete.Comment #5
dinesh18 commentedCreated the set methods in src/Entity/Tag.php and added the alter method in TagBlock.php
Comment #6
dinesh18 commentedFixed PHPCS errors
Comment #7
dinesh18 commentedFixed PHPLINT issue. Fix for hook_dfp_tag_alter(&$tag)
Comment #8
dinesh18 commentedComment #9
pareshpatel commentedComment #10
pareshpatel commentedComment #11
vipul tulse commentedComment #12
vipul tulse commentedHello Dinesh,
#7 Patch applied successfully.
After adding the hook_dfp_tag_alter function the ads size altered
/**
* Implements hook_dfp_tag_alter().
*/
function hook_dfp_tag_alter(&$tag) {
if($tag->id() == 'imu') {
$tag->setSize("300x600,300x250");
}
}
Please check the attachments Before and After how it changed after hook dfp tag alter
Comment #13
vladimirausHooks
hook_dfp_tag_load_alter&hook_dfp_tag_alterare not defined indfp.api.php.If you are adding new hooks, please update
dfp.api.phpAlso, what is the purpose of newly added functions in the patch?
Comment #14
grevil commentedComment #15
grevil commentedComment #16
grevil commentedI don't think hook_dfp_tag_load_alter(), makes sense in D10.
Comment #17
grevil commentedComment #19
grevil commentedDone. Please review the provided MR!
Comment #20
anybodyThanks @Grevil! Looks and works great!
I also can't see a good use case for
hook_dfp_tag_load_alter()now using config entities. So if anyone needs it, we should solve that as separate follow-up.Comment #21
grevil commentedCurrent MR as a static patch until it is merged.
Comment #22
anybodyJust found an issue with this implementation: #3427684: Tag altering is not represented in caching (= wrong ads targeting shown)
While it's super important to have the flexibility this hook provides, it doesn't care for caching.
I'm not even sure if the issue described doesn't also happen in other cases already, but at least for this MR the differences in targeting for the same tag need to be taken into account!
We may decide to merge that other issue in here and fix it here. But first we need to find a correct solution.
Any ideas everyone here?
Comment #23
grevil commentedI added a test trying to replicate the caching issue, but everything seems fine, maybe checking the response isn't the correct approach.
FYI: The ci-pipeline is a complete mess in dev. The pipeline errors are unrelated, the added test succeeds.
Comment #24
grevil commentedYea, I don't know LGTM 🤔

See https://developers.google.com/publisher-tag/reference#googletag.PubAdsSe....
UPDATE: Seems I misunderstood the issue. Adjusting the tests accordingly.
Comment #25
grevil commentedNice, now we have a failing test reproducing this issue!
Comment #26
grevil commentedOk just found this: https://www.drupal.org/docs/drupal-apis/cache-api/cache-max-age#s-what:
Comment #28
grevil commented@Anybody and I took a deeper look into this whole endeavour. The problem to begin with was, that "TagViewBuilder" did not add cache keys based on the dfp tag targeting (as this wasn't necessary before). Even after adding them, the caching wasn't fixed.
Then we found out, that the TagBlock "build()" wasn't executed again after reloading the page.
Turns out, the caching logic on the block hindered us to even reach the TagViewBuilder "build()" method, as the caching keys set in the TagViewBuilder do not bubble up to the block (caching keys do not bubble up in general, where as cache context does). We tried to simply add caching keys to "TagBlock" build(), but this only added cache keys to the block content, not to the block itself. We then tried to implement "hook_block_build_BASE_BLOCK_ID_alter" to add the proper caching keys to the block (see here).
This worked perfectly, but unfortunately the hook fires before the content gets passed to the block, meaning we do not have any information about the dfp tag in the alter hook.
Now in the final approach, we simply set the block cache max age to "0", IF the alter hook is implemented. Otherwise, the original max age is used. This way (if the alter hook is implemented) we delegate the block level caching (TagBlock) to the content level caching (TagViewBuilder).
Both @Anybody and I feel like this is the best approach, (since the approach through "hook_block_build_BASE_BLOCK_ID_alter" isn't working).
Another approach would be, to simply create a new "dfp_tag_targeting" cache CONTEXT, as cache contexts simply bubble up compared to cache KEYS. But a cache context for this specific scenario seems like the incorrect approach:
(https://www.drupal.org/docs/drupal-apis/cache-api/cache-contexts)
Dynamic tag targeting through the hook implementation doesn't have much to do with "REQUEST context dependencies". As it has nothing to do with the request itself (unlike other core contexts like "theme","cookies","language", etc.) and there can be multiple seemingly identical blocks with different tag targeting in one request. Maybe this is an edge case, where it is fine to create a dedicated cache context, even if it isn't linked to a "Vary header" (request cache context), but this isn't documented anywhere, whether there are edge cases like this.
Comment #29
grevil commentedPlease review.
EDIT: The newly added tests succeed.
Comment #30
anybodyWhao that was pain... but with happy end! :)
Thank you for the great investigations we had together @grevil! So I can happily confirm this is RTBC!
This is tested, tests fail without the cache fixes and so we can be sure it works as expected.
If we'll ever come to a better solution, which I currently can't see by hard, we can do that.
Other failing tests / broken pipeline is unrelated, as written above.
Comment #32
anybodyStatic patch attached, until this is merged!
Comment #33
vladimirausSwitching to 3.0.x
Comment #34
vladimirausNeed to retest in v3.
Comment #35
anybodyThanks @vladimiraus - @grevil could you have a final look in the next weeks please?
Comment #36
grevil commentedSeems to work great on v3! I fixed the remaining cspell issues and now the pipeline also succeeds again! 🙂👍
Comment #37
anybodyConfirming RTBC! 🚀
Comment #38
anybody@vladimiraus any chance to finally merge this into 3.0.x and tag a new release with this? Would be fabulous 🎉
Comment #39
anybodyLatest state of MR39 attached until this is merged. Would be great to have this fixed.
Can once again confirm this still works perfectly in our projects and is definitely needed.
Comment #40
anybodyComment #41
vladimirausComment #43
anybodyThank you @vladimiraus!! Great to have the hook back now!!