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.
CommentFileSizeAuthor
#75 2038965-out_of_page_slot-75.patch7.33 KBmarcelovani
#70 dfp-interdiff.txt1.82 KBmarcelovani
#70 2038965-out_of_page_slot-70.patch8.01 KBmarcelovani
#66 2038965-out_of_page_slot-67.patch7.03 KBmarcelovani
#58 2038965-out_of_page_slot-58.patch7.07 KBmarcelovani
#56 2038965-out_of_page_slot-56.patch6.41 KBmarcelovani
#55 2038965-out_of_page_slot-55.patch2.06 KBmarcelovani
#47 2038965-out_of_page_slot-47.patch12.13 KBextremal
#44 2038965-out_of_page_slot-44.patch11.99 KBextremal
#42 2038965-out_of_page_slot-42.patch10.21 KBMiszel
#39 2038965-out_of_page_slot-39.patch11.98 KBmarcelovani
#39 Screen Shot 2013-11-08 at 11.22.29.png101.91 KBmarcelovani
#36 2013-11-04_1544.png9.16 KBBogdan1988
#34 2038965-out_of_page_slot-34.patch1.77 KBmarcelovani
#31 2038965-out_of_page_slot-21.patch2.37 KBjohnish
#30 2038965-out_of_page_slot.patch2.37 KBjohnish
#22 Screen Shot 2013-08-27 at 11.14.12.png641.95 KBmarcelovani
#20 2038965-out_of_page_slot-20.patch1.72 KBmarcelovani
#19 2038965-out_of_page_slot-19.patch1.68 KBdavidgrayston
#18 2038965-out_of_page_slot-18.txt1.68 KBdavidgrayston
#17 Site-Install.png124.28 KBbleen
#13 2038965-out_of_page_slot-6.patch1.68 KBmarcelovani
#11 2038965-out_of_page_slot-5.patch1.68 KBmarcelovani
#8 2038965-out_of_page_slot-4.patch1.66 KBmarcelovani
#5 2038965-out_of_page_slot-3.patch1.53 KBmarcelovani
#3 2038965-out_of_page_slot-2.patch1.61 KBmarcelovani
#1 2038965-out_of_page_slot-1.patch1.61 KBmarcelovani
Screen shot 2013-07-10 at 17.17.15.png33.44 KBmarcelovani
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcelovani’s picture

Status: Active » Needs review
FileSize
1.61 KB

I have created the patch that adds the extra settings when editing ad slots.

Status: Needs review » Needs work

The last submitted patch, 2038965-out_of_page_slot-1.patch, failed testing.

marcelovani’s picture

Status: Needs work » Needs review
FileSize
1.61 KB

Status: Needs review » Needs work

The last submitted patch, 2038965-out_of_page_slot-2.patch, failed testing.

marcelovani’s picture

marcelovani’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2038965-out_of_page_slot-3.patch, failed testing.

marcelovani’s picture

marcelovani’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2038965-out_of_page_slot-4.patch, failed testing.

marcelovani’s picture

Status: Needs work » Needs review
FileSize
1.68 KB
bleen’s picture

Status: Needs review » Needs work

Can 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:

+++ b/dfp.moduleundefined
@@ -716,7 +716,11 @@ function _dfp_js_global_settings() {
+  } else {

coding standard: else should be on a new line

marcelovani’s picture

Status: Needs work » Needs review
FileSize
1.68 KB

Hi 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/

<div id="pre-page" class="region region-pre-page pre-page">
    <div id="pre-page-inner" class="pre-page-inner inner clearfix">
    <div id="block-dfp-leaderboard_oop" class="block block-dfp">
  <div class="gutter inner clearfix">
            
    <div class="content clearfix">
      <div id="dfp-ad-leaderboard_oop-wrapper" class="dfp-tag-wrapper">
<div id="dfp-ad-leaderboard_oop" class="dfp-tag-wrapper" style="display: none;">
  <script type="text/javascript">
    googletag.cmd.push(function() {
      googletag.display("dfp-ad-leaderboard_oop");
    });
  </script><iframe...></iframe></div>
</div>    </div>
  </div><!-- /block-inner -->
</div><!-- /block -->
bleen’s picture

Would it be incorrect to have more than one Out of page placement?

Thats actually my question ... would it?

johnish’s picture

The 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.

johnish’s picture

#13: 2038965-out_of_page_slot-6.patch queued for re-testing.

bleen’s picture

Status: Needs review » Needs work
FileSize
124.28 KB

'#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:

Site-Install.png

This needs to be handled more cleanly...

davidgrayston’s picture

Updated patch with correct function name (googletag.defineOutOfPageSlot)

davidgrayston’s picture

Updated patch with correct function name (googletag.defineOutOfPageSlot)

marcelovani’s picture

Status: Needs work » Needs review
FileSize
1.72 KB

Thanks David, I am also adding the logic on #17

bleen’s picture

marcelovani ... I do not see the logic to deal with #17 in the patch you have in #20. Am I missing something?

marcelovani’s picture

Hi 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?

bleen’s picture

...used CSS to make it not visible

Thats 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?

marcelovani’s picture

Hum, 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?

bleen’s picture

Status: Needs review » Needs work

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.

My 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?

girishmuraly’s picture

Not 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?

bleen’s picture

Deviating 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

marcelovani’s picture

I 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).

