Skip to content

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 UIDefine in YAML files
Manual testingLocal validation with tdx
Direct production changesTest locally, then deploy
Hard to automateAI agents can read/write

YAML as Source of Truth

Instead of navigating complex UIs, define your marketing logic in simple YAML files:

yaml
# 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: true

Why 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 files
  • tdx sg (segment) - Pull, edit, and push child segment YAML files

1. Define

AI generates or you write marketing definitions locally:

bash
# Pull existing segment to YAML
tdx sg pull "My Segment"

# AI can modify the YAML file
# or create new definitions from scratch

2. Verify

Test your changes locally before touching production:

bash
# Validate segment definition
tdx ps validate

# Preview sample data
tdx ps preview
tdx sg show

# Check what would change
tdx sg push --dry-run

3. Deploy

Push verified changes to production:

bash
# Deploy segment changes
tdx sg push

# Deploy parent segment
tdx ps push

Benefits

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

bash
# 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 push

Learn More