• Facebook
  • Twitter
  • Instagram
  • YouTube
  • Linkedin
  • Pinterest
Monday, July 6, 2026
  • Login
  • Register
No Result
View All Result
NEWSLETTER
Mania Africa
MERCH
  • Home
  • News
    • Politics
    • Opinion
  • Sports
  • Movies
  • Tech
    • The Geekline
    • AI for WordPress
  • Lifestyle
  • About Us
    • Contact Us
  • Privacy Policy
    • Community Guidelines & Comment Policy
    • Cookies Policy
  • Advertise
  • Patreon
    • Merch
  • Home
  • News
    • Politics
    • Opinion
  • Sports
  • Movies
  • Tech
    • The Geekline
    • AI for WordPress
  • Lifestyle
  • About Us
    • Contact Us
  • Privacy Policy
    • Community Guidelines & Comment Policy
    • Cookies Policy
  • Advertise
  • Patreon
    • Merch
No Result
View All Result
Mania Africa
No Result
View All Result
  • Home
  • News
  • Sports
  • Movies
  • Tech
  • Lifestyle
  • About Us
  • Privacy Policy
  • Advertise
  • Patreon
ADVERTISEMENT
Home Mania Developers

How to Create an ads.txt Page with Cloudflare Workers

by davidmania
July 22, 2024
in Mania Developers, Mania Guides
1.9k 38
Donate
0
172709665666f1675053658 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.com
703
SHARES
10k
VIEWS
Share on FacebookShare on TwitterShare on WhatsAppShare on Reddit
ADVERTISEMENT

Contents

    • 0.1 RelatedPosts
    • 0.2 How to Monitor and Maintain a High-Performance WordPress Server (Without the Guesswork)
    • 0.3 The Ultimate Server-Side Caching Guide for WordPress: Redis, Varnish, and Cloudflare Enterprise Explained
    • 0.4 How Cloudways CoPilot Makes WordPress Server Troubleshooting Easier and Saves You Hours (at a Fraction of the Cost of Hiring a DevOp Engineer)
      • 0.4.1 Featured: Elevate Your Website’s Performance with Cloudways Cloud Hosting!
    • 0.5 What is ads.txt?
  • 1 Setting Up Cloudflare Workers
    • 1.1 Step 1: Create a Cloudflare Worker
    • 1.2 Step 2: Add the Code
    • 1.3 Explanation of the Code:
    • 1.4 Step 3: Deploy the Worker
    • 1.5 Step 4: Create a Worker Route
    • 1.6 Step 5: Testing the Worker
  • 2 Benefits of Using Cloudflare Workers for ads.txt
  • 3 Creating an ads.txt page with Cloudflare Summary
  • 4 Video: How to Setup your Ads.txt File Using Cloudflare Workers

RelatedPosts

How to Monitor and Maintain a High-Performance WordPress Server (Without the Guesswork)

The Ultimate Server-Side Caching Guide for WordPress: Redis, Varnish, and Cloudflare Enterprise Explained

How Cloudways CoPilot Makes WordPress Server Troubleshooting Easier and Saves You Hours (at a Fraction of the Cost of Hiring a DevOp Engineer)

In the world of digital advertising, transparency, and control are paramount for both publishers and advertisers. One effective tool to achieve this is the ads.txt file, which stands for Authorized Digital Sellers. This file helps ensure that your digital ad inventory is only sold through authorized sellers, mitigating the risk of fraud. This guide will walk you through the process of creating an ads.txt page using Cloudflare Workers, a powerful platform for running serverless code.

Featured: Elevate Your Website’s Performance with Cloudways Cloud Hosting!

Unlock the full potential of your website with Cloudways Cloud Hosting!

ADVERTISEMENT

Experience lightning-fast speeds, ironclad security, and seamless scalability. With our user-friendly platform, you can easily manage your applications and servers, ensuring peak performance around the clock.

ADVERTISEMENT

Enjoy the flexibility of choosing from top cloud providers like AWS, Google Cloud, and DigitalOcean. Plus, our expert support team is available 24/7 to assist you every step of the way.

Don’t settle for average hosting—elevate your online presence today.

Advertisement. Scroll to continue reading.

Cloudways Discount Code: Use the code MANIAINC to get 20% off Cloudways.

Start your free trial with Cloudways and witness the difference in performance and reliability!

Advertisement. Scroll to continue reading.

Get a Cloudways Free Trial

Read our Cloudways Review for more details.

We may earn a commission when you make a purchase.

What is ads.txt?

Before diving into the technical details, let’s briefly understand what ads.txt is and why it’s important:

  1. Authorized Digital Sellers: ads.txt allows publishers to publicly declare the companies authorized to sell their digital inventory. This helps prevent unauthorized reselling.
  2. Transparency and Trust: Advertisers can verify the authorized sellers, ensuring they are buying genuine inventory.
  3. Industry Standard: Managed by the IAB Tech Lab, ads.txt is an industry standard supported by major advertising platforms like Google AdSense.

