The Trade Desk Export Guide — Python Script

GMSF v1.2 The Trade Desk 10 min install
🎯
Objective
This Python script automatically exports your The Trade Desk campaign data with the granularity needed for GMSF v1.2 carbon analysis in Carbon Intelligence. The Trade Desk offers very fine granularity on exchanges, connections, and buy types.
⚙️
Installation
3 steps · 10 minutes
Prerequisites
  1. Python 3.8+ installed on your server or local machine
  2. Install dependencies: pip install requests pandas
  3. Obtain an API Token and Partner ID from The Trade Desk
  4. Note the target Advertiser ID for export
Configure the script
  1. Open the file carbon-intelligence-thetradedesk-export.py
  2. Fill in the authentication parameters: API_TOKEN, PARTNER_ID, ADVERTISER_ID
  3. Configure OUTPUT_DIR for the CSV destination folder
Run
  1. Run the script: python carbon-intelligence-thetradedesk-export.py
  2. Schedule recurring execution via cron (Linux/macOS) or Task Scheduler (Windows)
  3. Recommendation: weekly (every Monday morning)
📊
What is exported
13 tabs created automatically
TabContentUsage Carbon Intelligence
CI_CampaignsSummary by campaign and dayEmissions overview
CI_DeviceBy device (mobile, desktop, CTV)Energy factor per device
CI_GeoBy country and regionGMSF v1.2 country energy mix
CI_PlacementsBy site and applicationEnergy-intensive placements
CI_CreativeSizeBy creative size (300x250, 728x90, etc.)Data transfer weight
CI_AdFormatBy format (Display, Video, Native)Ad format factor
CI_VideoDetailed video data (duration, type)Video carbon calculation
CI_ExchangeBy exchange (Rubicon, OpenX, AppNexus, etc.)🎯 TTD Specific — Inventory source
CI_ConnectionBy connection type (WiFi, mobile, wired)🎯 TTD Specific — Network energy efficiency
CI_EnvironmentBy context (app, web, OTT)🎯 TTD Specific — Media environment type
CI_BuyTypeBy buy mode (open auction, PMP, PG)🎯 TTD Specific — Buy strategy transparency
CI_MetadataAccount info, script version, datesTraceability and audit
CI_Export_CSVAll dimensions consolidatedDirect CI platform import
📁
Export CSV
Two options available
After each script execution, you will find in the OUTPUT_DIR folder the following CSV files:
  • CI_Export_[DATE].csv — Consolidated file for direct import
  • CI_Campaigns_[DATE].csv — Campaign details
  • CI_Device_[DATE].csv — By device
  • CI_Exchange_[DATE].csv — By exchange (TTD specific)
  • • ...and other dimensions
🔗
Sharing with Carbon Intelligence
📨
Share the Google Sheet with: support@carbonintelligence.green (accès lecteur)
Or send the exported CSV by email to the same address.
🔧
Advanced Configuration
Script CONFIG section
# In the script, CONFIG section:

LOOKBACK_DAYS: 90,              # Days of history (default: 90)
MIN_IMPRESSIONS: 1,             # Minimum impression threshold per row
REPORT_TIMEZONE: 'UTC',         # Report timezone
MAX_RETRIES: 3                # API retry attempts on error
🛠️
Troubleshooting
"401 Unauthorized"
Check that your API_TOKEN is valid and not expired. Regenerate it if necessary in The Trade Desk console.
"Advertiser not found"
Check that the ADVERTISER_ID exists and that your token has access to this account.
"Report timeout"
The report is taking too long. Reduce LOOKBACK_DAYS from 90 to 30 days.
"Empty report"
Check that you have active campaigns with impressions for the period defined by LOOKBACK_DAYS.
"Rate limit exceeded"
The Trade Desk API has a quota. Wait a few minutes and try again. Increase MAX_RETRIES for better resilience.
💬
Support
Email support@carbonintelligence.green
Script version 1.0.0
Methodology GMSF v1.2 (Ad Net Zero)