Ads.txt Delegation

HTL BID can host your ads.txt file for you.

Once configured, this allows your ads.txt file to be updated immediately through the HTLBID user interface, without requiring a code deployment from your team.

image

The “hosted ads.txt url” is the location of the hosted ads.txt file on our CDN.

💡
NOTE that HTL BID does not automatically generate the contents of your ads.txt file.

There are two ways to configure this on your webserver:

  • Proxy Method
  • Redirect Method

Both techniques are valid and can work in most situations. The Proxy method is simpler to implement correctly.

Proxy Method

Configure your webserver as a proxy. Instead of issuing a redirect, the proxy method uses your webserver to fetch content from the HTL BID CDN on the user’s behalf. There are multiple ways to configure this. Which method is simplest depends on your web stack and server configuration.

PHP example using the proxy method

<?php
$remote_url = 'https://htlbid.com/v3/example.com/ads.txt';
$content = file_get_contents($remote_uRL);
header('Content-Type: text/plain');
echo $content;
?>

NodeJS example using the proxy method

const express = require('express');
const axios = require('axios');
const app = express();

app.get('/ads.txt', async (req, res) => {
  try {
    const response = await axios.get('https://htlbid.com/v3/example.com/ads.txt');
    const adsTxtContent = response.data;
    
    res.set('Content-Type', 'text/plain');
    res.send(adsTxtContent);
  } catch (error) {
    console.error('Error fetching ads.txt content:', error);
    res.status(500).send('Error fetching ads.txt content');
  }
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Apache with mod_proxy example using the proxy method

# enable the necessary modules
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

# configure the proxy
ProxyPass "/ads.txt" "https://htlbid.com/v3/example.com/ads.txt"
ProxyPassReverse "/ads.txt" "https://htlbid.com/v3/example.com/ads.txt"

Nginx example using the proxy method

server {
  listen 443;
  server_name example.com;

  location /ads.txt {
    proxy_pass http://different-server.com/path/to/ads.txt;
    proxy_set_header Host different-server.com;
  }

  # ... other server configuration ...
}

Redirect Method

Configure your webserver to perform an HTTP 301 redirect from https://example.com/ads.txt to your ads.txt file hosted on the HTL BID CDN.

There are many ways to do this, depending on your web stack and server configuration . The sample code below shows some examples to provide inspiration, but adjustments may be required depending on your specific configuration.

PHP example using redirect method

<?php
$new_url = 'https://htlbid.com.com/v3/example.com/ads.txt';
header('Location: ' . $new_url, true, 301);
exit;
?>

NodeJS / Express example using redirect method

const express = require('express');
const app = express();

app.get('/ads.txt', (req, res) => {
  res.redirect(301, 'https://htlbid.com/v3/example.com/ads.txt');
});

const port = 3000;
app.listen(port, () => {
  console.log(`Server listening on port ${port}`);
});

Apache with mod_rewrite example using redirect method

RewriteEngine On
RewriteRule ^ads.txt$ https://htlbid.com.com/v3/example.com/ads.txt [R=301,L]

Nginx example using redirect method

server {
  listen 80;
  server_name example.com;

  location /ads.txt {
    return 301 https://htlbid.com/v3/examepl.com/ads.txt;
  }

  # ... other server configuration ...
}

Handling HTTP vs HTTPS and WWW vs non-WWW

Your server should be configured so that each of these URLs serves identical ads.txt content, with the other 3 of the URLs redirecting to the primary URL.

  • http://example.com/ads.txt
  • https://example.com/ads.txt
  • http://www.example.com/ads.txt
  • https://www.example.com/ads.txt

Some ads.txt bots are not very smart. The best way to ensure your ads.txt file is read correctly is to serve it from all 4 locations.

Limit to 1 redirect

The IAB Ads.txt Specification specifies a limit of 1 redirect.

  • Multiple redirects are not allowed

If you are using the Redirect method, use the Chrome dev tools to check your configuration and ensure that a maximum of 1 redirect is used. (if you are using the Proxy method, there should be no redirects)

image

Ads.txt and GAM

Verify in Google Ad Manager that your ads.txt is valid and read correctly by Google.

  • Login to Google Ad Manager
  • Navigate to Admin > Ads.txt Configuration
image

Troubleshooting Ads.txt

The best way to verify your ads.txt implementation is to use an ads.txt validator. These tools can verify that your ads.txt file is correctly formatted and can be parsed successfully by ads.txt bots.

Wrong mime type

Ads.txt should be served with the mime-type: text/plain

Too many redirects

Ads.txt files should be served with a maximum for 1 redirect

Multiple redirects due to HTTP ⇒ HTTPS

A common causes of multiple redirects is that a webserver may be configured to redirect

Which results in 2 redirects, first from HTTP ⇒ HTTPS, and then to htlbid.com

The exact fix is specific to your web server configuration, but will typically involve reordering or prioritizing rules to ensure that the ads.txt redirect rule is triggered before the HTTP ⇒ HTTPS rule.

Multiple redirects due to WWW

Some web servers are configured to automatically add “www” to all URLs. This can result in the following:

Similar to the HTTP ⇒ HTTPS issue above, this configuration causes multiple redirects. The exact fix is specific to your web server configuration, but will typically involve reordering or prioritizing rules to ensure that the ads.txt redirect rule is triggered before the WWW rule.

Incorrect IDs

Using the wrong IDs hurts monetization

Invalid Encoding

In rare cases, ads.txt files will be published without newlines, or including special characters, or with other non-standard formatting. If the bots cannot successfully parse the ads.txt file content, it will be ignored

Invalid HTTP response code

Ensure the ads.txt file is served with a HTTP 200 status code

Blocking Ads.txt Bots

Your webserver or CDN may be blocking ads.txt bots. Ensure that your ads.txt file is not blocked in robots.txt, and that your web server, firewall and CDN are not blocking access to the ads.txt file.

Caching

If your webserver or CDN caches the ads.txt file, this may cause inconsistent behavior. In some cases, the server configuration may serve 2x redirects when the cache is empty (cache miss), but server 1x redirect when the cache contains the ads.txt file (cache hit). This means that whether or not a bot succeeds in reading the ads.txt file can depend on luck and whether the bot receive a cache hit or cache miss.

Further References

Google - Ensure your ads.txt can be crawled