Official Advertising / Ad Plugin for Discourse

:warning: IF YOU ARE RUNNING AN AD BLOCKER RIGHT NOW YOU WILL HAVE A VERY BAD TIME TRYING TO SET THIS UP! TURN IT OFF BEFORE PROCEEDING DOWN THIS PATH! You’ve been warned. :dragon:

This is the officially supported Discourse ad plugin. Install and configure it to start serving ads on your Discourse forum.

The plugin supports the following ad platforms :

Install the Plugin

If your site is hosted by us, the Discourse Advertising Plugin is pre-installed on all our hosting plans. There is nothing that you need to do to install the plugin.

For self-hosted sites, follow our plugin installation guide to install the plugin from https://github.com/discourse/discourse-adplugin.

Setting up House Ads

If you don’t want to use an external ad platform, but want to show your own ads, then House Ads are for you! Define your ads by going to the Admin section of your Discourse forum, and go to the Plugins section. On the left, you should see a link called “House Ads”.

Begin by creating your ads. Give each a short descriptive name and enter the html for each. Style them using a custom theme (Admin > Customize > Themes). Lastly, click the Settings button in the House Ads UI and choose which of your ads to show in each of the ad slots. The ads will start showing as soon as you add them to slots.

Configure Ads For Your Advertisement Platform

  • Navigate to the Admin section in your Discourse forum.
  • Click on Settings and a left vertical navigation bar should appear.
  • Choose your advertisement platform.
    • House Ads - if you want to create and serve ads from your Discourse instance.
    • Adsense - if using Adsense as your advertisement platform.
    • DFP - if using the DoubleClick for Publishers advertisement platform.
    • Carbon Ads - if using the Carbon Ads advertisement platform.
    • AdButler - if using the AdButler advertisement platform.

Input Your Details

  1. Add in your publisher ID - your publisher ID can be obtained from your ad platform and can also be found in your ad tag (see pictures below).
  2. Choose your trust level from the dropdown box. This will only display ads to users with a certain level of trust. For more details about trust levels go to the Plugin Features heading.
  3. Get the Advertisement Tag from your Ad Platform - see the images below to see what a tag looks like.
  4. Add parts of your ad code to Discourse’s site settings for the locations you wish your ad to appear. Refer to image for your ad platform to where parts of your ad tag should go. For more detail about where the ad will appear
  5. Choose Your Ad Size - this is the same size that you’ve put into your ad provider to create your ad. Go to the Plugin Features heading to see a list of supported Ad sizes.

Adsense Advertisement Tag to Discourse’s Site Settings

First, add the contents of your ads.txt file to your Discourse ads txt site setting. Then copy the following values to your Discourse settings:

DoubleClick for Publishers’ Advertisement Tag to Discourse’s Site Settings

Amazon Affiliates’ Advertisement Tag to Discourse’s Site Settings

Only for Product Link and Banner Ads.

Carbon Ads Script Tag to Discourse’s Site Settings

AdButler Ads Zone URL to Discourse’s Site Settings

This plugin only support AdButler “Standard Zones”. Text and VAST are not supported.

If you browse to a zone in the AdButler admin, then you can find the Publisher ID (PPPPPP) and the Zone ID (ZZZZZZ) in the URL of your browser’s address bar:

https://admin.adbutler.com/?ID=PPPPPP&p=textadzone.view&zoneID=ZZZZZZ

Configure the ads in Admin > Settings > AdButler. Enter the publisher id in the “adbutler publisher id” setting, and enter the Zone IDs in the different zone id settings as desired.

By default, ads are assumed to be size 728 x 90, or 320 x 50 in mobile view. To use different size ads, customize using CSS in your site’s theme. Override the following CSS:

.adbutler-ad { width: 728px; height: 90px; } .adbutler-mobile-ad { width: 320px; height: 50px; }

View Your Ad

Once you’ve configured your settings and your advertising platform has ads that are ready to serve, navigate to the page where you’ve inputted for the location and you should see ads.

Plugin Features

In this section, we go into more detail on:

  • Available Locations for Ad Display
  • Trust Levels
  • Personal messages
  • Groups
  • Categories
  • Tags

Available Locations for Ad Display

The following are available locations along with a description and an image showing their location within Discourse to display ads for all platforms.

Location Name Description
Topic List Top Ad will appear at the header of Discourse homepage
Topic Above Post Stream Ad will appear in the header of all Discourse forum topics
Topic Above Suggested Ad will appear in the footer above suggested topics of all Discourse forum topics
Post Bottom & Nth Post Ad will appear on the stipulated nth post within a topic. So if you have 5 posts in a topic and you want the ad to display after on the 2nd post, put 2 in ad_platform_nth_post_code .

Trust Levels

You can use the ad_platform_through_trust_level dropdown to disable ads for users above a certain trust levels. As a guide, choosing:

  • 0 shows ads to users that are not logged in.
  • 1 shows ads to users that are not logged in, and to new and basic users.
  • 2 shows ads to members as well, but not to regulars and leaders.
  • 3 shows ads to everyone, but not to leaders.
  • 4 shows ads to everyone including leaders.

To find more about trust levels in Discourse, refer to Discourse’s posts on trust levels

Personal messages

By default, ads won’t be shown in personal messages. To enable ads in personal messages, use the “no ads for personal messages” setting.

Groups

To give some users an ad-free experience, put the users in groups and add those groups to the “no ads for groups” setting.

Categories

