How to Setup Google Adsense in Discourse


Once you have a good traffic discourse website, the next step to bring up some revenue is by setting up advertisements on your website.

This article describes the steps to configure google AdSense advertisement in Discourse website.


  1. Approved Google Adsense account
  2. Approve website in Google Adsense account.

Install Official Discourse Ad Plugin

In /var/discourse/containers/app.yaml add the following lines under the after_code hooks section.

$ cd /var/discourse
$ sudo vi app.yaml
    - exec:
        cd: $home/plugins
          - git clone 
git pull
sudo ./launcher rebuild app

Configure Content Security Policy To Load Google Ads

Discourse by default blocks loading resources from other hosts. This will block loading ads from the Google AdSense domain. You may notice the below error in network logs in such cases.

Content Security Policy: The page’s settings blocked the loading of a resource at (“script-src”).

To enable resources from google Adsense hosts in Discourse, search for content security policy script src on the Settings page or Navigate to the Security section on the Settings page.

Add the following values to the content security policy script src parameter.

  1. 'unsafe-inline'
  2. https

Configure Adsense In Discourse

Once the build is completed, log in to your discourse admin dashboard and navigate to the Settings tab and search for Adsense.

Fill in the AdSense publisher code and Ad unit details.

Note: Exlclude pub- from the Adsense Published ID while entering.

The Published ID will be available on the Accounts page of your Google Adsense account.

The ad code can be obtained from the ad embed code in the Google Adsense ad unit setting page.

For example, from the google ad embed code below, the code to be entered in discourse is x8082xxxxx

<script async src=""
<!-- -->
<ins class="adsbygoogle"
     (adsbygoogle = window.adsbygoogle || []).push({});
Note that it might take a while for the advertisement to appear on your website. Till then, you will just see a placeholder text  'ADVERTISEMENT'