diff --git a/assets/javascripts/discourse/components/ad-component.js.es6 b/assets/javascripts/discourse/components/ad-component.js.es6 index ced46dd..29be5f4 100644 --- a/assets/javascripts/discourse/components/ad-component.js.es6 +++ b/assets/javascripts/discourse/components/ad-component.js.es6 @@ -1,6 +1,13 @@ import computed from "ember-addons/ember-computed-decorators"; export default Ember.Component.extend({ + router: Ember.inject.service(), + + currentCategoryId: Ember.computed.or( + "router.currentRoute.attributes.category.id", + "router.currentRoute.parent.attributes.category_id" + ), + @computed("currentUser.groups") showToGroups(groups) { const currentUser = Discourse.User.current(); @@ -22,6 +29,17 @@ export default Ember.Component.extend({ return !groupNames.any(g => noAdsGroupNames.includes(g)); }, + @computed("currentCategoryId") + showOnCurrentPage(categoryId) { + return ( + !categoryId || + !this.siteSettings.no_ads_for_categories || + !this.siteSettings.no_ads_for_categories + .split("|") + .includes(categoryId.toString()) + ); + }, + isNthPost(n) { if (n && n > 0) { return this.get("postNumber") % n === 0; diff --git a/assets/javascripts/discourse/components/amazon-product-links.js.es6 b/assets/javascripts/discourse/components/amazon-product-links.js.es6 index 53e41c3..5471520 100644 --- a/assets/javascripts/discourse/components/amazon-product-links.js.es6 +++ b/assets/javascripts/discourse/components/amazon-product-links.js.es6 @@ -128,7 +128,8 @@ export default AdComponent.extend({ showAd: Ember.computed.and( "showToTrustLevel", "showToGroups", - "showAfterPost" + "showAfterPost", + "showOnCurrentPage" ), init() { diff --git a/assets/javascripts/discourse/components/carbonads-ad.js.es6 b/assets/javascripts/discourse/components/carbonads-ad.js.es6 index 6bd49d6..3d49d8c 100644 --- a/assets/javascripts/discourse/components/carbonads-ad.js.es6 +++ b/assets/javascripts/discourse/components/carbonads-ad.js.es6 @@ -28,8 +28,14 @@ export default AdComponent.extend({ ); }, - @computed("showToTrustLevel", "showToGroups") - showAd(showToTrustLevel, showToGroups) { - return placement && serve_id && showToTrustLevel && showToGroups; + @computed("showToTrustLevel", "showToGroups", "showOnCurrentPage") + showAd(showToTrustLevel, showToGroups, showOnCurrentPage) { + return ( + placement && + serve_id && + showToTrustLevel && + showToGroups && + showOnCurrentPage + ); } }); diff --git a/assets/javascripts/discourse/components/codefund-ad.js.es6 b/assets/javascripts/discourse/components/codefund-ad.js.es6 index 973157d..bacbc56 100644 --- a/assets/javascripts/discourse/components/codefund-ad.js.es6 +++ b/assets/javascripts/discourse/components/codefund-ad.js.es6 @@ -112,13 +112,19 @@ export default AdComponent.extend({ ); }, - @computed("showToTrustLevel", "showToGroups", "showAfterPost") - showAd(showToTrustLevel, showToGroups, showAfterPost) { + @computed( + "showToTrustLevel", + "showToGroups", + "showAfterPost", + "showOnCurrentPage" + ) + showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) { return ( this.siteSettings.codefund_property_id && showToTrustLevel && showToGroups && - showAfterPost + showAfterPost && + showOnCurrentPage ); }, diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6 index 3b31018..077679a 100644 --- a/assets/javascripts/discourse/components/google-adsense.js.es6 +++ b/assets/javascripts/discourse/components/google-adsense.js.es6 @@ -237,13 +237,19 @@ export default AdComponent.extend({ ); }, - @computed("showToTrustLevel", "showToGroups", "showAfterPost") - showAd(showToTrustLevel, showToGroups, showAfterPost) { + @computed( + "showToTrustLevel", + "showToGroups", + "showAfterPost", + "showOnCurrentPage" + ) + showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) { return ( this.siteSettings.adsense_publisher_code && showToTrustLevel && showToGroups && - showAfterPost + showAfterPost && + showOnCurrentPage ); }, diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 4e5a3ae..da99b75 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -234,13 +234,19 @@ export default AdComponent.extend({ return `width: ${w}px;`.htmlSafe(); }, - @computed("showToTrustLevel", "showToGroups", "showAfterPost") - showAd(showToTrustLevel, showToGroups, showAfterPost) { + @computed( + "showToTrustLevel", + "showToGroups", + "showAfterPost", + "showOnCurrentPage" + ) + showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) { return ( this.siteSettings.dfp_publisher_id && showToTrustLevel && showToGroups && - showAfterPost + showAfterPost && + showOnCurrentPage ); }, diff --git a/assets/javascripts/discourse/components/house-ad.js.es6 b/assets/javascripts/discourse/components/house-ad.js.es6 index d9a1470..dbb42de 100644 --- a/assets/javascripts/discourse/components/house-ad.js.es6 +++ b/assets/javascripts/discourse/components/house-ad.js.es6 @@ -22,9 +22,9 @@ export default AdComponent.extend({ return showAd ? `house-${placement}` : ""; }, - @computed("showToGroups", "showAfterPost") - showAd(showToGroups, showAfterPost) { - return showToGroups && showAfterPost; + @computed("showToGroups", "showAfterPost", "showOnCurrentPage") + showAd(showToGroups, showAfterPost, showOnCurrentPage) { + return showToGroups && showAfterPost && showOnCurrentPage; }, @computed("postNumber") diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index de0d297..6abdd51 100755 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,6 +1,7 @@ en: site_settings: no_ads_for_groups: "Don't show ads to users in these groups." + no_ads_for_categories: "Don't show ads on topic list and topic pages belonging to these categories." house_ads_after_nth_post: 'If "Between posts" house ads are defined, show an ad after every N posts, where N is this value.' house_ads_frequency: "If other ad networks are configured to show in an ad slot, how often should house ads be shown, as a percentage." ads_txt: "Contents of your ads.txt file. More details available at this Google AdSense help page." diff --git a/config/settings.yml b/config/settings.yml index f09c59c..9aec408 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -3,6 +3,10 @@ ad_plugin: client: true default: "" type: group_list + no_ads_for_categories: + client: true + default: "" + type: category_list house_ads_after_nth_post: client: true default: 20 diff --git a/test/javascripts/acceptance/house-ad-test.js.es6 b/test/javascripts/acceptance/house-ad-test.js.es6 index ada3188..4a0ba08 100644 --- a/test/javascripts/acceptance/house-ad-test.js.es6 +++ b/test/javascripts/acceptance/house-ad-test.js.es6 @@ -3,6 +3,7 @@ import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers"; acceptance("House Ads", { loggedIn: true, settings: { + no_ads_for_categories: "1", house_ads_after_nth_post: 6 }, site: { @@ -66,4 +67,28 @@ test("correct ads show", async assert => { 1, "it should render ad above topic list" ); + + await visit("/t/28830"); + assert.equal( + find(".h-above-post-stream").length, + 0, + "no ad above post stream because category is in no_ads_for_categories" + ); + assert.equal( + find(".h-post").length, + 0, + "no ad between posts because category is in no_ads_for_categories" + ); + assert.equal( + find(".h-above-suggested").length, + 0, + "no ad above suggested because category is in no_ads_for_categories" + ); + + await visit("/c/bug"); + assert.equal( + find(".h-topic-list").length, + 0, + "no ad above category topic list because category is in no_ads_for_categories" + ); });