To disable ads in certain categories, add them to the “no ads for categories” setting. Also consider using the “no ads for restricted categories” to disable ads in all categories that have read access restrictions.

Tags

Individual topics can have ads disabled by using tags, and entering those tags in the “no ads for tags” setting. This is useful if some topics violate ad network policies.

Fixing Content Security Policy Issues

If your site uses an advertising service (like Google Ad Manager, Adsense, etc.) you probably will have to use a very permissive policy:

In the screenshot above, the policy allows any script from a https: source and any inline script. (In the future, this might be replaced by the strict-dynamic keyword, but as of this writing, strict-dynamic isn’t supported by Safari or Edge.)

50 Likes

I was able to get responsive ads in AdSense working on desktop. An example of a responsive ad that filled the width:

I’ll do mobile next. (For some reason the plugin hard-codes a size of 320x50 on mobile for all AdSense ads…)

But DFP… :cry:

Support for truly responsive ads doesn’t exist. You always needs to specify the size of ads in two places: your javascript via defineSlot, and in your DFP ad unit definitions. There are ways to kinda add support for responsive ads, but it means your javascript needs to define a list of all the ad sizes you want to allow at which viewport widths. Surely you should be able to set this list when you define the ad units in DFP, so I don’t understand why you need to define them again in your javascript…

So, the solution for DFP going forward is one of these:

  • Keep adding more values to the lists of ad sizes
  • Remove the lists and change the settings so you enter the arbitrary dimensions you want. (Not sure how to migrate existing DFP users to new settings…)
9 Likes

Getting error: Failed to load resource: the server responded with a status of 400 ()

How to resolve this?

1 Like

400 Bad Request can indicate that your DFP publisher ID is wrong. In your DFP console, go to Admin > Global Settings > All network settings and find the number in “Network code”. Mine is 9 digits long.

Also it could mean the ad size that DFP is trying to serve is larger than the ad unit you’ve defined in your Discourse settings. DFP refuses to serve ads that will be cropped.

2 Likes

To do responsive properly with JS and defineSlot, can you please provide the following @neil? Thanks in advance!

  1. List of Discourse viewport widths
  2. List of ALL the different URLS where the ads can appear.
    For example, “dfp topic list top code desktop” & “dfp mobile topic list top code” appear at “/” and “/c” (from what I can tell but I’m 100% sure). We need this so we can create “zones” to map our tags in the JS properly.
  • dfp topic list top code
  • dfp mobile topic list top code
  • dfp topic above post stream code
  • dfp mobile topic above post stream code
  • dfp topic above suggested code
  • dfp mobile topic above suggested code
  • dfp post bottom code
  • dfp mobile post bottom code

@Brock_Busby I think all the widths are in the main mixins.scss file.

All the urls is all the topic list pages. (e.g., /latest, /unread, etc.), and any topic page (/t/topic-slug/123).

I’m curious what you’re going to do to get it working. :thinking:

6 Likes

Appreciate it @neil ! We are going to attempt to do proper responsive using JS like on our regular site FTW.in.
I’ll come back once we try it out on our test server.

1 Like

Does it work with Native In-Feed and In-Article Ad blocks?

Status don’t change for Native type blocks…
image

1 Like

Status 400 (bad request) is coming from AdSense, and means you need to wait until Adsense approves your new ad units or has some ads to show. It’s hard to say why Adsense is rejecting the request.

6 Likes

Wow…this works.
Thanks @Steven and @pfaffman for the tips.

1 Like

If you see the ad code when you inspect the page, then the plugin has done its job.

3 Likes

Ad language question

Will Adsense adverts be shown in the user’s browser default language? Is it on auto by Google or configurable?

It’s the advertiser’s choice. When setting up ads via AdWords or other networks, an advertiser will select the audience by geographic location, demographics, language, or myriad other targeting options the network might allow. That makes sense because serving ads to an audience that can’t understand the ad or act upon it is a waste of money.

In Google AdSense you can allow or block ads via its Ad review center, which I find useful for eliminating deceptive ads, such as those with a big button that says “Start Download” — especially if they might appear on a document sharing page. A good portion of my users are not computer tech-savvy, so this is a big deal.

5 Likes

I’m adding a Patreon integration to my site and would like to offer Patreons a banner-free site. Is there a way to disable banners for a specific user group? (Or maybe better, multiple groups?)

4 Likes

You can do it by trust level:

3 Likes

I’m aware you can set the trust level, but that’s not the same thing - members shouldn’t be able to ‘buy’ a trust level by becoming a Patreon. It would be much ‘cleaner’ if I could set a user group, right?

4 Likes

Yes, that would be a nice feature, but I don’t think it’s available out f the box. As a workaround, you could assign automatic trust levels to the Patreon group, but that too is not as clean as specifying a group in the ad plugin, and it goes against “buying trust.”

It’s currently not an option, but sounds like a good idea to me.

6 Likes

If anyone of you have added Amazon banner links using this plugin, please tell me how to get the code?
I have an Amazon Associates account, but I’m finding it really hard to find the iframe link.
I can find just JS code on their site.

Please help me :frowning:

Screenshot

@itsbhanusharma

Here’s how to use Amazon affiliate links.

Find the ad unit you want to use in the Amazon Affiliate website. I’ll use a banner.

You’ll need three values from it. The src, width, and height. Put those values in you Amazon settings in Discourse.

Reload your browser and go to wherever you added the Amazon ad unit.

The code is in the src. Something like this:

//rcm-na.amazon.com/e/cm?o=1&p=......&tracking_id=myid

4 Likes