/**
 * Implements hook_block_view().
 */
function dfp_block_view($delta) {
  $block = array();

  // If this is 32, this should be an md5 hash.
  if (drupal_strlen($delta) == 32) {
    $hashes = variable_get('dfp_block_hashes', array());
    if (!empty($hashes[$delta])) {
      $delta = $hashes[$delta];
    }
  }

  $tag = dfp_tag_load($delta);

  if (empty($tag->disabled)) {
    $block['content'] = dfp_tag($delta);
  }
  if (!empty($block['content']['dfp_wrapper']['tag']['#tag']->out_of_page)) {  
  	$block['content']['dfp_wrapper']['#attributes']['class'] = array('dfp-tag-out-of-page-wrapper');
  	$block['content']['#attached']['css'] = drupal_add_css('.dfp-tag-out-of-page-wrapper {height: 0px;}', array('group' => CSS_THEME, 'type' => 'inline'));
  }
  return $block;
}

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:

variables
  elements
    dfp_wrapper
      #attributes
         …

Placing the blocks using Context:

variables
  elements
    content
      dfp_wrapper
        #attributes
           ...
          
/**
 * Implements hook_preprocess_block().
 */
function dfp_preprocess_block(&$variables) {
  // Remove default block classes and keep only dfp-tag-out-of-page-wrapper.
  $elements = &$variables['elements'];
  $module = $elements['#block']->module;

  // When blocks are placed using context, they array has an extra index 'content'.
  if (!empty($elements['dfp_wrapper'])) {
  	$dfp_wrapper = $elements['dfp_wrapper'];
  }
  elseif (!empty($elements['content']['dfp_wrapper'])) {
  	$dfp_wrapper = $elements['content']['dfp_wrapper'];
  }
  
  if ($module == 'dfp' && !empty($dfp_wrapper['#attributes']['class'])) {
    $classes_array = $dfp_wrapper['#attributes']['class'];
    if (in_array('dfp-tag-out-of-page-wrapper', $classes_array)) {
      $variables['classes_array'] = array('dfp-tag-out-of-page-wrapper');
    }
  }
}

Thoughts?

bleen’s picture

Ultimately 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....

johnish’s picture

I took patch .20 and updated it for DFP 7.x-1.1 code

johnish’s picture

I 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.

samueldarwin’s picture

we 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.

marcelovani’s picture

@samueldarwin

  1. Apply the patch
  2. Create a DFP ad slot
  3. Under "Display options", tick "Out of page (interstitial) ad slot"
marcelovani’s picture

Issue summary: View changes
FileSize
1.77 KB

Updating patch that applies to the current 7.x dev or 1.1 tag

Bogdan1988’s picture

Hi. 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!

Bogdan1988’s picture

FileSize
9.16 KB
marcelovani’s picture

Are you using aggregation?
Have you tried to clear all cache?

Bogdan1988’s picture

Yes 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!

marcelovani’s picture

Status: Needs work » Needs review
FileSize
101.91 KB
11.98 KB

I 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.

Bogdan1988’s picture

Thank you, marcelovani. I will test this code and will tell you result. Thank you!

Bogdan1988’s picture

Thank 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!

Miszel’s picture

A 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);

marcelovani’s picture

Thanks 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

extremal’s picture

Patch in #42 is missing the dfp_context_reaction_outofpage.inc file.
Re-rolling.

Bogdan1988’s picture

Thank 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!

marcelovani’s picture

@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.

    if (isset($page['footer']['#suffix'])) {
      $page['footer']['#suffix'] .= $html;
    } 
    else {
      $page['footer']['#suffix'] = $html;
    }
