Skip to main content

Klaviyo Multi-Environment Guide

How to manage Klaviyo across Dev, Staging, and Production environments.


Overview

We use separate Klaviyo accounts for testing vs production to avoid polluting real customer data.

EnvironmentKlaviyo AccountPurpose
Develi-health-testAPI development, debugging
Stagingeli-health-testQA testing, flow verification
Productioneli-healthReal customers

Part 1: Developer Setup

Klaviyo Account Setup

Ask Morgane to create:

  • A new Klaviyo account called eli-health-test (free tier is fine)
  • Add developers as users so they can view test profiles

Environment Variables

Location: eli-devops/tf/ and Secret Manager

Terraform Configuration:

# dev.tfvars
klaviyo_api_key = "pk_test_xxx"

# staging.tfvars
klaviyo_api_key = "pk_test_xxx"

# production.tfvars
klaviyo_api_key = "pk_prod_xxx"

Secret Manager Setup:

# Create secrets (one-time)
echo -n "pk_test_xxx" | gcloud secrets create klaviyo-api-key-dev --data-file=-
echo -n "pk_test_xxx" | gcloud secrets create klaviyo-api-key-staging --data-file=-
echo -n "pk_prod_xxx" | gcloud secrets create klaviyo-api-key-prod --data-file=-

Backend Configuration

File: eli-backend-api/src/modules/klaviyo/klaviyo.service.ts

KLAVIYO_API_KEY     → From environment/Secret Manager
KLAVIYO_ENABLED → Optional flag to disable entirely

Testing Checklist (Dev)

Before merging:

  • API call succeeds (no auth errors)
  • Profile created in test Klaviyo
  • Properties populated correctly
  • Errors logged but don't block test completion

Testing Checklist (Staging)

Before production deploy:

  • Complete a real test in staging app
  • Profile appears in test Klaviyo with correct email
  • total_tests_completed increments
  • test_stock_percentage calculates correctly
  • first_test_completed and days_to_first_test set on first test
  • Automation flow triggers (if cloned to test account)

Part 2: Marketing Setup (Morgane)

Account Structure

AccountURLPurpose
eli-health-testklaviyo.com (separate login)Build and test flows
eli-healthklaviyo.comProduction - real customers

Workflow: Build → Test → Deploy

How to Clone Flows to Production

Step-by-step:

  1. In Test Account: Go to Flows
  2. Find your flow: Click the (three dots) menu
  3. Select "Clone"
  4. Choose "Clone to multiple accounts"
  5. Search for "eli-health" (production account)
  6. Name the flow (e.g., same name or add version)
  7. Review settings:
    • Adjust segments if test vs prod segments differ
    • Verify trigger metrics exist in production
  8. Click Clone - wait a few minutes
  9. In Production Account:
    • Find the cloned flow
    • Review all steps
    • Activate when ready

What Gets Cloned

ClonedNot Cloned
Flow structureSpecific profiles
Email templatesAnalytics/metrics
Trigger logicLive status (starts as Draft)
Timing delaysAccount-specific lists
Conditional splits-

Updating Production Flows

Option A: Edit in Place

  • Make changes directly in production
  • Good for small tweaks (copy, timing)

Option B: Clone Again

  • Make changes in test account
  • Re-clone to production
  • Deactivate old flow, activate new one
  • Good for major changes

Tips for Morgane

  1. Name flows consistently across accounts (e.g., "First Test Welcome - v2")
  2. Test with your own email in the test account before cloning
  3. Use Klaviyo's Preview feature to see how emails render
  4. Check segments exist in production before cloning segment-triggered flows
  5. Keep test account clean - archive old test flows

Quick Reference

Developer Commands

# Check which Klaviyo key is configured
gcloud secrets versions access latest --secret=klaviyo-api-key-dev

# View logs for Klaviyo calls
gcloud logging read "resource.type=cloud_run_revision AND textPayload:klaviyo" --limit=20

Klaviyo URLs

AccountDashboard
Testhttps://www.klaviyo.com/dashboard (eli-health-test login)
Productionhttps://www.klaviyo.com/dashboard (eli-health login)

API Documentation



Document History

DateAuthorChanges
2025-01-26ChipInitial multi-environment guide