FEATURE: new setting to disable ads based on category of current page
Use the "no ads for categories" setting to define which category pages (topic list and topics) should not render any ads.
This commit is contained in:
parent
f745ecfbdc
commit
7af8f1d46b
|
@ -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;
|
||||
|
|
|
@ -128,7 +128,8 @@ export default AdComponent.extend({
|
|||
showAd: Ember.computed.and(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost"
|
||||
"showAfterPost",
|
||||
"showOnCurrentPage"
|
||||
),
|
||||
|
||||
init() {
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 <a href='https://support.google.com/adsense/answer/7532444?hl=en' target='_blank'>this Google AdSense help page</a>."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue