Continuing the discussion from Advertising Plugin for Discourse - Serve Ads on your Discourse Forum (Official Endorsed):
So… it would be great if the Advertising Plugin for Discourse has got the option to show/hide ads for specific user group.
The discussion revolves around adding group-based ad visibility options to the Advertising Plugin for Discourse. Users SidV, marianord, and FoohonPie request the ability to hide ads for specific user groups, such as Patreon supporters, to enhance user experience. bartv proposes a workaround using JavaScript to add group classes to the body tag and CSS to hide ads, but Stephen warns that this violates AdSense policies. Falco notes that user groups are now included by default, simplifying the process. rishabh confirms that the feature may already exist, pointing to a UI option for disabling ads for certain groups.
Continuing the discussion from Advertising Plugin for Discourse - Serve Ads on your Discourse Forum (Official Endorsed):
So… it would be great if the Advertising Plugin for Discourse has got the option to show/hide ads for specific user group.
I’m in with this feature request, I’m starting to use Patreon and I’d like to offer a tier with no ads in the site. Would this feature be too difficult to implement?
This is also what I came looking for. I’ll probably grant relevant trust to patreon subs until then, but that does indeed feel inappropriate.
It would be great to get some feedback from the developers of this plugin. If it’s not on the roadmap I’m willing to sponsor the development of this feature.
Any update?
I’m just thinking… there is no javascript code to “detect” the user group for hide the ads by DOM? ![]()
I’ve achieved this with the following code that adds the users’s groups to the body tag:
<script>
// https://meta.discourse.org/t/css-classes-for-group-membership-for-simplified-ui-mode/60838/2
if (window.jQuery) {
window.jQuery(function ($) {
var u = Discourse.User.current();
if (u !== null){
u.findDetails().then(function(u) {
// console.log(u.groups);
var arrayLength = u.groups.length;
for (var i = 0; i < arrayLength; i++) {
$('body').addClass('group-'+u.groups[i].name);
}
});
}
});
};
</script>
This code performs one additional call to the Discourse API to fetch the group information, but only once during the initial page load so the impact is minimal.
Next, target the right groups in CSS and hide banners for them:
/* remove ads for Patreon supporters */
.group-patreon-casual .google-adsense,
.group-patreon-commercial .google-adsense,
.group-patreon-serious .google-adsense {
display:none;
}
I’d love to disable ads for certain categories of my forum!
Forgot to say this at the time, but this is a clear breach of AdSense policy and can end up with you losing your account:
- Hiding ad units at anytime (e.g.,
display:none), unless you’re implementing a responsive ad unit
Source: modification of AdSense code
We now ship the current user groups by default, so the code can be simplified a lot @bartv.
Also makes it easy if anyone really wants this feature and craft a PR that allows groups to not even run ad code.