Setting Up Cloudflare Workers

Cloudflare Workers is a serverless computing platform that allows you to run JavaScript code on Cloudflare’s network. It’s an ideal solution for tasks like serving an ads.txt file because it’s fast, scalable, and easy to implement.

Step 1: Create a Cloudflare Worker

  1. Log into your Cloudflare account: Navigate to the Cloudflare dashboard.
  2. Navigate to Cloudflare’s Dashboard: Navigate to the Cloudflare dashboard i.e., the main screen before selecting a site.
  3. Navigate to Workers & Pages: Click on the “Workers & pages” tab from the dashboard.
  4. Create a Worker: Click on the “Create a Worker” button. This will take you to the Workers editor screen.
  5. Name Your Worker: Add a descriptive name for your Worker.

Step 2: Add the Code

In the Workers editor, you will need to add the following JavaScript code. This code will serve as your ads.txt file when someone requests it. Remember to replace the lines under ‘#Ads.txt file for mania.africa’ with entries you want in your ads.txt.

const adstxt = `
# Ads.txt file for mania.africa
google.com, pub-0000000000000000, DIRECT, f08c47fec0942fa0
google.com, pub-1111111111111111, DIRECT, f08c47fec0942fa0
google.com, pub-2222222222222222, DIRECT, f08c47fec0942fa0
# Add more lines as needed
`;

async function handleRequest(request) {
  try {
    const init = {
      'content-type': 'text/plain'
    };
    return new Response(adstxt, init);
  } catch (error) {
    return new Response(`Error: ${error.message}`, { status: 500 });
  }
}

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request));
});

Explanation of the Code:

  • adstxt Variable: This variable holds the contents of your ads.txt file. Replace the placeholder text with your actual ads.txt entries.
  • handleRequest Function: This function creates a new HTTP response with the ads.txt content and sets the content type to text/plain.
  • addEventListener: This listens for fetch events and responds with the ads.txt content when requested.
computer code on a screen | How to Create an ads.txt Page with Cloudflare Workers | Mania Guides
Deploying the code above effectively will encapsulate your ads.txt in a Cloudflare Worker. Photo by Aaron McLean / Unsplash

Step 3: Deploy the Worker

  1. Save and Deploy: After adding your code, click the “Save and Deploy” button. This will make your Worker live.

Step 4: Create a Worker Route

