diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 66120a0..c746f10 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -55,15 +55,13 @@ function custom_targeting(key_array, value_array, location) { } } -function defineSlot(placement, settings, isMobile) { - var ad, width, height, divId; +function defineSlot(divId, placement, settings, isMobile) { + var ad, width, height; - if (ads[placement]) { - return ads[placement]; + if (ads[divId]) { + return ads[divId]; } - divId = "div-gpt-ad-" + placement; - if (isMobile) { // There are no settings for customizing the mobile ad sizes. width = 320; @@ -113,8 +111,8 @@ function defineSlot(placement, settings, isMobile) { } if (ad) { - ads[placement] = {ad: ad, width: width, height: height}; - return ads[placement]; + ads[divId] = {ad: ad, width: width, height: height}; + return ads[divId]; } } @@ -157,8 +155,12 @@ export default Ember.Component.extend({ refreshOnChange: null, divId: function() { - return "div-gpt-ad-" + this.get('placement'); - }.property('placement'), + if (this.get('postNumber')) { + return "div-gpt-ad-" + this.get('placement') + '-' + this.get('postNumber'); + } else { + return "div-gpt-ad-" + this.get('placement'); + } + }.property('placement', 'postNumber'), adUnitClass: function() { return "dfp-ad-" + this.get("placement"); @@ -177,7 +179,7 @@ export default Ember.Component.extend({ }.property('trust_level'), refreshAd: function() { - var slot = ads[this.get('placement')]; + var slot = ads[this.get('divId')]; if (!(slot && slot.ad)) { return; } var self = this, @@ -196,7 +198,7 @@ export default Ember.Component.extend({ loadGoogle(this.siteSettings).then(function() { self.set('loadedGoogletag', true); window.googletag.cmd.push(function() { - let slot = defineSlot(self.get('placement'), self.siteSettings, self.site.mobileView); + let slot = defineSlot(self.get('divId'), self.get('placement'), self.siteSettings, self.site.mobileView); if (slot && slot.ad) { slot.ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : '0'); self.set('width', slot.width); 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 9da8203..b922b5a 100644 --- a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs @@ -1,9 +1,9 @@ {{#if postSpecificCountAdsense}} - {{google-adsense placement="post-bottom"}} + {{google-adsense placement="post-bottom" postNumber=post_number}} {{/if}} {{#if postSpecificCountDFP}} - {{google-dfp-ad placement="post-bottom" category=topic.category.slug}} + {{google-dfp-ad placement="post-bottom" category=topic.category.slug postNumber=post_number}} {{/if}} {{#if postSpecificCountAmazon}} - {{amazon-product-links placement="post-bottom"}} + {{amazon-product-links placement="post-bottom" postNumber=post_number}} {{/if}} diff --git a/assets/javascripts/initializers/initialize-ad-plugin.js.es6 b/assets/javascripts/initializers/initialize-ad-plugin.js.es6 index e9ab83c..1b6d473 100644 --- a/assets/javascripts/initializers/initialize-ad-plugin.js.es6 +++ b/assets/javascripts/initializers/initialize-ad-plugin.js.es6 @@ -8,16 +8,24 @@ export default { PostModel.reopen({ postSpecificCountDFP: function() { - return this.get('post_number') === parseInt(siteSettings.dfp_nth_post_code); + return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code)); }.property('post_number'), postSpecificCountAdsense: function() { - return this.get('post_number') === parseInt(siteSettings.adsense_nth_post_code); + return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code)); }.property('post_number'), postSpecificCountAmazon: function() { - return this.get('post_number') === parseInt(siteSettings.amazon_nth_post_code); + return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code)); }.property('post_number'), + + isNthPost: function(n) { + if (n && n > 0) { + return (this.get('post_number') % n) === 0; + } else { + return false; + } + } }); withPluginApi('0.1', api => {