Skip to content

Marketing as Code

tdx enables Marketing as Code—a paradigm shift from manual UI operations to AI-friendly marketing configurations.

Learn with AI

New to Marketing as Code? Read the AI-Native Marketing Book for a step-by-step guide from setup to segments, journeys, and workflows.

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
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
yaml
type: journey
name: Welcome Series
reentry: no_reentry

stages:
  - name: Onboarding
    steps:
      - type: activation
        name: Send Welcome Email
        with:
          activation: welcome-email
        next: wait-for-engagement

      - type: wait
        name: Wait for Engagement
        id: wait-for-engagement
        with:
          condition:
            segment: engaged-users
            timeout:
              duration: 7
              unit: day
        next: follow-up

      - type: activation
        name: Follow Up
        id: follow-up
        with:
          activation: follow-up-email

activations:
  welcome-email:
    connection: email-provider
  follow-up-email:
    connection: email-provider

segments:
  engaged-users:
    rules:
      - attribute: email_opened
        operator: is_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 and Journey YAML Schema for full specifications.

CDP Architecture

CDP resources follow a hierarchical structure:

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.)

Journeys orchestrate multi-step customer experiences:

  • Define stages with sequential or conditional steps
  • Wait for time delays or segment conditions
  • Branch based on A/B tests or decision points
  • Activate to channels at each step

The Lifecycle

Marketing as Code follows a familiar development workflow:

Use these commands to manage CDP resources 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
  • tdx journey - Pull, edit, and push journey YAML files

1. Define

AI generates or you write marketing definitions locally:

bash
# Pull existing resources to YAML
tdx sg pull "My Segment"
tdx journey pull "My Journey"

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

2. Verify

Test your changes locally before touching production:

bash
# Validate definitions
tdx sg validate
tdx journey validate

# Preview sample data
tdx ps preview
tdx sg show

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

3. Deploy

Push verified changes to production:

bash
# Deploy segment changes
tdx sg push

# Deploy journey changes
tdx journey 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 resources to start working locally
tdx sg pull "My Segment" -u
tdx journey pull "My Journey" -u

# Make changes to the YAML files, then push
tdx sg push
tdx journey push

Learn More