INN / doubleclick-for-wp

WordPress plugin for serving Google Ad Manager ads
https://wordpress.org/plugins/doubleclick-for-wp/
GNU General Public License v2.0
25 stars 11 forks source link

Another report of ads not fetching #92

Open benlk opened 5 years ago

benlk commented 5 years ago

From https://secure.helpscout.net/conversation/739589544/2981/?folderId=1219602

WP 5.0.2
PHP 7.2.2
Plugins:

It's a long list - Advanced Cron Manager - Advanced Custom Fields PRO - Akismet Anti-Spam - Alexa Certify - All In One SEO Pack - AMP - Beautiful taxonomy filter - Better WordPress Recent Comments - BP Profile Search - BuddyPress - BuddyPress Friends Only Activity Stream - Buddypress Messages Spam Blocker - BuddyPress Xprofile Custom Fields Type - Classic Editor - Cloudflare - Co-Authors - Comments Like Dislike - Cookie Consent - DoubleClick for WordPress - Edit Flow - Email Address Encoder - Enhanced Text Widget - Export Users to CSV - Featured Images in RSS w/ Size and Position - Gravity Forms - Gravity Forms Polls Add-On - Gravity Forms Quiz Add-On - iframe - Jetpack by WordPress.com - Lazy Load for Comments - MemberPress Business Edition - MemberPress - MailChimp - MetaSlider - oEmbed in Comments - PHP Compatibility Checker - Popup Maker - Post-Plugin Library - Public Post Preview - Recent Posts Widget Extended - Redis Object Cache - Regenerate Thumbnails - Register IPs - Revision Control - Simple 301 Redirects - Simple Image Widget - Simple Lightbox - Stop New User + Change Password Emails Select - Stop Spammers - Theme Check - Upcoming Events - Widget Select - VaultPress Widget CSS Classes - Wordfence Security - Wordpress Video Plugin - WP Crontrol - WP Missed Schedule - WP Resized Image Quality - WP ULike - WP-Ban - WP-Cron Status Checker - Yet Another Related Posts Plugin > some of those are plugins I wrote myself, if they look unfamiliar

Custom theme
Plugin version 0.3

The contents of the ?googfc error:

  1. That's an error. The requested URL was not found on this server. That's all we know. The "slot size" shows the height as zero though.

Other details:

Our ad folks said the reason the ads are no longer displaying is that the sizes are now being sent incorrectly:

The issue why you are getting a 400 error here is that the request is sending incorrect ad size. In this example, it was sending these ad sizes :

  • 1115x0 for the leaderboard_top
  • 362x0 for the bigbox
  • 1115x0 for the leaderboard_bottom
benlk commented 5 years ago

This may be related to #91 and #90.

Next steps:

benlk commented 5 years ago

But after updating the plugin, the site stopped showing ads and there were below errors in the console:

-> GET https://securepubads.g.doubleclick.net/gampad/ads?gdfp_req=1& .... with 400 error. -> Access to XMLHttpRequest at 'https://securepubads.g.doubleclick.net/gampad/ads?gdfp_req=1&pvsid=417413281066130& ........' from origin 'https://example.org' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

After digging up in the code, I found below DOM code in the footer of the website:

plugin ver 0.3 code:

jQuery('.dfw-unit:not(.dfw-lazy-load)').dfp( window.dfw );

which is different than the earlier version of the plugin which is as below:

plugin ver 0.2.1 code:

jQuery('.dfw-unit:not(.dfw-lazy-load)').dfp({
    dfpID: '<?php echo $this->networkCode(); ?>',
    collapseEmptyDivs: false,
    setTargeting: <?php echo json_encode($this->targeting()); ?>,
    sizeMapping: <?php echo json_encode($mappings); ?>
});

The older plugin was using these php values instead of the JS var dfw.

So, I commented out the below line in "/plugins/doubleclick-for-wp/inc/class-doubleclick.php" :

jQuery('.dfw-unit:not(.dfw-lazy-load)').dfp( window.dfw );

and added this code:

jQuery('.dfw-unit:not(.dfw-lazy-load)').dfp({
    dfpID: '<?php echo $this->network_code(); ?>',
    collapseEmptyDivs: false,
    setTargeting: <?php echo json_encode($this->targeting()); ?>,
    sizeMapping: <?php echo json_encode($mappings); ?>
});

which fixed the issue and I can see the ads on my site now and the category targeting also seem to be working.

benlk commented 5 years ago

Aha.

https://github.com/INN/doubleclick-for-wp/blob/f73e00d5cf8897fd75706453986b21a0e6e4a8a2/inc/class-doubleclick.php#L159-L163

window.dfw uses targeting and mappings; the added code uses setTargeting and sizeMapping.

That might reduce the amount of code needed on https://github.com/INN/doubleclick-for-wp/blob/bf4fcb5423ff359af955948ba253a8e2211185a3/js/jquery.dfw.js#L35-L39