To ensure that the ads.txt file is served correctly when requested from your domain, you need to create a Worker route.

  1. Select Your Site in the Cloudflare Dashboard: In the Cloudflare dashboard, select your site and enter the site’s screen.
  2. Access Workers Routes: Under the Worker Routes tab, you will find a section for HTTP Routes.
  3. Create a Route: Click on “Add Route”. Here, you will specify the path where your Worker will respond. Enter your domain followed by /ads.txt (e.g., https://yourdomain.com/ads.txt).
  4. Assign Worker: Assign the previously created Worker to this route.

Step 5: Testing the Worker

After setting up the Worker route, you can now test your Worker by appending /ads.txt to your domain in the browser. For example, navigate to https://yourdomain.com/ads.txt. If everything is set up correctly, you should see the contents of your ads.txt file displayed in the browser.

Benefits of Using Cloudflare Workers for ads.txt

  1. Performance: Cloudflare’s global network ensures that your ads.txt file is served quickly from a location close to the requester.
  2. Scalability: As a serverless solution, Cloudflare Workers can handle a high volume of requests without the need to manage infrastructure.
  3. Simplicity: Creating and managing Workers is straightforward, requiring minimal setup and maintenance.
A laptop with words on the screen | Creating an ads.txt page with Cloudflare Summary | Mania Africa
An ads.txt configuration via Cloudflare Workers assists you in ensuring transparency for the digital ads on your site and is a good alternative to uploading the file on your server root. Photo by Ben Kolde / Unsplash

Creating an ads.txt page with Cloudflare Summary

Creating an ads.txt page with Cloudflare Workers is a simple yet effective way to manage and serve your ads.txt file. By following the steps outlined in this guide, you can ensure that your digital ad inventory is protected and transparent, fostering trust with advertisers and maximizing your revenue potential. Whether you’re a small publisher or a large media company, implementing ads.txt via Cloudflare Workers is a smart move for securing your digital advertising ecosystem.

Mania Guides – Mania Africa
All our Guides and Tutorials. We offer insight into how you can best achieve a set goal, deliberate on the most effective approaches, and guide you on how to go about carrying them out.
35 3 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.comMania AfricaDavid Mania
photo 1630577915125 ee3a64f6f086cropentropycstinysrgbfitmaxfmjpgixidM3wxMTc3M3wwfDF8c2VhcmNofDIyfHx0dXRvcmlhbHxlbnwwfHx8fDE3MjExOTc0MzB8MAixlibrb 4.0 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.com

Read more Tech Guides here

By leveraging the power of Cloudflare Workers, you not only enhance the security and transparency of your ad inventory but also benefit from the performance and scalability of Cloudflare’s network. This setup is a win-win for both publishers and advertisers, contributing to a healthier and more trustworthy digital advertising landscape.

Everything You Need to Know About Cloudflare’s Rocket Loader: A Comprehensive Guide to Boosting Site Speed and Resolving Script Conflicts
Rocket Loader is a performance optimization feature offered by Cloudflare, a leading content delivery network (CDN) provider.
35 3 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.comMania AfricaDavid Mania
https 3a 2f 2fsubstack post media s3 amazonaws com 2fpublic 2fimages 2f7f36fd17 5a0e 48ec 8828 0407aa3b71f1 2000x1577 jpeg 1 1 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.com

Video: How to Setup your Ads.txt File Using Cloudflare Workers

For further assistance, you can refer to Cloudflare’s documentation or watch the video guide for a visual walkthrough.

Bonus: If you’re using Ghost CMS and need to know how to set up Cloudflare Caching, refer to this article for the best Cloudflare settings for Ghost CMS.

Post Views: 513
Spread the love

More from Mania Africa:

5 Reasons Why Your Website Needs Managed Cloud Hosting (and Why We Think Cloudways is the Best) - Mania Developers5 Reasons Why Your Website Needs Managed Cloud Hosting (and Why We Think Cloudways is the Best) a blue and white wordpress logo - Easy and Quick WordPress Optimizations with One-Click and One-Plugin Solutions - Mania DevelopersEasy and Quick WordPress Optimizations with One-Click and One-Plugin Solutions Why Your WordPress Multisite Is Slowing Down — and How CPU-Optimized Hosting Can Fix It - Mania TechWhy Your WordPress Multisite Is Slowing Down — and How CPU-Optimized Hosting Can Fix It 172709671666f1678c208b0 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.comChoosing the Right Web Hosting Provider: A Comprehensive Guide to Finding Your Perfect Match Mastering Server-Level WordPress Optimizations - WordPress Server Optimization Guide by Mania AfricaMastering Server-Level WordPress Optimizations: Proven Strategies for Blazing-Fast Performance 172709672766f1679756da4 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.comWordPress Starter Kit and Blogging Guide: How to Start Your New Site on a Strong Footing Windows Won’t Load: Fixing Windows Boot Errors with Only a Phone, SD Card, SD Card Reader, and OTG Cable - It Only Took Me a WeekWindows Won’t Load: Fixing Windows Boot Errors with Only a Phone, SD Card, SD Card Reader, and OTG Cable https 3a 2f 2fsubstack post media s3 amazonaws com 2fpublic 2fimages 2ff7fa8b1f d7de 4cd6 9aaf b8fffeed4cd3 2000x1331 jpeg 1 1 | Mania Africa: News, Sports, Tech, Movies, and Lifestyle | maniainc.comBeginner’s Guide to React.js: What It Is, How to Use It, and Its Benefits with Examples of Code for Websites and Mobile Apps

Catch up with the latest!
Get an alert for new posts

Opt Out
ADVERTISEMENT
davidmania

davidmania

David Mania is the creative force behind Mania Africa. With a Bachelor's Degree in Business & IT and 8 years of writing experience, he delivers compelling and thought-provoking content.

Related Posts

How to Monitor and Maintain a High-Performance WordPress Server (Without the Guesswork) - Comprehensive WordPress Server Monitoring and Troubleshooting Guide

How to Monitor and Maintain a High-Performance WordPress Server (Without the Guesswork)

by davidmania
December 19, 2025
1
10k

It's time you upped your WordPress server monitoring game for easier, more efficient, and more powerful troubleshooting and maintenance. Here's...

The Ultimate Server-Side Caching Guide for WordPress: Redis, Varnish, and Cloudflare Enterprise Explained

The Ultimate Server-Side Caching Guide for WordPress: Redis, Varnish, and Cloudflare Enterprise Explained

by davidmania
November 6, 2025
0
10k

Caching is the internet’s short-term memory. Instead of making the server re-cook every single page on every single visit, caching...

Two code blocks morphing - How Cloudways CoPilot Makes WordPress Server Troubleshooting Easier and Saves You Hours (at a Fraction of the Cost of Hiring a DevOp Engineer)

How Cloudways CoPilot Makes WordPress Server Troubleshooting Easier and Saves You Hours (at a Fraction of the Cost of Hiring a DevOp Engineer)

by davidmania
October 17, 2025
0
10k

Let’s get started… 1. Introduction: The Stresses of Cumbersome Host Troubleshooting for WordPress/WooCommerce If you have ever had a client...

laptop computer on glass-top table - Maximize ROI for your SMB Website with Cloudways' CPU-Optimized Servers + Lightning Stack: Scale for Long-term Growth at an Affordable Price

Maximize ROI for your SMB Website with Cloudways’ CPU-Optimized Servers + Lightning Stack: Scale for Long-term Growth at an Affordable Price

by davidmania
October 2, 2025
0
10k

Let's get started... 1. Introduction: The Challenges SMBs Face While Trying to Scale for Long-Term Growth For small and medium...

5 Reasons Why Your Website Needs Managed Cloud Hosting (and Why We Think Cloudways is the Best) - Mania Developers

5 Reasons Why Your Website Needs Managed Cloud Hosting (and Why We Think Cloudways is the Best)

by davidmania
July 3, 2025
0
10k

Let's get started... Introduction As a small business owner using WooCommerce, a content creator creating blogs on WordPress or a...

a blue and white wordpress logo - Easy and Quick WordPress Optimizations with One-Click and One-Plugin Solutions - Mania Developers

Easy and Quick WordPress Optimizations with One-Click and One-Plugin Solutions

by davidmania
June 16, 2025
0
10k

Let's get started... Introduction: Achieving <2 s Load Times, Core Web Vitals, and PageSpeed ≥ 80 High-performing WordPress sites rank better and...

Search

The Feed

Why Anthropic Restricted Claude Fable 5 and Mythos 5 - Mania Tech

Why Anthropic Restricted Fable 5 and Mythos 5: National Security Concerns, AI Jailbreaking, and the Future of Frontier AI

June 14, 2026
Sunlight streams through clouds over the ocean - A serene, misty horizon where the ocean meets a golden sky, symbolizing the transition between life and the unknown - The Paradox of Life at Death’s Edge: The Gift of Perspective and Lessons from Near-Death Experiences - Mania Lifestyle

The Paradox of Life at Death’s Edge: The Gift of Perspective and Lessons from Near-Death Experiences

March 7, 2026
All You Need to Know About Seedance 2.0 - ByteDance’s Next-Gen AI Video Model - Mania AI

All You Need to Know About Seedance 2.0: ByteDance’s Next-Gen AI Video Model

February 14, 2026
A close up of a green glass object - Why Users Are Rallying to #Keep4o: The Social Backlash Against OpenAI Retiring ChatGPT 4o

Why Users Are Rallying to #Keep4o: The Social Backlash Against OpenAI Retiring ChatGPT 4o

February 8, 2026
a group of blue plastic containers engulfing a Bitcoin golden coin - A Practical, Hype-Free Look at the Feb 2026 Bitcoin Crash

To the Moon?: Is Bitcoin a Balloon in Space or a Building on a Solid Rock Foundation – A Practical, Hype-Free Look at the Feb 2026 Bitcoin Crash

February 6, 2026
a statue of a Roman emperor holding a staff - Is Modern Society Addicted to Drama? What a TikTok Joke Reveals About the Brain, Addiction, & Our Hunger for Intensity - Mania Lifestyle

Is Modern Society Addicted to Drama? What a TikTok Joke Reveals About the Brain, Addiction, & Our Hunger for Intensity

February 3, 2026
ADVERTISEMENT

Mania Africa 💎🌍

✨ News, Sports, Movies, Tech & Lifestyle—Unveil the Stories that Matter with David Mania 📚 We pride ourselves in going beyond the headlines and into the nitty-gritty of every story. We are not here to just churn out articles. Far from it. We actually care about the key issues and how they affect the lives of those communities.

Buy us a coffee

Tip us and support our work

Tip

Resources

  • Home
  • About Us
  • Discord
  • Threads
  • Mastodon
  • BlueSky
  • Videos
  • AI WordPress Automation
  • The Geekline Feed

Notifications

Get Notified when we post

Sure
  • Home
  • Advertise
  • Patreon
  • Tip Us
  • Merch
  • Linktree
  • Kit
  • RSS
  • The Geekline

Copyright © 2020-2026. Mania Online Connect. All rights reserved.

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

Automate your WordPress Workflow! Try the Gemini MCP Tools Plugin. Dismiss

No Result
View All Result
  • Home
  • News
    • Politics
    • Opinion
  • Sports
  • Movies
  • Tech
    • The Geekline
    • AI for WordPress
  • Lifestyle
  • About Us
    • Contact Us
  • Privacy Policy
    • Community Guidelines & Comment Policy
    • Cookies Policy
  • Advertise
  • Patreon
    • Merch

Copyright © 2020-2026. Mania Online Connect. All rights reserved.

Not enough quota to unlock this post
Unlock left : 0
Are you sure want to cancel subscription?

Terms and Conditions