extremal’s picture

Thanks @marcelovani . Added these changes into the patch.
Also changed line 919:
$html .= render(dfp_tag($machinename));
to

$dfp_tag = dfp_tag($machinename);
$html .= render($dfp_tag);

So php 5.5 will not complain about passing variables by reference

davidgrayston’s picture

Status: Needs review » Reviewed & tested by the community

This is working as expected

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 2038965-out_of_page_slot.patch, failed testing.

marcelovani’s picture

Status: Needs work » Reviewed & tested by the community

No idea why it's trying to test patch #30

marcelovani’s picture

Status: Needs work » Reviewed & tested by the community
bleen’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/dfp.module
    @@ -866,3 +883,73 @@ function template_preprocess_dfp_short_tag(&$variables) {
    +    drupal_add_css(implode(',', $selectors) . ' {position: absolute; height: 1px; padding: 0; margin: 0;}', array('group' => CSS_THEME, 'type' => 'inline'));
    

    This makes me cringe ... cant we just take advantage of the "element-hidden" class instead?

  2. +++ b/plugins/contexts/dfp_context_reaction_outofpage.inc
    @@ -0,0 +1,57 @@
    +      '#description' => t('The following DFP tags will be added to the page.'),
    

    There needs to be some messaging added here if $options is empty

  3. +++ b/plugins/export_ui/dfp_ctools_export_ui.inc
    @@ -89,13 +89,28 @@ function dfp_tag_form(&$form, &$form_state) {
    +  );
    ...
    +  $form['tag_settings']['out_of_page'] = array(
    +    '#type' => 'checkbox',
    +    '#title' => t('Out of page (interstitial) ad slot'),
    +    '#description' => (module_exists('context')) ?
    +        t('Use Context module to place the Ad slot on the page.') :
    +        t('The slot will be placed on pages, respecting the Page specific settings below.'),
    +    '#default_value' => isset($tag->settings['out_of_page']) ? $tag->settings['out_of_page'] : 0,
    +    '#parents' => array('settings', 'out_of_page'),
    +    '#weight' => 0,
    ...
    +    '#states' => array(
    +      'invisible' => array(
    +        'input[name="settings[out_of_page]"]' => array('checked' => TRUE),
    +      ),
    +    ),
    
    @@ -135,6 +150,11 @@ function dfp_tag_form(&$form, &$form_state) {
    +    '#states' => array(
    +      'invisible' => array(
    +        'input[name="settings[out_of_page]"]' => array('checked' => TRUE),
    +      ),
    +    ),
    
    +++ b/plugins/contexts/dfp_context_reaction_outofpage.inc
    @@ -0,0 +1,57 @@
    +    foreach ($tags as $tag) {
    +      if (!empty($tag->settings['out_of_page'])) {
    +        $options[$tag->machinename] = $tag->slot;
    +      }
    +    }
    

    Why bother having this at all? Why not just show a checkbox for all tags on the context reaction form?

  4. +++ b/plugins/export_ui/dfp_ctools_export_ui.inc
    @@ -89,13 +89,28 @@ function dfp_tag_form(&$form, &$form_state) {
    +    '#required' => FALSE,
    
    @@ -236,6 +289,10 @@ function dfp_tag_form_validate(&$form, &$form_state) {
    +  // Size is required for non-interstitial slots.
    +  if (empty($form_state['values']['settings']['out_of_page']) && empty($form_state['values']['size'])) {
    +    form_set_error('size', t('Size field is required.'));
    +  }
    
    +++ b/plugins/export_ui/dfp_tag_ui.class.php
    @@ -54,6 +54,10 @@ class dfp_tag_ui extends ctools_export_ui {
    +    // Interstitial slots do not have Size attribute.
    +    if (!empty($item->settings['out_of_page'])) {
    +      $item->size = t('N/A');
    +    }
    
    @@ -91,6 +95,11 @@ class dfp_tag_ui extends ctools_export_ui {
    +      // Interstitial slots do not require size and should not be displayed as a block.
    +      if (!empty($form_state['values']['settings']['out_of_page'])) {
    +        $form_state['item']->size = '0';
    +        $form_state['item']->block = '0';
    +      }
    

    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

  5. +++ b/plugins/export_ui/dfp_ctools_export_ui.inc
    @@ -143,6 +163,40 @@ function dfp_tag_form(&$form, &$form_state) {
    +  if (!module_exists('context')) {
    +    // Settings for visibility.
    +    $options = array(t('On every page except the listed pages.'), t('On the listed pages only.'));
    +    $description = t('Enter one page per line as Drupal paths. The "*" character is a wildcard. ' .
    +      'Example paths are %blog for the blog page and %blog-wildcard for every personal blog. ' .
    +      '%front is the front page.',
    +      array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
    +    $form['tag_settings']['visibility'] = array(
    +      '#type' => 'fieldset',
    +      '#title' => t('Page specific settings'),
    +      '#collapsible' => TRUE,
    +      '#collapsed' => FALSE,
    +      '#states' => array(
    +        'invisible' => array(
    +          'input[name="settings[out_of_page]"]' => array('checked' => FALSE),
    +        ),
    +      ),
    +    );
    +    $form['tag_settings']['visibility']['dfp_outofpage_visibility'] = array(
    +      '#type' => 'radios',
    +      '#title' => t('Add this Ad slot'),
    +      '#options' => $options,
    +      '#parents' => array('settings', 'out_of_page_visibility'),
    +      '#default_value' => isset($tag->settings['out_of_page_visibility']) ? $tag->settings['out_of_page_visibility'] : 0,
    +    );
    +    $form['tag_settings']['visibility']['dfp_outofpage_pages'] = array(
    +      '#type' => 'textarea',
    +      '#title' => t('Pages'),
    +      '#parents' => array('settings', 'out_of_page_pages'),
    +      '#default_value' => isset($tag->settings['out_of_page_pages']) ? $tag->settings['out_of_page_pages'] : 'admin*' . PHP_EOL,
    +      '#description' => $description,
    +      '#wysiwyg' => FALSE,
    +    );
    +  }
    

    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?

  6. +++ b/dfp.module
    @@ -866,3 +883,73 @@ function template_preprocess_dfp_short_tag(&$variables) {
    \ No newline at end of file
    

    nit: new line at EOF

  7. +++ b/dfp.module
    @@ -866,3 +883,73 @@ function template_preprocess_dfp_short_tag(&$variables) {
    +function dfp_page_alter(&$page) {
    

    I suspect that based on my other comments at least 90% of this function can be removed

  8. +++ b/dfp.module
    @@ -866,3 +883,73 @@ function template_preprocess_dfp_short_tag(&$variables) {
    +function _dfp_visibility_pages($tag) {
    

    Based on my other comments, this function should be unneeded

marcelovani’s picture

Hi, 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.

bleen’s picture

1 and 2: We could try it.

Cool

3: I just thought would be nice to display only options that were relevant for the type of Ad slot selected.

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

4: Agree with 0x0.

Cool

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.

I dont want to babysit that code either if there is a good solution already

marcelovani’s picture

Status: Needs work » Needs review
FileSize
2.06 KB

Simplified patch
Wrong file, uploading again...

marcelovani’s picture

This is the correct attachment

marcelovani’s picture

marcelovani’s picture

I missed one bit on the previous patch. Interstitial slots are not displayed as a block, so we need to avoid creating blocks.

bleen’s picture

+++ b/dfp.module
@@ -866,3 +883,28 @@ function template_preprocess_dfp_short_tag(&$variables) {
+  $page['page_top']['dfp_out_of_page'] = array(

As 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 :)

bleen’s picture

Status: Needs review » Needs work
marcelovani’s picture

I 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...

By default, valid region keys are 'page_top', 'header', 'sidebar_first', 'content', 'sidebar_second' and 'page_bottom'.

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.

$regions = array('page_top', 'content', 'page_bottom');
foreach ($regions as $region_name) {
  if (isset($page[$region_name])) {
    $page[$region_name]['dfp_out_of_page'] = array(
      '#weight' => -1000,
      '#markup' => $html,
    );
    break;
  }
}

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.

marcelovani’s picture

Status: Needs work » Needs review
Bogdan1988’s picture

Thank 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.

Status: Needs review » Needs work

The last submitted patch, 58: 2038965-out_of_page_slot-58.patch, failed testing.

marcelovani’s picture

Re-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

marcelovani’s picture

Status: Needs work » Needs review
danharper’s picture

Thanks for the quick response, anything from stopping this going into dev.

Cheers Dan

bleen’s picture

@danharper, have you tested the patch in #66? If so, can you report back what you did to test and what the results were...

marcelovani’s picture

Hi 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:

  • Enable Context, Context UI /admin/modules
  • Configure DFP /admin/structure/dfp_ads/settings
  • Put your network ID
  • Add a new Out of page slot /admin/structure/dfp_ads/add
  • Tick the Out of page checkbox
  • Set size to 0x0
  • Add a new context /admin/structure/context/add
  • Conditions: Sitewide - Always active
  • Reaction: Out of page, tick the out of page tag on the right panel
  • Clear all caches /admin/config/development/performance
  • Visit the home page
  • View source
  • You should see "googletag.defineOutOfPageSlot..." in the source
  • You should see "<div id="dfp-ad-???-wrapper" class="dfp-tag-wrapper element-hidden">" in the source
bleen’s picture

  1. +++ b/dfp.module
    @@ -465,12 +477,16 @@ function dfp_tag_load($machinename) {
    -  ctools_include('export');
    +  $tags = &drupal_static(__FUNCTION__, array());
     
    -  $tags = ctools_export_crud_load_all('dfp_tags');
    -  foreach ($tags as $key => $tag) {
    -    if (!$include_disabled && isset($tag->disabled) && $tag->disabled) {
    -      unset($tags[$key]);
    +  if (empty($tags)) {
    +    ctools_include('export');
    +
    +    $tags = ctools_export_crud_load_all('dfp_tags');
    +    foreach ($tags as $key => $tag) {
    +      if (!$include_disabled && isset($tag->disabled) && $tag->disabled) {
    +        unset($tags[$key]);
    +      }
    

    The 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.

  2. +++ b/dfp.module
    @@ -886,3 +906,38 @@ function template_preprocess_dfp_short_tag(&$variables) {
    +  foreach ($tags as $tag) {
    +    if (isset($tag->settings['out_of_page']) && $tag->settings['out_of_page'] == TRUE) {
    +      drupal_alter('dfp_tag_load', $tag);
    +    }
    +  }
    +
    

    why? This alter is already called on load.

marcelovani’s picture

Re 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()?

bleen’s picture

Re 1: If you think it's not needed, no problem, we can revert it.

Yeah ... there is no need to add to the memory footprint. Lets kill 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()?

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.

bleen’s picture

+++ b/dfp.module
@@ -886,3 +906,38 @@ function template_preprocess_dfp_short_tag(&$variables) {
+  }

On second glance I dont see why this is here at all. You dont use the $tags variable anywhere

marcelovani’s picture

bleen’s picture

I 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.

bleen’s picture

melon’s picture

Status: Needs review » Reviewed & tested by the community

#75 works fine for me, thanks for the patch Marcelo!

mrconnerton’s picture

The 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.

bleen’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs reroll
marcelovani’s picture

There 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.

mrconnerton’s picture

I 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.

marcelovani’s picture

BTW 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

  • bleen18 committed f4ae312 on 7.x-1.x authored by marcelovani
    Issue #2038965 by marcelovani, extremal, johnish, davidgrayston, Marcin...
bleen’s picture

Status: Needs review » Fixed

Ok ... I took this for another test drive today. All is well. Thanks everyone!!!

bleen’s picture

Issue tags: -Needs reroll

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ZhuRenTongKu’s picture

Hey 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.

/**
 * Implements of hook_page_build().
 * DFP Interstitial ad placement without context module
 */
function my_module_page_build(&$page) {
  $html = '';
  $machinename = '';
  $tags = dfp_tag_load_all();
  foreach ($tags as $tag) {
    if (isset($tag->settings['out_of_page']) && $tag->settings['out_of_page'] == TRUE && $tag->machinename == 'interstitial') {
          drupal_alter('dfp_tag_load', $tag);
      $machinename = $tag->machinename;
    }
  }
  if (!empty($machinename)) {
    $tag = dfp_tag_load($machinename);
    if (empty($tag->disabled)) {
      $dfp_tag = dfp_tag($machinename);
      $dfp_tag['dfp_wrapper']['#attributes']['class'][] = 'element-hidden';
      $html .= render($dfp_tag);
    }
  }
  // Add Out Of Page slots on the top of the page.
  $page['page_top']['dfp_out_of_page'] = array(
      '#weight' => -1000,
      '#markup' => $html,
  );
}

output in head

<script type="text/javascript">
<!--//--><![CDATA[//><!--
googletag.slots["interstitial"] = googletag.defineOutOfPageSlot("/NETWORK-ID/CAMPAIGN/interstitial", "dfp-ad-interstitial")
  .addService(googletag.pubads());
//--><!]]>
</script>

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

marcelovani’s picture

Hi

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.