From e13a6ecdce86c3db9bc0055fd4f274aab93e87f4 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 27 Oct 2015 16:42:36 -0400 Subject: [PATCH 1/2] DFP: send key discourse-category and value as category slug when loading ads --- assets/javascripts/discourse/components/google-dfp-ad.js.es6 | 4 ++++ .../discovery-list-container-top/discourse-adplugin.hbs | 2 +- .../templates/connectors/post-bottom/discourse-adplugin.hbs | 2 +- .../connectors/topic-above-post-stream/discourse-adplugin.hbs | 2 +- .../connectors/topic-above-suggested/discourse-adplugin.hbs | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 7239f32..e8bb23d 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -195,8 +195,11 @@ export default Ember.Component.extend({ var ad = ads[this.get('placement')]; if (!ad) { return; } + var self = this; + if (this.get('loadedGoogletag')) { googletag.cmd.push(function() { + ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : null); googletag.pubads().refresh([ad]); }); } @@ -209,6 +212,7 @@ export default Ember.Component.extend({ googletag.cmd.push(function() { var ad = defineSlot(self.get('placement'), self.siteSettings); if (ad) { + ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : null); googletag.display(self.get('divId')); googletag.pubads().refresh([ad]); } diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs index 5718677..62b7370 100644 --- a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs @@ -2,7 +2,7 @@ {{google-adsense placement="topic-list-top"}} {{/if}} {{#if siteSettings.dfp_topic_list_top_code}} - {{google-dfp-ad placement="topic-list-top"}} + {{google-dfp-ad placement="topic-list-top" category=category.slug}} {{/if}} {{#if siteSettings.amazon_topic_list_top_src_code}} {{amazon-product-links placement="topic-list-top"}} diff --git a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs index 84f0984..4d17491 100644 --- a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs @@ -2,7 +2,7 @@ {{google-adsense placement="post-bottom"}} {{/if}} {{#if postSpecificCountDFP}} - {{google-dfp-ad placement="post-bottom"}} + {{google-dfp-ad placement="post-bottom" category=topic.category.slug}} {{/if}} {{#if postSpecificCountAmazon}} {{amazon-product-links placement="post-bottom"}} diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs index 691113e..2928caf 100644 --- a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs @@ -2,7 +2,7 @@ {{google-adsense placement="topic-above-post-stream"}} {{/if}} {{#if siteSettings.dfp_topic_above_post_stream_code}} - {{google-dfp-ad placement="topic-above-post-stream" refreshOnChange=model.id}} + {{google-dfp-ad placement="topic-above-post-stream" refreshOnChange=model.id category=model.category.slug}} {{/if}} {{#if siteSettings.amazon_topic_above_post_stream_src_code}} {{amazon-product-links placement="topic-above-post-stream"}} diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs index 4b68794..8f17b29 100644 --- a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs @@ -2,7 +2,7 @@ {{google-adsense placement="topic-above-suggested"}} {{/if}} {{#if siteSettings.dfp_topic_above_suggested_code}} - {{google-dfp-ad placement="topic-above-suggested" refreshOnChange=model.id}} + {{google-dfp-ad placement="topic-above-suggested" refreshOnChange=model.id category=model.category.slug}} {{/if}} {{#if siteSettings.amazon_topic_above_suggested_src_code}} {{amazon-product-links placement="topic-above-suggested"}} From c5b9392ae50aa51e509adc29aaf45c94a75b0366 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 27 Oct 2015 17:44:03 -0400 Subject: [PATCH 2/2] FIX: ads not refreshing when going from one topic list to another --- assets/javascripts/discourse/components/google-dfp-ad.js.es6 | 2 +- .../discovery-list-container-top/discourse-adplugin.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index e8bb23d..1fcf4e1 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -197,7 +197,7 @@ export default Ember.Component.extend({ var self = this; - if (this.get('loadedGoogletag')) { + if (this.get('loadedGoogletag') && this.get('refreshOnChange')) { googletag.cmd.push(function() { ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : null); googletag.pubads().refresh([ad]); diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs index 62b7370..0400350 100644 --- a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs @@ -2,7 +2,7 @@ {{google-adsense placement="topic-list-top"}} {{/if}} {{#if siteSettings.dfp_topic_list_top_code}} - {{google-dfp-ad placement="topic-list-top" category=category.slug}} + {{google-dfp-ad placement="topic-list-top" refreshOnChange=loading category=category.slug}} {{/if}} {{#if siteSettings.amazon_topic_list_top_src_code}} {{amazon-product-links placement="topic-list-top"}}