# Add group options to Advertising Plugin

**URL:** https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768
**Category:** Support
**Tags:** advertising
**Created:** [May 4, 2018, 3:17pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768 "2018-05-04T15:17:49Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [May 4, 2018, 3:17pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/1 "2018-05-04T15:17:50Z")

</div>

Continuing the discussion from [Advertising Plugin for Discourse - Serve Ads on your Discourse Forum (Official Endorsed)](https://meta.discourse.org/t/advertising-plugin-for-discourse-serve-ads-on-your-discourse-forum-official-endorsed/33734/180):

> [@Discourse Advertising Plugin (Ads)](https://meta.discourse.org/t/discourse-advertising-plugin-ads/33734/64):
>
> Just wondering. Is there a way to hide ads from specific user group? Regardless of user trust level.

So… it would be great if the Advertising Plugin for Discourse has got the option to show/hide ads for specific user group.

---

<div class="post-metadata">

### Author: ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)
#### Post date: [June 26, 2018, 8:13pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/2 "2018-06-26T20:13:37Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![FoohonPie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/foohonpie/32/119648_2.png) [@FoohonPie](https://meta.discourse.org/u/FoohonPie)
#### Post date: [August 19, 2018, 8:17pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/3 "2018-08-19T20:17:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [August 21, 2018, 12:05pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/4 "2018-08-21T12:05:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [November 24, 2018, 11:09pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/7 "2018-11-24T23:09:55Z")

</div>

Any update?

I’m just thinking… there is no javascript code to “detect” the user group for hide the ads by DOM? 🤔

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [November 25, 2018, 7:46am UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/8 "2018-11-25T07:46:52Z")

</div>

I’ve achieved this with the following code that adds the users’s groups to the body tag:

```plaintext
<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:

```plaintext
/* remove ads for Patreon supporters */
.group-patreon-casual .google-adsense,
.group-patreon-commercial .google-adsense,
.group-patreon-serious .google-adsense {
	display:none;
}

```

---

<div class="post-metadata">

### Author: ![ShanniiWrites](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shanniiwrites/32/133910_2.png) [@ShanniiWrites](https://meta.discourse.org/u/ShanniiWrites)
#### Post date: [April 9, 2019, 5:38pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/9 "2019-04-09T17:38:36Z")

</div>

I’d love to disable ads for certain categories of my forum!

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [April 9, 2019, 5:53pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/10 "2019-04-09T17:53:13Z")

</div>

> [@bartv](#):
>
> Next, target the right groups in CSS and hide banners for them:

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](https://support.google.com/adsense/answer/6307124#hide)

Source: [modification of AdSense code](https://support.google.com/adsense/answer/1354736?hl=en)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [April 9, 2019, 6:08pm UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/11 "2019-04-09T18:08:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![rishabh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rishabh/32/179446_2.png) [@rishabh](https://meta.discourse.org/u/rishabh)
#### Post date: [May 3, 2021, 6:31am UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/12 "2021-05-03T06:31:14Z")

</div>

> [@SidV](#):
>
> option to show/hide ads for specific user group

I think the `no ads for groups` setting can do that now!

 ![image](https://global.discourse-cdn.com/meta/original/3X/d/2/d2445580af4bb5acc6d356cf1b27e29d0e0630df.png)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [June 2, 2021, 6:31am UTC](https://meta.discourse.org/t/add-group-options-to-advertising-plugin/86768/13 "2021-06-02T06:31:25Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
