Closed tienvooracht closed 5 years ago
If you want to serve non-personalized ads to all users, the easiest way would be to use the DFP settings (https://support.google.com/dfp_premium/answer/7673898). By default, DFP will send personalized ads to non-European-Economic-Area users.
We don't currently have a way to do googletag.pubads().setRequestNonPersonalizedAds(1)
for all readers using this plugin. It may be possible to enqueue JavaScript from your theme to access the googletag
variable that DFP uses.
Any idea what would be the best way to do this? I've tried:
<script> googletag.cmd.push( function() { googletag.pubads().setRequestNonPersonalizedAds(1); googletag.enableServices(); }); </script>
Without any luck. Only managed to get it working once by enqueueing a custom version of jquery.dfp.js but that threw a lot of JS errors.
I would write something like this:
<script>
window.googletag.pubads().setRequestNonPersonalizedAds(1);
</script>
And then wrap it in a PHP function, and add_action that function with priority 9 on wp_print_footer_scripts
in order to get there before DoubleClick::footer_script
But that doesn't affect already-fetched ads, and might not trigger before the JS in DoubleClick::footer_script
, so you may want to use disableInitialLoad
, make the change, and then refresh()
.
I haven't tried this yet, but what you could attempt is setting disableInitialLoad
via an argument on the jQuery( 'selector' ).dfp({})
call. Unfortunately there aren't any ways to do that without dequeueing DFW's code and enqueueing your own. You'd want to adjust the footer script:
And in the lazy-loader in jquery.dfw.js:
An ideal revision to this plugin would be to set a filter on $data
here:
And then, once the filtered options are output via the script localization on the page as the global dfw
variable, have the footer script draw from dfw
instead of using its own hardcoded options here:
https://github.com/INN/doubleclick-for-wp/blob/d90fba39cb0b14cbcf94d3cc86d98ec84108a9ba/dfw-init.php#L187-L204
Then as an example of how to use this, we'd need some docs about using window.googletag.pubads().refresh()
to summon new ads once it's appropriate to load, and an example short plugin to put that in a popup to show how this might be used in a "can we load personalized ads y/n?" example, with the PHP filter and the js for the popup.
In conclusion, you're right, you'd need to customize this plugin some, but here's the list:
$data
before it's localised by calling apply_filters()
on itjquery.dfw.js
to load arbitrary options from the dfw
option, same as the footer script. What would probably work here is getting the keys on $data
to be the appropriate keys for use as the configuration options that jQuery.dfp
is looking for.DoubleClick::footer_script
to draw from window.dfw
instead of its own optionsPlease, if you have any questions about this response, let me know. This response not very well-edited and may be missing some code.
How about dequeueing the minified JS, enqueuing the non-minified JS and adding the setRequestNonPersonalizedAds(1) straight into the code (as a quick fix since i'm not making any progress).
Yep, you could do that, and that does sound pretty easy.
No luck!
Any chance of making this an update for all of us EU based users of this plugin?
We'll add it to the next milestone for this plugin, but I can't guarantee a release date for that fix.
Can you upload your edited version of the non-minified JS, please? Seeing what didn't work may help us get an update out faster.
I added:
pubadsService.setRequestNonPersonalizedAds(1);
Beneath:
if (dfpOptions.noFetch) { pubadsService.noFetch(); }
On line 297.
Ideal would be to have some kind of filter/hook that we can access, for example using our cookie consent script.
Thanks for providing the edit.
What cookie consent script are you using?
It's a custom one based one, pretty straight forward. I've created a simple WordPress function that checks if consent is given. Ideal for showing/hiding ads. That's why a filter/hook would be awesome!
Any progress in adding this? Thanks!
@tienvooracht Progress is starting in https://github.com/INN/doubleclick-for-wp/pull/81 and would be merged in the next 24 hours. What sorts of documentation would be helpful to you in using the filter added here? https://github.com/INN/doubleclick-for-wp/pull/81/files#diff-d3aa22c88317ac877d6ef91e82d40c08R172
@tienvooracht please let us know if the filter 'dfw_js_data'
added in #81 works for you; I'm closing this issue for now but we can reopen it.
How would i get the plugin to use non personalized ads? Thanks!