Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
To serve pop-up, pop-under, or floating creatives to your website, we need to traffic the creatives using one of DFP’s built-in creative templates, and make sure the tags are set up properly to allow these creative types to serve.
More info
See https://support.google.com/dfp_premium/answer/1154352?hl=en-GB
and https://support.google.com/dfp_premium/answer/1650154?hl=en
Click on: Method details > Method details for googletag
Here is an example of the usage
<script type="text/javascript">
<!--//--><![CDATA[//><!--
googletag.defineOutOfPageSlot("/999/site.com", dfp-ad-leaderboard_oop")
.addService(googletag.pubads());
//--><!]]>
</script>
Proposed solution
- Add a new setting for "Out of page (interstitial) ad slot" on DFP Ad Tags edit page.
- Use the setting to output the relevant call on the javascript.
Comment | File | Size | Author |
---|---|---|---|
#56 | 2038965-out_of_page_slot-56.patch | 6.41 KB | marcelovani |
#47 | 2038965-out_of_page_slot-47.patch | 12.13 KB | extremal |
#44 | 2038965-out_of_page_slot-44.patch | 11.99 KB | extremal |
#42 | 2038965-out_of_page_slot-42.patch | 10.21 KB | Miszel |
#39 | 2038965-out_of_page_slot-39.patch | 11.98 KB | marcelovani |
Comments
Comment #1
marcelovaniI have created the patch that adds the extra settings when editing ad slots.
Comment #3
marcelovaniComment #5
marcelovaniComment #6
marcelovaniComment #8
marcelovaniComment #9
marcelovaniComment #11
marcelovaniComment #12
bleen CreditAttribution: bleen commentedCan there be more than one of these declared on a page. It would be weird to create a block for this, but if we dont how do we get the correct slot defined on the page. ... I just want to think this workflow through a bit.
minor note:
coding standard: else should be on a new line
Comment #13
marcelovaniHi Bleen18. Thanks for pointing out the coding standard.
Regarding the logic, I thought the same, but the patch would be a lot more complex if we wanted to create a new setting just to store the Out of page slot.
Would it be incorrect to have more than one Out of page placement?
We are currently using this patch on this website http://www.denofgeek.com/
Comment #14
bleen CreditAttribution: bleen commentedThats actually my question ... would it?
Comment #15
johnish CreditAttribution: johnish commentedThe site I work on now has 2 out of page slots, one is an interstitial and the other is wallpaper. The wallpaper is also called rails or gutters. This is how the site was doing it and how the company 'Outsourced Ad Ops' recommend we do it.
Therefore to be flexible I believe this should allow for multiple out of page slots.
Comment #16
johnish CreditAttribution: johnish commented#13: 2038965-out_of_page_slot-6.patch queued for re-testing.
Comment #17
bleen CreditAttribution: bleen commented'#default_value' => $tag->settings['out_of_page'],
needs to be
'#default_value' => isset($tag->settings['out_of_page']) ? $tag->settings['out_of_page'] : 0,
Otherwise existing ads will throw an error when you try to edit them.
Also, when testing, I created an ad that had "out of page" checked and used admin/structure/block to add it to the page. The problem here is that all the normal block markup is added. With a vanilla install of D7 this means you can get this:
This needs to be handled more cleanly...
Comment #18
davidgrayston CreditAttribution: davidgrayston commentedUpdated patch with correct function name (googletag.defineOutOfPageSlot)
Comment #19
davidgrayston CreditAttribution: davidgrayston commentedUpdated patch with correct function name (googletag.defineOutOfPageSlot)
Comment #20
marcelovaniThanks David, I am also adding the logic on #17
Comment #21
bleen CreditAttribution: bleen commentedmarcelovani ... I do not see the logic to deal with #17 in the patch you have in #20. Am I missing something?
Comment #22
marcelovaniHi Bleen18, I added this bit as you suggested
'#default_value' => isset($tag->settings['out_of_page']) ? $tag->settings['out_of_page'] : 0
Regarding the block appearing in the sidebar, in our case we positioned the block in a 'pre_page' region and used CSS to make it not visible.
If you look at http://www.mensfitness.co.uk/ you will see the markup. As soon as you open the site, the popup should show.
What do you think if we added some CSS to target the Out of page blocks?
Comment #23
bleen CreditAttribution: bleen commentedThats considered bad practice. We should really handle this in the hook_block_view() somehow. We might need to render the tag using a different template or something - I havent thought it through very much - but we should not be outputting any markup that later needs to be hidden with CSS.
Alternatively we can rethink how these ads are placed somehow and not use the block system at all, but use hook_page_alter (or something) but then you loose the benefits of using context to decide which page(s) these are displayed on. Hmmmm.
Thoughst?
Comment #24
marcelovaniHum, I have seen people using something like this
<div id='block-dfp-out_of_page' style='height:0;'>
We could add this to every page, maybe at the bottom, so don't need to worry about placing it using context.
I believe the Ads can be targeted to certain keyworks or pages, so it would be possible to choose which pages would show the ads.
Or, we could create a context plugin specifically for the Out of page slot.
Setting the height to 0 will make sure we don't see anything when the iframe is appended into the wrapper.
What do you reckon?
Comment #25
bleen CreditAttribution: bleen commentedMy problem with this is that google charges sites based on the number of calls, even if no ad is returned. Adding this to every page would increase everyone's bill.
I think the correct solution would be to define a theme function that used a template with nothing in it except
print $block->content
and then when we define blocks in hook info we check for your new property and switch what theme function is used for these blocks. How bout that?Comment #26
girishmuraly CreditAttribution: girishmuraly commentedNot really sure about the new block template suggestion mechanism as it sounds like deviating from the normal block themeing and bit hacky? Also we need to ensure block caching and other components are unaffected.
@marcelovani and I have been discussing an idea to ditch the block system for out-of-page ad slots and instead place the required iframe via javascript. Dfp configuration could ask for paths to place the ad slot on which the JS should use, as a start. Later we could reuse the same to make a Context plugin. Would you see this working?
Comment #27
bleen CreditAttribution: bleen commentedDeviating from the normal block theming is exactly what is called for here... That's the point. These ads shouldn't have a div around them. They should nave no physical presence on the page. A different block theme would not effect block caching and it would still allow for the use of the context module or panels to decide under what conditions these ad tags should be present on the page (e.g. Only show this out of page tag on Tuesdays)
Placing via js sounds like an interesting idea but again I'm concerned about context integration ... Definitely be willing to consider this route though
Comment #28
marcelovaniI have a possible solution here that seems to work, on hook_block_view() I check if the Ad slot is out_of_page, then change the class and add CSS (If we don't specify the height, the block will pick up the defaults the computed height will be 21px).
Then on hook_preprocess_block() I check if the block has the dfp-tag-out-of-page-wrapper class and override the block classes.
I found that when placing the block using the core block system, the array of elements will add an extra index i.e.
Placing the blocks using Drupal's built in:
Placing the blocks using Context:
Thoughts?
Comment #29
bleen CreditAttribution: bleen commentedUltimately this has the same flaw ... We are adding a bunch of stuff in one place just to remove it later.
Can you clarify your reasoning for not simply adding a new block theme function or tpl? I'm open to other ideas but I don't see why adding a new block theme function wouldn't work....
Comment #30
johnish CreditAttribution: johnish commentedI took patch .20 and updated it for DFP 7.x-1.1 code
Comment #31
johnish CreditAttribution: johnish commentedI guess i'm going to need some help; never submitted a patch before. I put the define slot in an array as I was having the issue where the machine name was a number or starting with a number and that was causing all sorts of issues. This is https://drupal.org/node/2078187 JS error when Ad Slot machine name starts with an integer.
Comment #32
samueldarwin CreditAttribution: samueldarwin commentedwe are using the production DFP module.
in the meantime, in the very very short term...
is there a simple explanation for what manual steps might be used to implement defineOutOfPageSlot , until such time as this patch is released into production?
can the DFP module still be used?
thanks.
Comment #33
marcelovani@samueldarwin
Comment #34
marcelovaniUpdating patch that applies to the current 7.x dev or 1.1 tag
Comment #35
Bogdan1988 CreditAttribution: Bogdan1988 commentedHi. When we check "Render ads asynchronously" in general dfp settings, outofpage tags become invisible. Also we get this js error - Uncaught ReferenceError: jQuery is not defined, while trying to access outofpage tags in async mode. How can I make jQuery loads before outofpage tags? I have tried to make jquery_update module weight equal to -10, but it gives nothing. Thank you!
Comment #36
Bogdan1988 CreditAttribution: Bogdan1988 commentedComment #37
marcelovaniAre you using aggregation?
Have you tried to clear all cache?
Comment #38
Bogdan1988 CreditAttribution: Bogdan1988 commentedYes I have turned on and off agregation, also I had cleared caches. One thing that I miss is that I didn't put any div for outofpage inside body tag. I just put it as a block. If it is my mistake, could you please explain how can I do this, thanks!
Comment #39
marcelovaniI have worked on a new solution that will allow the Out of page markup to be added to the page, not as a block.
It works with Context module by providing a reaction for DFP Out of page.
If Context is not present, when creating/editing an Out of page tag, there will be a box where you can setup the visibility pages.
I am attaching the patch and screenshots.
The code is experimental, it needs reviewing, and maybe some tweaks.
Comment #40
Bogdan1988 CreditAttribution: Bogdan1988 commentedThank you, marcelovani. I will test this code and will tell you result. Thank you!
Comment #41
Bogdan1988 CreditAttribution: Bogdan1988 commentedThank you, marcelovani. This code works nice, and in synchronous ads rendering it seems to work much faster then block implementation. But my problem with async is still there, possibly it is an error on ads end, not in drupal. Thank you!
Comment #42
Miszel CreditAttribution: Miszel commentedA couple of things:
* line 923:
We cannot assume that page_top will always exists.
* line 951:
$visible = !($tag->out_of_page_visibility xor $page_match);
should be:
$visible = !($tag->settings['out_of_page_visibility'] xor $page_match);
Comment #43
marcelovaniThanks Marcin.
@Bogdan I don't know the answer for that problem, could be DFP module, but I think it's not related to this patch. Maybe you could open a new issue
Comment #44
extremal CreditAttribution: extremal commentedPatch in #42 is missing the dfp_context_reaction_outofpage.inc file.
Re-rolling.
Comment #45
Bogdan1988 CreditAttribution: Bogdan1988 commentedThank you @Marcelo, I think the main problem in my case is that jQuery is loaded after gpt.js. I will try to find problem and then report here, thx!
Comment #46
marcelovani@extremal we need the markup to be outputed on the footer instead of page top, since not all the themes add this region by default.
Comment #47
extremal CreditAttribution: extremal commentedThanks @marcelovani . Added these changes into the patch.
Also changed line 919:
$html .= render(dfp_tag($machinename));
to
So php 5.5 will not complain about passing variables by reference
Comment #48
davidgrayston CreditAttribution: davidgrayston commentedThis is working as expected
Comment #50
marcelovaniNo idea why it's trying to test patch #30
Comment #51
marcelovaniComment #52
bleen CreditAttribution: bleen commentedThis makes me cringe ... cant we just take advantage of the "element-hidden" class instead?
There needs to be some messaging added here if $options is empty
Why bother having this at all? Why not just show a checkbox for all tags on the context reaction form?
This is an API change I'm not comfortable with. I'd be ok with adding a note to the description that says "use 0x0 for out of page ads" or something like that
First, what is this? What does this have to do with "out of page" ads? If I understand this correctly, everything that is here can be accomplished with the "Context" module. Why do we need code to handle visibility?
nit: new line at EOF
I suspect that based on my other comments at least 90% of this function can be removed
Based on my other comments, this function should be unneeded
Comment #53
marcelovaniHi, thanks for reviewing
1 and 2: We could try it.
3: I just thought would be nice to display only options that were relevant for the type of Ad slot selected.
4: Agree with 0x0.
5: We can remove it if you think it's not important, the ide was to provide functionality for people that don't user Context.
Comment #54
bleen CreditAttribution: bleen commentedCool
We are just adding complexity in the name of simplicity. I think the simplicity is minimal but the complexity is a lot of code to baby-sit
Cool
I dont want to babysit that code either if there is a good solution already
Comment #55
marcelovaniSimplified patchWrong file, uploading again...
Comment #56
marcelovaniThis is the correct attachment
Comment #57
marcelovaniComment #58
marcelovaniI missed one bit on the previous patch. Interstitial slots are not displayed as a block, so we need to avoid creating blocks.
Comment #59
bleen CreditAttribution: bleen commentedAs far as I know, nothing guarantees that "page top" exists. It's annoying, but I think that "content" is the only guaranteed region. That said I believe you can just add "page_top" if it doesnt exist in $page already
Other than this, I'm good to go :)
Comment #60
bleen CreditAttribution: bleen commentedComment #61
marcelovaniI have tested that, using Garland theme, which doesn't define a region called page_top.
I can confirm that the markup was correctly added to the page_top region.
The page_top region is a default Drupal region
See https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...
I would be happy to add a logic like below, to have some fallbacks, if you think its better, but in my opinion it's not needed.
The logic above will check if any of those 3 regions exist and get out of the loop as soon as the first occurrence happens.
Comment #62
marcelovaniComment #63
Bogdan1988 CreditAttribution: Bogdan1988 commentedThank you marcelovani for your patch. But I have a question. What if I need to combine couple out of page slots from different contexts. In current out of page reaction only first context value added. To make possible addition of multiple out of page slots from different contexts we need to remove break from context execute() method.
Comment #66
marcelovaniRe-rolled the patch to work with the latest changes on 7.x-1.x
and @Gogdan1988 you can add multiple OOP slots with the code as it is
Comment #67
marcelovaniComment #68
danharper CreditAttribution: danharper commentedThanks for the quick response, anything from stopping this going into dev.
Cheers Dan
Comment #69
bleen CreditAttribution: bleen commented@danharper, have you tested the patch in #66? If so, can you report back what you did to test and what the results were...
Comment #70
marcelovaniHi bleen18, I tested the Out of page tags on their own and noticed that there was some logic missing since I changed the Out of page tags from Blocks to Context Reaction.
I have added the logic on hook_page_build(), see the dfp-interdiff.txt. Also, I changed dfp_tag_load_all() to be static to save some processing.
Here is a quick list of steps to test it and maybe write simpletest too.
Once you are inside the Sandbox:
Comment #71
bleen CreditAttribution: bleen commentedThe problem here is that ctools_export_crud_load_all() already stores these results in a static variable. Adding this will cause all the entities to be stored in memory twice.
why? This alter is already called on load.
Comment #72
marcelovaniRe 1: If you think it's not needed, no problem, we can revert it.
Re 2: If you remove it and try to run the code, you will have no Out of page tags on the page. I need to call drupal_alter to process all the Out of page tags since they do not get processed by the block hooks anymore. How about we put the drupal_alter('dfp_tag_load', $tag) into dfp_tag_load_all()?
Comment #73
bleen CreditAttribution: bleen commentedYeah ... there is no need to add to the memory footprint. Lets kill it
I dont think we can move it to dfp_tag_load_all because there are plenty of reasons why people would call dfp_tag_load and the alter should really run. That said, you are running dfp_tag_load() just a few lines down from this code anyway.
Comment #74
bleen CreditAttribution: bleen commentedOn second glance I dont see why this is here at all. You dont use the $tags variable anywhere
Comment #75
marcelovaniComment #76
bleen CreditAttribution: bleen commentedI think #75 looks good to go ... I'd love to have at least one more person give the thumbs up, but if no one steps up soon I will commit this.
Comment #77
bleen CreditAttribution: bleen commentedComment #78
melon CreditAttribution: melon commented#75 works fine for me, thanks for the patch Marcelo!
Comment #79
mrconnerton CreditAttribution: mrconnerton commentedThe patch in #75 doesn't apply to the latest dev but I was able to apply it manually. So far everything seems to look good. I created the ad slot and used the context module to place it on the homepage and a specific node. I see the code in the correct places. I've notified my DFP manager to start testing serving to it but I'm not getting any errors so I think this is a good patch.
Comment #80
bleen CreditAttribution: bleen commentedComment #81
marcelovaniThere have been numerous changes to the code that makes my patch not to apply. Shame, as if it were committed after #78 RTBC, it would have got in and we all would have benefited.
If anybody else wants to pick up this patch for re-roll, you are welcome to do so. I won't be working on this any longer as I have moved on other work.
Comment #82
mrconnerton CreditAttribution: mrconnerton commentedI will wait and confirm that ads are serving properly and I can do a reroll at that point. Would be great if this can get commited soon so I don't have to maintain another patched module.
Comment #85
marcelovaniBTW the patch applied with no errors for me.
I have also re-sent the test to the queue, but it is not showing the results, see https://qa.drupal.org/pifr/test/855458
Comment #87
bleen CreditAttribution: bleen commentedOk ... I took this for another test drive today. All is well. Thanks everyone!!!
Comment #88
bleen CreditAttribution: bleen commentedComment #90
ZhuRenTongKu CreditAttribution: ZhuRenTongKu commentedHey Guys, I know this thread has been closed for some time now.
I'm working with a client who is trying to serve interstitial adverts on their site. I have gone through the configuration on the dfp module side and according to everything I've read, and based on the usage example at the top of the page here, it is setup correctly on our end.
My question, does anyone have experience setting up the ad slot on the google dfp side? This is proving challenging since I do not have access to their ad campaign/slot configurations. But it seems to me something is not setup correctly on the ad slot itself vs drupal.
Also note, I'm using a hook_page_build to render this ad slot, since context module is heavy and I'd rather not install it.
output in head
output in body
I see the advert markup is rendering properly, however, it is not behaving as a popup. The element-hidden is still applied to the parent wrapper, and the advert slot (iframe) is coming through as 1px x 1px... Seems something is not triggering this to actually behave like a popup on the advert side. I've been told an out of page 'pop-up, pop-under' template has been configured on the advert side of things in Google.
Any insights would be very appreciated.
Thanks
Comment #91
marcelovaniHi
I is out of my knowledge that Context module is heavy, therefore I cannot comment on this. But since you decided to do your own implementation, I cannot prove that it works either.
Regarding Out of page ads, as far as I know they do not pop up automatically, to achieve that you will need to create an add with javascript. I imagine DFP works like this because Out of page ads are not only used for popups, but also to fill the whole background of the page with an ad for example.
Here is the support on how to create out-of-page line items
https://support.google.com/dfp_sb/answer/79265?hl=en
I would suggest you use DFP module with Context as it is first, then you get your javascript ad working (with popup), then you disable Context and do your own thing.