All web admins know that just about every advertiser requires the ads.txt
file if they want optimal rates for publishing ads.
The official discourse plugin offers ads.txt
support; but what happens if you are running your own ad code in a template component or simple theme modification?
Well, there is a very easy way to do it; and here it is:
Let's say you are running the Discourse standard install app
with standard shared volume at the location:
/var/discourse/shared/standalone
Simple copy your ads.txt
file to this shared directory, so it looks like this:
/var/discourse/shared/standalone/ads.txt
Then add this line to the bottom of your app.yml
file in the run section:
run:
- exec: echo "Beginning of custom commands"
- exec: cp /shared/ads.txt /var/www/discourse/public
- exec: echo "End of custom commands"
Now, when you rebuild your container your ads.txt
file will work perfectly without the need for a plugin and you can run any custom ad tag you want directly by adding an <iframe>
ad tag to the theme.
Because ads.txt
generally does not need to change often, the method will work for most people.
Let's say you get a new ad client, you run a single container configuration, and your client wants you to update your ads.txt
file; you can manually add the entry to your ads.txt
file in the container at location:
/var/www/discourse/public/ads.txt
and you can also update your staged version of ads.txt
so the next time you rebuild your container, you will not need to manually edit the file in the container:
/var/discourse/shared/standalone/ads.txt
If you run multiple containers behind a reverse proxy like we do, this is not an issue at all, because rebuilding and launching a new container and switching it over live takes zero downtime anyway.
In a nutshell, it is really easy to run ads.txt
in this manner, or you can use the official Discourse plugin if that works best for you!
Questions or Comments?