I have been using the pubads().refresh() method to load only certain ad slots at different view port widths. In order to do this I have had to save the googletag.defineSlot declaration to a global variable.

To accompany this I have also added an option to the global settings to disable ads on initial load so that they can be "refreshed" whenever required. (e.g. on an orientation change) Patch attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chriskinch’s picture

Status: Active » Needs review
FileSize
2.16 KB

Just adding a quick amend so that the disableInitialLoad() is not automatically on when patch is first applied.

bleen’s picture

Status: Needs review » Needs work
+++ b/dfp.admin.incundefined
@@ -71,6 +71,12 @@ function dfp_admin_settings($form, $form_state) {
+  $form['global_tag_settings']['dfp_disable_init_load'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Disable initial ad load'),
+    '#default_value' => variable_get('dfp_disable_init_load', 0),
+    '#description' => t('(Async mode only) Disables the initial fetch of ads from Google when the page is first loaded. Calls to refresh() can still be used to fetch ads.'),

If this is for async only, why not use #states to only show this checkbox if async is checked

+++ b/dfp.moduleundefined
@@ -711,7 +714,7 @@ function _dfp_js_global_settings() {
+  $js = 'var slot_' . $tag->machinename . ' = googletag.defineSlot("' . $tag->adunit . '", ' . $tag->size . ', "' . $tag->placeholder_id . '")' . "\n";

I'm not a big fan of creating a global var here ... cant we use the googletag object to store these values?

chriskinch’s picture

Status: Needs work » Needs review
FileSize
2.4 KB

Hey

Attached is an updated patch based on your comments.

I am now using states to enable/disable the checkbox rather then hide as it might be nice for people to see that the option is there.
I have also added the slots definitions to the googletag object.

bleen’s picture

Status: Needs review » Fixed

I like it, thanks!! .... added

Status: Fixed » Closed (fixed)

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