Add support for showing ad after every nth post, not only after the nth post
This commit is contained in:
parent
cee3f66009
commit
e4405dd486
|
@ -55,15 +55,13 @@ function custom_targeting(key_array, value_array, location) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function defineSlot(placement, settings, isMobile) {
|
function defineSlot(divId, placement, settings, isMobile) {
|
||||||
var ad, width, height, divId;
|
var ad, width, height;
|
||||||
|
|
||||||
if (ads[placement]) {
|
if (ads[divId]) {
|
||||||
return ads[placement];
|
return ads[divId];
|
||||||
}
|
}
|
||||||
|
|
||||||
divId = "div-gpt-ad-" + placement;
|
|
||||||
|
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
// There are no settings for customizing the mobile ad sizes.
|
// There are no settings for customizing the mobile ad sizes.
|
||||||
width = 320;
|
width = 320;
|
||||||
|
@ -113,8 +111,8 @@ function defineSlot(placement, settings, isMobile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ad) {
|
if (ad) {
|
||||||
ads[placement] = {ad: ad, width: width, height: height};
|
ads[divId] = {ad: ad, width: width, height: height};
|
||||||
return ads[placement];
|
return ads[divId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +155,12 @@ export default Ember.Component.extend({
|
||||||
refreshOnChange: null,
|
refreshOnChange: null,
|
||||||
|
|
||||||
divId: function() {
|
divId: function() {
|
||||||
return "div-gpt-ad-" + this.get('placement');
|
if (this.get('postNumber')) {
|
||||||
}.property('placement'),
|
return "div-gpt-ad-" + this.get('placement') + '-' + this.get('postNumber');
|
||||||
|
} else {
|
||||||
|
return "div-gpt-ad-" + this.get('placement');
|
||||||
|
}
|
||||||
|
}.property('placement', 'postNumber'),
|
||||||
|
|
||||||
adUnitClass: function() {
|
adUnitClass: function() {
|
||||||
return "dfp-ad-" + this.get("placement");
|
return "dfp-ad-" + this.get("placement");
|
||||||
|
@ -177,7 +179,7 @@ export default Ember.Component.extend({
|
||||||
}.property('trust_level'),
|
}.property('trust_level'),
|
||||||
|
|
||||||
refreshAd: function() {
|
refreshAd: function() {
|
||||||
var slot = ads[this.get('placement')];
|
var slot = ads[this.get('divId')];
|
||||||
if (!(slot && slot.ad)) { return; }
|
if (!(slot && slot.ad)) { return; }
|
||||||
|
|
||||||
var self = this,
|
var self = this,
|
||||||
|
@ -196,7 +198,7 @@ export default Ember.Component.extend({
|
||||||
loadGoogle(this.siteSettings).then(function() {
|
loadGoogle(this.siteSettings).then(function() {
|
||||||
self.set('loadedGoogletag', true);
|
self.set('loadedGoogletag', true);
|
||||||
window.googletag.cmd.push(function() {
|
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) {
|
if (slot && slot.ad) {
|
||||||
slot.ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : '0');
|
slot.ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : '0');
|
||||||
self.set('width', slot.width);
|
self.set('width', slot.width);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{{#if postSpecificCountAdsense}}
|
{{#if postSpecificCountAdsense}}
|
||||||
{{google-adsense placement="post-bottom"}}
|
{{google-adsense placement="post-bottom" postNumber=post_number}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if postSpecificCountDFP}}
|
{{#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}}
|
||||||
{{#if postSpecificCountAmazon}}
|
{{#if postSpecificCountAmazon}}
|
||||||
{{amazon-product-links placement="post-bottom"}}
|
{{amazon-product-links placement="post-bottom" postNumber=post_number}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -8,16 +8,24 @@ export default {
|
||||||
|
|
||||||
PostModel.reopen({
|
PostModel.reopen({
|
||||||
postSpecificCountDFP: function() {
|
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'),
|
}.property('post_number'),
|
||||||
|
|
||||||
postSpecificCountAdsense: function() {
|
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'),
|
}.property('post_number'),
|
||||||
|
|
||||||
postSpecificCountAmazon: function() {
|
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'),
|
}.property('post_number'),
|
||||||
|
|
||||||
|
isNthPost: function(n) {
|
||||||
|
if (n && n > 0) {
|
||||||
|
return (this.get('post_number') % n) === 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
withPluginApi('0.1', api => {
|
withPluginApi('0.1', api => {
|
||||||
|
|
Loading…
Reference in New Issue