How to Track Adsterra Traffic Using Python (Full Script Guide)

How to Track Adsterra Traffic Using Python (Full Script Guide)
If you're monetizing your website with Adsterra, tracking your traffic and earnings efficiently is very important. Instead of manually checking your dashboard every day, you can automate everything using Python.
In this tutorial, you’ll learn how to build a simple but powerful script that fetches:
Your domains
Ad placements
Daily stats (clicks, impressions, revenue)
🚀 Why Use Python for Adsterra Tracking?
Using Python with the Requests library allows you to:
Automate data collection
Save time
Build your own dashboard
Monitor performance in real-time
⚙️ Full Python Script
Below is the complete working script:
Copy code
Python
import requests

# =========================
# 🔑 CONFIG
# =========================
API_KEY = ""
BASE_URL = "https://api3.adsterratools.com/publisher"

headers = {
    "X-API-Key": API_KEY
}

# =========================
# 🌐 GET DOMAINS
# =========================
def get_domains():
    url = f"{BASE_URL}/domains.json"
    response = requests.get(url, headers=headers)

    if response.status_code == 200:
        data = response.json()

        if isinstance(data, dict):
            data = data.get("items", [])

        print("\n✅ DOMAINS:")
        for d in data:
            print(f"ID: {d.get('id')} | Name: {d.get('title')}")

        return data
    else:
        print("❌ Domains Error:", response.status_code, response.text)
        return []


# =========================
# 📢 GET PLACEMENTS
# =========================
def get_placements():
    url = f"{BASE_URL}/placements.json"
    response = requests.get(url, headers=headers)

    if response.status_code == 200:
        data = response.json()

        if isinstance(data, dict):
            data = data.get("items", [])

        print("\n✅ PLACEMENTS:")
        for p in data:
            print(f"ID: {p.get('id')} | Name: {p.get('title')}")

        return data
    else:
        print("❌ Placements Error:", response.status_code, response.text)
        return []


# =========================
# 📊 GET STATS
# =========================
def get_stats():
    url = f"{BASE_URL}/stats.json"

    params = {
        "start_date": "2026-02-01",
        "finish_date": "2026-03-22",
        "group_by": "date"
    }

    response = requests.get(url, headers=headers, params=params)

    if response.status_code == 200:
        data = response.json()

        if isinstance(data, dict):
            data = data.get("items", [])

        print("\n📊 STATS (DAILY):")

        total_clicks = 0
        total_impressions = 0
        total_revenue = 0

        for s in data:
            date = s.get("date")
            clicks = s.get("clicks", 0)
            impressions = s.get("impressions", 0)
            revenue = s.get("revenue", 0)

            total_clicks += clicks
            total_impressions += impressions
            total_revenue += revenue

            print(f"📅 {date} | 👁 {impressions} | 🖱 {clicks} | 💰 ${revenue}")

        print("\n====== TOTAL ======")
        print(f"👁 Impressions: {total_impressions}")
        print(f"🖱 Clicks: {total_clicks}")
        print(f"💰 Revenue: ${total_revenue}")

        return data
    else:
        print("❌ Stats Error:", response.status_code, response.text)
        return []


# =========================
# ▶️ MAIN RUN
# =========================
if __name__ == "__main__":
    domains = get_domains()

    if not domains:
        print("⚠️ No domains found")
        exit()

    placements = get_placements()

    if not placements:
        print("⚠️ No placements found")
        exit()

    get_stats()
🔑 How to Use This Script
1. Add Your API Key
Replace:
Copy code
Python
API_KEY = ""
With your real key:
Copy code
Python
API_KEY = "your_api_key_here"
2. Install Required Library
Run:
Copy code
Bash
pip install requests
3. Run the Script
Copy code
Bash
python script.py
📊 What You Will See
The script will output:
✅ List of your domains
📢 Your ad placements
📅 Daily performance stats
💰 Total earnings
❌ Common Issues
No Stats Showing (0)
Wrong date range
No traffic yet
API key incorrect
Error 403 / 401
API key invalid
Access not allowed
💡 Bonus Ideas
You can upgrade this script to:
Save data into MySQL database
Build a dashboard (PHP / JS)
Send daily report to email
Create Telegram bot for alerts
🧠 Conclusion
Using Python with Adsterra API gives you full control over your ad performance. It helps you track, analyze, and improve your earnings without stress.

Post a Comment

0 Comments