Fixing Google AdSense Ads.txt Warnings
I'm a pretty lightweight Google Adsense user, having a couple of sites that have the ads running to support some older projects and hosted community systems that have been online for 10-15 years. Checking on my account today I noticed a new bright red banner at the top of the pageletting me know that my earnings were at risk, and that I needed to fix "some" ads.txt issues on my sites.
Around 2017 the IAB introduced ads.txt as a standard for granting permission to digital advertisers to run inventory on a site. I can be all too easy to have user-generated HTML or JS find its way onto a site and suddenly start monetizing pages without approval. Google have also stepped their site verification for AdSense up significantly - in years past, adding the code was enough to begin running inventory - a site I added this year required a manual verification and actually failed for being too shallow initially!
Steps To Fix ads.txt Issues
If you don't have sites on subdomains of your site, the fix for the warning is straightforward. Google offer to let you download a pre-filled ads.txt file (assuming you only run their inventory). Simply upload this to your website root and the message will dissapear in a few days.
Alternatively, create a text file with the following content, replacing your root domain and AdSense publisher ID instead of the example values here. You should leave the ID at the end alone, that's Google AdSense's program identifier.
example.com, pub-0123123123123123, DIRECT, f08c47fec0942fa0
If you do use subdomains in your site, you have a choice to make:
If you don't put an ads.txt in the root of a subdomain, but do have one for the site at the root of your domain, then the one for your domain will be used for all subdomains. e.g. if there is no ads.txt at forum.example.com, the ads.txt at example.com will be used.
If you want a subdomain to have it's own ads.txt file, you need to identfiy the subdomain in your root domain's ads.txt using the subdomain feature and then put the relevant ads permissions in the subdomain's ads.txt e.g.
# Ads.txt for example.com (example.com/ads.txt) example.com, pub-0123123123123123, DIRECT, f08c47fec0942fa0 subdomain = forum.example.com
# Ads.txt for forum.example.com (forum.example.com/ads.txt) forum.example.com, pub-0123123123123123, DIRECT, f08c47fec0942fa0
Section 4.5 of the IAB's spec for Ads.txt has all the gory details about subdomain handling if you're curious.
Hopefully this helps anyone out there wanting to quickly put their sites back into compliance, preventing any lost revenue.