From f845815fed9a454de97303172cda760b1eadc182 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Thu, 7 Feb 2019 15:48:03 -0500 Subject: [PATCH 1/6] Fix https://github.com/INN/doubleclick-for-wp/issues/95 by making the mapping key be sizeMapping and the targeting key be setTargeting --- inc/class-doubleclick.php | 4 ++-- js/jquery.dfw.js | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/inc/class-doubleclick.php b/inc/class-doubleclick.php index d5439fa..2e3f72c 100644 --- a/inc/class-doubleclick.php +++ b/inc/class-doubleclick.php @@ -159,8 +159,8 @@ public function enqueue_scripts() { $data = array( 'dfpID' => $this->network_code(), 'network_code' => $this->network_code(), - 'mappings' => $mappings, - 'targeting' => $this->targeting(), + 'sizeMapping' => $mappings, + 'setTargeting' => $this->targeting(), ); /** diff --git a/js/jquery.dfw.js b/js/jquery.dfw.js index 5744aaf..06eb845 100644 --- a/js/jquery.dfw.js +++ b/js/jquery.dfw.js @@ -33,9 +33,7 @@ // if we have some ads, then load 'em! if (toLoad.length > 0) { dfp_options = Object.assign( dfw, { - "collapseEmptyDivs": false, - "sizeMapping": dfw.mappings, - "setTargeting": dfw.targeting + "collapseEmptyDivs": false }); window.dfp_options = dfp_options; $( toLoad ).dfp( dfp_options ).addClass( 'dfw-loaded' ); From 16559ead9c29c8688c127e3f412148eee1fec4fb Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Thu, 7 Feb 2019 16:14:51 -0500 Subject: [PATCH 2/6] Partially fix https://github.com/INN/doubleclick-for-wp/issues/95 by moving the non-lazy-load ads loader into jquery.dfw.js, next to the lazy-load ads loader --- inc/class-doubleclick.php | 16 ---------------- js/jquery.dfw.js | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/inc/class-doubleclick.php b/inc/class-doubleclick.php index 2e3f72c..58dd399 100644 --- a/inc/class-doubleclick.php +++ b/inc/class-doubleclick.php @@ -83,8 +83,6 @@ public function __construct( $network_code = null ) { $this::$enqueued = true; } - add_action( 'wp_print_footer_scripts', array( $this, 'footer_script' ) ); - $breakpoints = maybe_unserialize( get_option( 'dfw_breakpoints' ) ); if ( ! empty( $breakpoints ) ) : @@ -199,20 +197,6 @@ private function network_code() { return ( isset( $this->network_code ) && ! empty( $this->network_code ) ) ? $this->network_code : get_option( 'dfw_network_code','xxxxxx' ); } - public function footer_script() { - if ( ! $this->debug ) { - $mappings = array(); - foreach ( $this->ad_slots as $ad ) { - if ( $ad->has_mapping() ) { - $mappings[ "mapping{$ad->id}" ] = $ad->mapping(); - } - } ?> - - Date: Thu, 7 Feb 2019 16:47:00 -0500 Subject: [PATCH 3/6] Keep the old parameters around for backwards compatibility --- inc/class-doubleclick.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/inc/class-doubleclick.php b/inc/class-doubleclick.php index 58dd399..7418c40 100644 --- a/inc/class-doubleclick.php +++ b/inc/class-doubleclick.php @@ -156,9 +156,12 @@ public function enqueue_scripts() { $data = array( 'dfpID' => $this->network_code(), - 'network_code' => $this->network_code(), 'sizeMapping' => $mappings, 'setTargeting' => $this->targeting(), + // The following are legacy support for pre-0.3.1 user code + 'network_code' => $this->network_code(), + 'mappings' => $mappings, + 'targeting' => $this->targeting(), ); /** @@ -168,9 +171,10 @@ public function enqueue_scripts() { * @link https://github.com/INN/doubleclick-for-wp/issues/63#issuecomment-393342611 * @param Array $data An associative array of things. The default is: * array( + * 'dfpID' => the option from the plugin settings * 'network_code' => the option from the plugin settings - * 'mappings' => an array of ad mappings; not sure exactly what this is supposed to be - * 'targeting' => the ad targeting data appropriate to this page + * 'sizeMapping' => an array of ad mappings; not sure exactly what this is supposed to be + * 'setTargeting' => the ad targeting data appropriate to this page * ) */ $data = apply_filters( 'dfw_js_data', $data ); From 26e3e510ea02e8d7e5ffde5f33e931453d6e655a Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Thu, 7 Feb 2019 17:13:20 -0500 Subject: [PATCH 4/6] Remove old copies of jquery.dfp.js Closes https://github.com/INN/doubleclick-for-wp/issues/94 --- js/jquery.dfp.min.js | 8 -------- js/vendor/jquery.dfp.min.js | 8 -------- 2 files changed, 16 deletions(-) delete mode 100644 js/jquery.dfp.min.js delete mode 100644 js/vendor/jquery.dfp.min.js diff --git a/js/jquery.dfp.min.js b/js/jquery.dfp.min.js deleted file mode 100644 index 9d6b7f9..0000000 --- a/js/jquery.dfp.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * jQuery DFP v1.1.5 - * http://github.com/coop182/jquery.dfp.js - * - * Copyright 2014 Matt Cooper - * Released under the MIT license - */ -!function(a,b,c){"use strict";var d,e=this,f="",g=0,h=0,i=0,j=".adunit",k={},l=!1,m="googleAdUnit",n=function(b,c,e){g=0,i=0,f=b,d=a(c),v(),o(e),a(function(){p(),q()})},o=function(d){if(k={setTargeting:{},setCategoryExclusion:"",setLocation:"",enableSingleRequest:!0,collapseEmptyDivs:"original",refreshExisting:!0,disablePublisherConsole:!1,disableInitialLoad:!1,noFetch:!1,namespace:c,sizeMapping:{}},"undefined"==typeof d.setUrlTargeting||d.setUrlTargeting){var e=r();a.extend(!0,k.setTargeting,{inURL:e.inURL,URLIs:e.URLIs,Query:e.Query,Domain:b.location.host})}a.extend(!0,k,d),k.googletag&&b.googletag.cmd.push(function(){a.extend(!0,b.googletag,k.googletag)})},p=function(){d.each(function(){var c=a(this);g++;var d=t(c),e=s(c,d),h=u(c);c.data("existingContent",c.html()),c.html("").addClass("display-none"),b.googletag.cmd.push(function(){var g,i=c.data(m);g=i?i:c.data("outofpage")?b.googletag.defineOutOfPageSlot("/"+f+"/"+d,e).addService(b.googletag.pubads()):c.data("companion")?b.googletag.defineSlot("/"+f+"/"+d,h,e).addService(b.googletag.companionAds()).addService(b.googletag.pubads()):b.googletag.defineSlot("/"+f+"/"+d,h,e).addService(b.googletag.pubads());var j=c.data("targeting");j&&a.each(j,function(a,b){g.setTargeting(a,b)});var l=c.data("exclusions");if(l){var n,o=l.split(",");a.each(o,function(b,c){n=a.trim(c),n.length>0&&g.setCategoryExclusion(n)})}var p=c.data("size-mapping");if(p&&k.sizeMapping[p]){var q=b.googletag.sizeMapping();a.each(k.sizeMapping[p],function(a,b){q.addSize(b.browser,b.ad_sizes)}),g.defineSizeMapping(q.build())}c.data(m,g),"function"==typeof k.beforeEachAdLoaded&&k.beforeEachAdLoaded.call(this,c)})}),b.googletag.cmd.push(function(){if(k.enableSingleRequest&&b.googletag.pubads().enableSingleRequest(),a.each(k.setTargeting,function(a,c){b.googletag.pubads().setTargeting(a,c)}),"object"==typeof k.setLocation&&("number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&"number"==typeof k.setLocation.precision?b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude,k.setLocation.precision):"number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude)),k.setCategoryExclusion.length>0){var c,e=k.setCategoryExclusion.split(",");a.each(e,function(d,e){c=a.trim(e),c.length>0&&b.googletag.pubads().setCategoryExclusion(c)})}k.collapseEmptyDivs&&b.googletag.pubads().collapseEmptyDivs(),k.disablePublisherConsole&&b.googletag.pubads().disablePublisherConsole(),k.companionAds&&(b.googletag.companionAds().setRefreshUnfilledSlots(!0),k.disableInitialLoad||b.googletag.pubads().enableVideoAds()),k.disableInitialLoad&&b.googletag.pubads().disableInitialLoad(),k.noFetch&&b.googletag.pubads().noFetch(),b.googletag.pubads().addEventListener("slotRenderEnded",function(b){i++;var c=a("#"+b.slot.getSlotId().getDomId()),e=b.isEmpty?"none":"block",f=c.data("existingContent");"none"===e&&a.trim(f).length>0&&"original"===k.collapseEmptyDivs&&(c.show().html(f),e="block display-original"),c.removeClass("display-none").addClass("display-"+e),"function"==typeof k.afterEachAdLoaded&&k.afterEachAdLoaded.call(this,c,b),"function"==typeof k.afterAllAdsLoaded&&i===g&&k.afterAllAdsLoaded.call(this,d)}),b.googletag.enableServices()})},q=function(){d.each(function(){var c=a(this),d=c.data(m);b.googletag.cmd.push(k.refreshExisting&&d&&c.hasClass("display-block")?function(){b.googletag.pubads().refresh([d])}:function(){b.googletag.display(c.attr("id"))})})},r=function(){var a=b.location.pathname.replace(/\/$/,""),c=new RegExp("/([^/]*)","ig"),d=a.match(c),e=["/"],f="";if(d&&"/"!==a){var g="",h=d.length;if(h>0)for(var i=0;h>i;i++){g=d[i],e.push(g);for(var j=i+1;h>j;j++)g+=d[j],e.push(g);0===i&&(e.splice(-1,1),f=g)}e.push(f)}e=e.reverse();var k=(b.location.toString().replace(/\=/gi,":").match(/\?(.+)$/),RegExp.$1.split("&"));return{inURL:e,URLIs:e[0],Query:k}},s=function(a,b){return h++,a.attr("id")||a.attr("id",b.replace(/[^A-z0-9]/g,"_")+"-auto-gen-id-"+h).attr("id")},t=function(a){var b=a.data("adunit")||k.namespace||a.attr("id")||"";return"function"==typeof k.alterAdUnitName&&(b=k.alterAdUnitName.call(this,b,a)),b},u=function(b){var c=[],d=b.data("dimensions");if(d){var e=d.split(",");a.each(e,function(a,b){var d=b.split("x");c.push([parseInt(d[0],10),parseInt(d[1],10)])})}else c.push([b.width(),b.height()]);return c},v=function(){if(l=l||a('script[src*="googletagservices.com/tag/js/gpt.js"]').length,!l){b.googletag=b.googletag||{},b.googletag.cmd=b.googletag.cmd||[];var c=document.createElement("script");c.async=!0,c.type="text/javascript",c.onerror=function(){w()};var d="https:"===document.location.protocol;c.src=(d?"https:":"http:")+"//www.googletagservices.com/tag/js/gpt.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(c,e),"none"===c.style.display&&w()}},w=function(){var c=b.googletag.cmd;setTimeout(function(){var d=function(a,c,d){return b.googletag.ads.push(d),b.googletag.ads[d]={renderEnded:function(){},addService:function(){return this}},b.googletag.ads[d]};b.googletag={cmd:{push:function(a){a.call(e)}},ads:[],pubads:function(){return this},noFetch:function(){return this},disableInitialLoad:function(){return this},disablePublisherConsole:function(){return this},enableSingleRequest:function(){return this},setTargeting:function(){return this},collapseEmptyDivs:function(){return this},enableServices:function(){return this},defineSlot:function(a,b,c){return d(a,b,c,!1)},defineOutOfPageSlot:function(a,b){return d(a,[],b,!0)},display:function(a){return b.googletag.ads[a].renderEnded.call(e),this}},a.each(c,function(a,c){b.googletag.cmd.push(c)})},50)};a.dfp=a.fn.dfp=function(a,b){b=b||{},a===c&&(a=f),"object"==typeof a&&(b=a,a=b.dfpID||f);var d=this;return"function"==typeof this&&(d=j),n(a,d,b),this}}(window.jQuery||window.Zepto||window.tire,window); \ No newline at end of file diff --git a/js/vendor/jquery.dfp.min.js b/js/vendor/jquery.dfp.min.js deleted file mode 100644 index 9d6b7f9..0000000 --- a/js/vendor/jquery.dfp.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * jQuery DFP v1.1.5 - * http://github.com/coop182/jquery.dfp.js - * - * Copyright 2014 Matt Cooper - * Released under the MIT license - */ -!function(a,b,c){"use strict";var d,e=this,f="",g=0,h=0,i=0,j=".adunit",k={},l=!1,m="googleAdUnit",n=function(b,c,e){g=0,i=0,f=b,d=a(c),v(),o(e),a(function(){p(),q()})},o=function(d){if(k={setTargeting:{},setCategoryExclusion:"",setLocation:"",enableSingleRequest:!0,collapseEmptyDivs:"original",refreshExisting:!0,disablePublisherConsole:!1,disableInitialLoad:!1,noFetch:!1,namespace:c,sizeMapping:{}},"undefined"==typeof d.setUrlTargeting||d.setUrlTargeting){var e=r();a.extend(!0,k.setTargeting,{inURL:e.inURL,URLIs:e.URLIs,Query:e.Query,Domain:b.location.host})}a.extend(!0,k,d),k.googletag&&b.googletag.cmd.push(function(){a.extend(!0,b.googletag,k.googletag)})},p=function(){d.each(function(){var c=a(this);g++;var d=t(c),e=s(c,d),h=u(c);c.data("existingContent",c.html()),c.html("").addClass("display-none"),b.googletag.cmd.push(function(){var g,i=c.data(m);g=i?i:c.data("outofpage")?b.googletag.defineOutOfPageSlot("/"+f+"/"+d,e).addService(b.googletag.pubads()):c.data("companion")?b.googletag.defineSlot("/"+f+"/"+d,h,e).addService(b.googletag.companionAds()).addService(b.googletag.pubads()):b.googletag.defineSlot("/"+f+"/"+d,h,e).addService(b.googletag.pubads());var j=c.data("targeting");j&&a.each(j,function(a,b){g.setTargeting(a,b)});var l=c.data("exclusions");if(l){var n,o=l.split(",");a.each(o,function(b,c){n=a.trim(c),n.length>0&&g.setCategoryExclusion(n)})}var p=c.data("size-mapping");if(p&&k.sizeMapping[p]){var q=b.googletag.sizeMapping();a.each(k.sizeMapping[p],function(a,b){q.addSize(b.browser,b.ad_sizes)}),g.defineSizeMapping(q.build())}c.data(m,g),"function"==typeof k.beforeEachAdLoaded&&k.beforeEachAdLoaded.call(this,c)})}),b.googletag.cmd.push(function(){if(k.enableSingleRequest&&b.googletag.pubads().enableSingleRequest(),a.each(k.setTargeting,function(a,c){b.googletag.pubads().setTargeting(a,c)}),"object"==typeof k.setLocation&&("number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&"number"==typeof k.setLocation.precision?b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude,k.setLocation.precision):"number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude)),k.setCategoryExclusion.length>0){var c,e=k.setCategoryExclusion.split(",");a.each(e,function(d,e){c=a.trim(e),c.length>0&&b.googletag.pubads().setCategoryExclusion(c)})}k.collapseEmptyDivs&&b.googletag.pubads().collapseEmptyDivs(),k.disablePublisherConsole&&b.googletag.pubads().disablePublisherConsole(),k.companionAds&&(b.googletag.companionAds().setRefreshUnfilledSlots(!0),k.disableInitialLoad||b.googletag.pubads().enableVideoAds()),k.disableInitialLoad&&b.googletag.pubads().disableInitialLoad(),k.noFetch&&b.googletag.pubads().noFetch(),b.googletag.pubads().addEventListener("slotRenderEnded",function(b){i++;var c=a("#"+b.slot.getSlotId().getDomId()),e=b.isEmpty?"none":"block",f=c.data("existingContent");"none"===e&&a.trim(f).length>0&&"original"===k.collapseEmptyDivs&&(c.show().html(f),e="block display-original"),c.removeClass("display-none").addClass("display-"+e),"function"==typeof k.afterEachAdLoaded&&k.afterEachAdLoaded.call(this,c,b),"function"==typeof k.afterAllAdsLoaded&&i===g&&k.afterAllAdsLoaded.call(this,d)}),b.googletag.enableServices()})},q=function(){d.each(function(){var c=a(this),d=c.data(m);b.googletag.cmd.push(k.refreshExisting&&d&&c.hasClass("display-block")?function(){b.googletag.pubads().refresh([d])}:function(){b.googletag.display(c.attr("id"))})})},r=function(){var a=b.location.pathname.replace(/\/$/,""),c=new RegExp("/([^/]*)","ig"),d=a.match(c),e=["/"],f="";if(d&&"/"!==a){var g="",h=d.length;if(h>0)for(var i=0;h>i;i++){g=d[i],e.push(g);for(var j=i+1;h>j;j++)g+=d[j],e.push(g);0===i&&(e.splice(-1,1),f=g)}e.push(f)}e=e.reverse();var k=(b.location.toString().replace(/\=/gi,":").match(/\?(.+)$/),RegExp.$1.split("&"));return{inURL:e,URLIs:e[0],Query:k}},s=function(a,b){return h++,a.attr("id")||a.attr("id",b.replace(/[^A-z0-9]/g,"_")+"-auto-gen-id-"+h).attr("id")},t=function(a){var b=a.data("adunit")||k.namespace||a.attr("id")||"";return"function"==typeof k.alterAdUnitName&&(b=k.alterAdUnitName.call(this,b,a)),b},u=function(b){var c=[],d=b.data("dimensions");if(d){var e=d.split(",");a.each(e,function(a,b){var d=b.split("x");c.push([parseInt(d[0],10),parseInt(d[1],10)])})}else c.push([b.width(),b.height()]);return c},v=function(){if(l=l||a('script[src*="googletagservices.com/tag/js/gpt.js"]').length,!l){b.googletag=b.googletag||{},b.googletag.cmd=b.googletag.cmd||[];var c=document.createElement("script");c.async=!0,c.type="text/javascript",c.onerror=function(){w()};var d="https:"===document.location.protocol;c.src=(d?"https:":"http:")+"//www.googletagservices.com/tag/js/gpt.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(c,e),"none"===c.style.display&&w()}},w=function(){var c=b.googletag.cmd;setTimeout(function(){var d=function(a,c,d){return b.googletag.ads.push(d),b.googletag.ads[d]={renderEnded:function(){},addService:function(){return this}},b.googletag.ads[d]};b.googletag={cmd:{push:function(a){a.call(e)}},ads:[],pubads:function(){return this},noFetch:function(){return this},disableInitialLoad:function(){return this},disablePublisherConsole:function(){return this},enableSingleRequest:function(){return this},setTargeting:function(){return this},collapseEmptyDivs:function(){return this},enableServices:function(){return this},defineSlot:function(a,b,c){return d(a,b,c,!1)},defineOutOfPageSlot:function(a,b){return d(a,[],b,!0)},display:function(a){return b.googletag.ads[a].renderEnded.call(e),this}},a.each(c,function(a,c){b.googletag.cmd.push(c)})},50)};a.dfp=a.fn.dfp=function(a,b){b=b||{},a===c&&(a=f),"object"==typeof a&&(b=a,a=b.dfpID||f);var d=this;return"function"==typeof this&&(d=j),n(a,d,b),this}}(window.jQuery||window.Zepto||window.tire,window); \ No newline at end of file From a5ecab461286f5073c6dfa10afc67834bb5a5cbf Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Thu, 7 Feb 2019 17:20:16 -0500 Subject: [PATCH 5/6] Start 0.3.1 changelog --- readme.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/readme.txt b/readme.txt index d1b720a..41c0c84 100644 --- a/readme.txt +++ b/readme.txt @@ -34,6 +34,17 @@ For more advanced documentation for developers and advanced users see [the offic == Changelog == += 0.3.1 = + +Fixes: + +- Fixes an issue where non-lazy-loaded ads were not being loaded with the correct mappings, leading to ads requesting creatives with sizes that matched the size of the ad condainer, such as 1090x0. [Pull request #97](https://github.com/INN/doubleclick-for-wp/pull/97) for issues [#96](https://github.com/INN/doubleclick-for-wp/issues/96), [#95](https://github.com/INN/doubleclick-for-wp/issues/95). +- Fixes an issue where [Autoptimize](https://wordpress.org/plugins/autoptimize/) was breaking non-lazy-load ads. [Pull request #97](https://github.com/INN/doubleclick-for-wp/pull/97) for issue [#95](https://github.com/INN/doubleclick-for-wp/issues/95). + +Cleanup: + +- Removes some antiquated copied of jquery.dfp.js that were kept in the plugin, despite not being referenced. [Pull request #97](https://github.com/INN/doubleclick-for-wp/pull/97) for issue [#94](https://github.com/INN/doubleclick-for-wp/issues/94). + = 0.3 = Thanks to WordPress.org user [onlineforbusiness](https://wordpress.org/support/users/onlineforbusiness/) and GitHub users [dbeniaminov](https://github.com/dbeniaminov) and [tienvooracht](https://github.com/tienvooracht) for their contributions to this release. From e77db93917bc1b305a3cd123a419ce27253ee3bf Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Thu, 7 Feb 2019 17:25:36 -0500 Subject: [PATCH 6/6] Bump version number to 0.3.1-rc1 --- bower.json | 2 +- dfw.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 047c269..e37164c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "dfp", - "version": "0.3", + "version": "0.3.1", "homepage": "https://github.com/INN/DoubleClick-for-WordPress", "authors": [ "nerds@inn.org" diff --git a/dfw.php b/dfw.php index 272ce9f..d0f90ab 100644 --- a/dfw.php +++ b/dfw.php @@ -1,8 +1,8 @@