Marketing as Code
tdx enables Marketing as Code—a paradigm shift from manual UI operations to AI-friendly marketing configurations.
The Problem
Traditional marketing operations rely on clicking through UIs:
- Manual and error-prone - Complex sequences of clicks that are hard to reproduce
- Invisible to AI - AI assistants cannot navigate UIs or understand click-based workflows
- Hard to scale - Cannot easily replicate configurations across brands or environments
- No version control - Difficult to track changes, review history, or roll back mistakes
The Solution
tdx treats marketing logic as code:
| Traditional "Click Ops" | Marketing as Code |
|---|---|
| Configure in UI | Define in YAML files |
| Manual testing | Local validation with tdx |
| Direct production changes | Test locally, then deploy |
| Hard to automate | AI agents can read/write |
YAML as Source of Truth
Instead of navigating complex UIs, define your marketing logic in simple YAML files:
# segment.yaml
name: High-Value Customers
description: Customers with lifetime value > $1000
rules:
- attribute: lifetime_value
operator: greater_than
value: 1000
activations:
- connection: salesforce-prod
enabled: trueWhy YAML?
- AI excels at generating structured text like YAML
- Human-readable and easy to review
- Standard format with excellent tooling support
- Avoids hallucinations from complex JSON APIs
See Segment YAML Schema for the full specification.
Segment Architecture
CDP segments follow a parent-child hierarchy:
Parent Segment defines the data foundation:
- Master Table - Source of customer records
- Attributes - Customer properties (e.g., lifetime_value, signup_date)
- Behaviors - Customer actions (e.g., purchases, page_views)
Child Segments define targeting rules and activations:
- Filter customers using attributes and behaviors
- Activate to marketing channels (Salesforce, Google Ads, etc.)
The Lifecycle
Marketing as Code follows a familiar development workflow:
Use these commands to manage segments as code:
tdx ps(parent-segment) - Pull, edit, and push parent segment YAML filestdx sg(segment) - Pull, edit, and push child segment YAML files
1. Define
AI generates or you write marketing definitions locally:
# Pull existing segment to YAML
tdx sg pull "My Segment"
# AI can modify the YAML file
# or create new definitions from scratch2. Verify
Test your changes locally before touching production:
# Validate segment definition
tdx ps validate
# Preview sample data
tdx ps preview
tdx sg show
# Check what would change
tdx sg push --dry-run3. Deploy
Push verified changes to production:
# Deploy segment changes
tdx sg push
# Deploy parent segment
tdx ps pushBenefits
Standardization
Code is standard. One team's segment definition looks the same as another's—solving scattered, inconsistent configurations.
Version Control (Optional)
Store YAML files in Git to track changes over time. If an AI agent makes a mistake, you can git revert. You cannot easily revert a sequence of UI clicks.
Scalability
Copy and adapt YAML files across 100 brands. You cannot copy-paste UI clicks.
Production Safety
Test locally before deploying. Marketing as Code means you don't break production—you validate first.
AI-Native
AI agents can read, write, and test marketing configurations safely. The complexity stays in tdx, not in your prompts.
Use tdx claude to launch Claude Code with TD's AI Foundry backend—AI can edit your YAML files, validate changes, and deploy segments directly.
Getting Started
# Install tdx
npm install -g @treasuredata/tdx
# Authenticate
tdx auth setup
# Pull a segment to start working locally
tdx sg pull "My Segment" -u
# Make changes to the YAML file, then push
tdx sg pushLearn More
- Parent Segment Commands - Manage parent segments as YAML
- Segment Commands - Manage child segments as YAML
- TD Skills - AI skills for segment management